github.com/minio/madmin-go@v1.7.5/remote-target-commands_test.go (about) 1 // 2 // MinIO Object Storage (c) 2021 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 madmin 18 19 import ( 20 "net/url" 21 "testing" 22 ) 23 24 func isOpsEqual(op1 []TargetUpdateType, op2 []TargetUpdateType) bool { 25 if len(op1) != len(op2) { 26 return false 27 } 28 for _, o1 := range op1 { 29 found := false 30 for _, o2 := range op2 { 31 if o2 == o1 { 32 found = true 33 break 34 } 35 } 36 if !found { 37 return false 38 } 39 } 40 return true 41 } 42 43 // TestGetTargetUpdateOps tests GetTargetUpdateOps 44 func TestGetTargetUpdateOps(t *testing.T) { 45 testCases := []struct { 46 values url.Values 47 expectedOps []TargetUpdateType 48 }{ 49 { 50 values: url.Values{ 51 "update": []string{"true"}, 52 }, 53 expectedOps: []TargetUpdateType{}, 54 }, 55 { 56 values: url.Values{ 57 "update": []string{"false"}, 58 "path": []string{"true"}, 59 }, 60 expectedOps: []TargetUpdateType{}, 61 }, 62 { 63 values: url.Values{ 64 "update": []string{"true"}, 65 "path": []string{""}, 66 }, 67 expectedOps: []TargetUpdateType{}, 68 }, 69 { 70 values: url.Values{ 71 "update": []string{"true"}, 72 "path": []string{"true"}, 73 "bzzzz": []string{"true"}, 74 }, 75 expectedOps: []TargetUpdateType{PathUpdateType}, 76 }, 77 78 { 79 values: url.Values{ 80 "update": []string{"true"}, 81 "path": []string{"true"}, 82 "creds": []string{"true"}, 83 "sync": []string{"true"}, 84 "proxy": []string{"true"}, 85 "bandwidth": []string{"true"}, 86 "healthcheck": []string{"true"}, 87 }, 88 expectedOps: []TargetUpdateType{ 89 PathUpdateType, CredentialsUpdateType, SyncUpdateType, ProxyUpdateType, BandwidthLimitUpdateType, HealthCheckDurationUpdateType, 90 }, 91 }, 92 } 93 for i, test := range testCases { 94 gotOps := GetTargetUpdateOps(test.values) 95 if !isOpsEqual(gotOps, test.expectedOps) { 96 t.Fatalf("test %d: expected %v got %v", i+1, test.expectedOps, gotOps) 97 } 98 } 99 }