2021-04-18 19:41:13 +00: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 01:05:00 +00:00
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2020-07-30 06:15:34 +00:00
|
|
|
"context"
|
2017-01-17 01:05:00 +00:00
|
|
|
"testing"
|
|
|
|
|
2021-06-01 21:59:40 +00:00
|
|
|
"github.com/minio/minio/internal/dsync"
|
2017-01-17 01:05:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Tests lock rpc client.
|
2019-04-18 06:16:27 +00:00
|
|
|
func TestLockRESTlient(t *testing.T) {
|
2019-11-13 20:17:45 +00:00
|
|
|
endpoint, err := NewEndpoint("http://localhost:9000")
|
2018-06-06 08:51:56 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error %v", err)
|
|
|
|
}
|
2020-11-02 15:43:11 +00:00
|
|
|
|
2019-11-13 20:17:45 +00:00
|
|
|
lkClient := newlockRESTClient(endpoint)
|
2020-06-17 01:59:32 +00:00
|
|
|
if !lkClient.IsOnline() {
|
2019-04-18 06:16:27 +00:00
|
|
|
t.Fatalf("unexpected error. connection failed")
|
2018-06-06 08:51:56 +00:00
|
|
|
}
|
2017-01-17 01:05:00 +00:00
|
|
|
|
|
|
|
// Attempt all calls.
|
2020-07-30 06:15:34 +00:00
|
|
|
_, err = lkClient.RLock(context.Background(), dsync.LockArgs{})
|
2017-01-17 01:05:00 +00:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("Expected for Rlock to fail")
|
|
|
|
}
|
|
|
|
|
2020-07-30 06:15:34 +00:00
|
|
|
_, err = lkClient.Lock(context.Background(), dsync.LockArgs{})
|
2017-01-17 01:05:00 +00:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("Expected for Lock to fail")
|
|
|
|
}
|
|
|
|
|
2021-05-11 09:11:29 +00:00
|
|
|
_, err = lkClient.RUnlock(context.Background(), dsync.LockArgs{})
|
2017-01-17 01:05:00 +00:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("Expected for RUnlock to fail")
|
|
|
|
}
|
|
|
|
|
2021-05-11 09:11:29 +00:00
|
|
|
_, err = lkClient.Unlock(context.Background(), dsync.LockArgs{})
|
2017-01-17 01:05:00 +00:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("Expected for Unlock to fail")
|
|
|
|
}
|
|
|
|
}
|