github.com/openebs/node-disk-manager@v1.9.1-0.20230225014141-4531f06ffa1e/api-service/node/services/listBlockDevice_test.go (about) 1 /* 2 Copyright 2020 The OpenEBS Authors 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 http://www.apache.org/licenses/LICENSE-2.0 7 Unless required by applicable law or agreed to in writing, software 8 distributed under the License is distributed on an "AS IS" BASIS, 9 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 See the License for the specific language governing permissions and 11 limitations under the License. 12 */ 13 14 package services 15 16 import ( 17 "reflect" 18 "testing" 19 ) 20 21 // TestFilterPartitions tests the FilterPartitions 22 func TestFilterPartitions(t *testing.T) { 23 var testCases = []struct { 24 testName string 25 name string 26 names []string 27 exp []string 28 }{ 29 { 30 name: "sdb", 31 names: []string{"sdb1", "sdb2", "sdc1"}, 32 testName: "Filtering partitions of two disks", 33 exp: []string{"sdb1", "sdb2"}, 34 }, 35 { 36 name: "sdd", 37 names: []string{"sdb1", "sdc1", "sdc2", "sdd1"}, 38 testName: "Filtering partitions of three disks", 39 exp: []string{"sdd1"}, 40 }, 41 } 42 43 for _, e := range testCases { 44 res := FilterPartitions(e.name, e.names) 45 if !reflect.DeepEqual(res, e.exp) { 46 t.Errorf("Test failed : %v , expected : %v , got : %v", e.testName, e.exp, res) 47 } 48 49 } 50 51 }