2021-04-18 21:41:13 +02:00
|
|
|
// Copyright (c) 2015-2021 MinIO, Inc.
|
|
|
|
//
|
|
|
|
// This file is part of MinIO Object Storage stack
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2017-01-17 02:05:00 +01:00
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2020-07-30 08:15:34 +02:00
|
|
|
"context"
|
2017-01-17 02:05:00 +01:00
|
|
|
"testing"
|
|
|
|
|
2019-11-13 21:17:45 +01:00
|
|
|
"github.com/minio/minio/pkg/dsync"
|
2017-01-17 02:05:00 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Tests lock rpc client.
|
2019-04-18 08:16:27 +02:00
|
|
|
func TestLockRESTlient(t *testing.T) {
|
2019-11-13 21:17:45 +01:00
|
|
|
endpoint, err := NewEndpoint("http://localhost:9000")
|
2018-06-06 10:51:56 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error %v", err)
|
|
|
|
}
|
2020-11-02 16:43:11 +01:00
|
|
|
|
2019-11-13 21:17:45 +01:00
|
|
|
lkClient := newlockRESTClient(endpoint)
|
2020-06-17 03:59:32 +02:00
|
|
|
if !lkClient.IsOnline() {
|
2019-04-18 08:16:27 +02:00
|
|
|
t.Fatalf("unexpected error. connection failed")
|
2018-06-06 10:51:56 +02:00
|
|
|
}
|
2017-01-17 02:05:00 +01:00
|
|
|
|
|
|
|
// Attempt all calls.
|
2020-07-30 08:15:34 +02:00
|
|
|
_, err = lkClient.RLock(context.Background(), dsync.LockArgs{})
|
2017-01-17 02:05:00 +01:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("Expected for Rlock to fail")
|
|
|
|
}
|
|
|
|
|
2020-07-30 08:15:34 +02:00
|
|
|
_, err = lkClient.Lock(context.Background(), dsync.LockArgs{})
|
2017-01-17 02:05:00 +01:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("Expected for Lock to fail")
|
|
|
|
}
|
|
|
|
|
2021-05-11 11:11:29 +02:00
|
|
|
_, err = lkClient.RUnlock(context.Background(), dsync.LockArgs{})
|
2017-01-17 02:05:00 +01:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("Expected for RUnlock to fail")
|
|
|
|
}
|
|
|
|
|
2021-05-11 11:11:29 +02:00
|
|
|
_, err = lkClient.Unlock(context.Background(), dsync.LockArgs{})
|
2017-01-17 02:05:00 +01:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("Expected for Unlock to fail")
|
|
|
|
}
|
|
|
|
}
|