github.com/openebs/api@v1.12.0/pkg/util/unixsock_test.go (about) 1 // Copyright © 2020 The OpenEBS Authors 2 // 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 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package util 16 17 import ( 18 "testing" 19 ) 20 21 func TestIsResponseEOD(t *testing.T) { 22 tests := map[string]struct { 23 resp []string 24 cmd string 25 expectedresult bool 26 }{ 27 "empty response": { 28 resp: []string{}, 29 cmd: "STATUS", 30 expectedresult: false, 31 }, 32 "only header line in response": { 33 resp: []string{"iSCSI Target Controller version istgt:0.5.20121028:08:47:01:Aug 28 2018 on from\r\n"}, 34 cmd: "STATUS", 35 expectedresult: false, 36 }, 37 "header line along with incomplete output in response": { 38 resp: []string{"iSCSI Target Controller version istgt:0.5.20121028:08:47:01:Aug 28 2018 on from\r\n", "STATUS iqn FAKE\r\n"}, 39 cmd: "STATUS", 40 expectedresult: false, 41 }, 42 "header line with complete output in response": { 43 resp: []string{"iSCSI Target Controller version istgt:0.5.20121028:08:47:01:Aug 28 2018 on from\r\n", "STATUS iqn FAKE\r\n", "OK STATUS\r\n"}, 44 cmd: "STATUS", 45 expectedresult: true, 46 }, 47 } 48 49 for name, mock := range tests { 50 t.Run(name, func(t *testing.T) { 51 result := IsResponseEOD(mock.resp, mock.cmd) 52 if mock.expectedresult != result { 53 t.Fatalf("failed test '%s' - expected result '%v': actual result '%v'", name, mock.expectedresult, result) 54 } 55 }) 56 } 57 }