(t *testing.T)
| 120 | } |
| 121 | |
| 122 | func TestReadResponse(t *testing.T) { |
| 123 | tests := []struct { |
| 124 | name string |
| 125 | chunks [][]byte |
| 126 | want string |
| 127 | wantErr bool |
| 128 | }{ |
| 129 | { |
| 130 | name: "single chunk", |
| 131 | chunks: [][]byte{[]byte("[=276428]\r\n")}, |
| 132 | want: "[=276428]", |
| 133 | }, |
| 134 | { |
| 135 | name: "split across reads", |
| 136 | chunks: [][]byte{[]byte("[=27"), []byte("6428]\r\n")}, |
| 137 | want: "[=276428]", |
| 138 | }, |
| 139 | { |
| 140 | name: "terminator split", |
| 141 | chunks: [][]byte{[]byte("[=42]\r"), []byte("\n")}, |
| 142 | want: "[=42]", |
| 143 | }, |
| 144 | { |
| 145 | name: "timeout before terminator", |
| 146 | chunks: [][]byte{[]byte("[=incomplete")}, |
| 147 | wantErr: true, |
| 148 | }, |
| 149 | { |
| 150 | name: "empty", |
| 151 | chunks: nil, |
| 152 | wantErr: true, |
| 153 | }, |
| 154 | } |
| 155 | for _, tc := range tests { |
| 156 | t.Run(tc.name, func(t *testing.T) { |
| 157 | m := newTestMac(&fakePort{chunks: tc.chunks}) |
| 158 | got, err := m.ReadResponse() |
| 159 | if tc.wantErr { |
| 160 | require.Error(t, err) |
| 161 | return |
| 162 | } |
| 163 | require.NoError(t, err) |
| 164 | require.Equal(t, tc.want, got) |
| 165 | }) |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | func TestGetSendsExpectedCommand(t *testing.T) { |
| 170 | fp := &fakePort{chunks: [][]byte{[]byte("[=276428]\r\n")}} |
nothing calls this directly
no test coverage detected
searching dependent graphs…