storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/cmd/lock-rest-client_test.go (about) 1 /* 2 * MinIO Cloud Storage, (C) 2019 MinIO, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package cmd 18 19 import ( 20 "context" 21 "testing" 22 23 "storj.io/minio/pkg/dsync" 24 ) 25 26 // Tests lock rpc client. 27 func TestLockRESTlient(t *testing.T) { 28 endpoint, err := NewEndpoint("http://localhost:9000") 29 if err != nil { 30 t.Fatalf("unexpected error %v", err) 31 } 32 33 lkClient := newlockRESTClient(endpoint) 34 if !lkClient.IsOnline() { 35 t.Fatalf("unexpected error. connection failed") 36 } 37 38 // Attempt all calls. 39 _, err = lkClient.RLock(context.Background(), dsync.LockArgs{}) 40 if err == nil { 41 t.Fatal("Expected for Rlock to fail") 42 } 43 44 _, err = lkClient.Lock(context.Background(), dsync.LockArgs{}) 45 if err == nil { 46 t.Fatal("Expected for Lock to fail") 47 } 48 49 _, err = lkClient.RUnlock(dsync.LockArgs{}) 50 if err == nil { 51 t.Fatal("Expected for RUnlock to fail") 52 } 53 54 _, err = lkClient.Unlock(dsync.LockArgs{}) 55 if err == nil { 56 t.Fatal("Expected for Unlock to fail") 57 } 58 }