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