(t *testing.T)
| 181 | } |
| 182 | |
| 183 | func TestTLSVersionMarshalJSON(t *testing.T) { |
| 184 | tests := []struct { |
| 185 | input TLSVersion |
| 186 | expected string |
| 187 | err error |
| 188 | }{ |
| 189 | { |
| 190 | input: TLSVersions["TLS13"], |
| 191 | expected: `"TLS13"`, |
| 192 | err: nil, |
| 193 | }, |
| 194 | { |
| 195 | input: TLSVersions["TLS10"], |
| 196 | expected: `"TLS10"`, |
| 197 | err: nil, |
| 198 | }, |
| 199 | { |
| 200 | input: TLSVersion(999), |
| 201 | expected: "", |
| 202 | err: fmt.Errorf("unknown TLS version: 999"), |
| 203 | }, |
| 204 | } |
| 205 | |
| 206 | for _, test := range tests { |
| 207 | t.Run(fmt.Sprintf("MarshalJSON(%d)", test.input), func(t *testing.T) { |
| 208 | actualBytes, err := json.Marshal(&test.input) |
| 209 | if err != nil { |
| 210 | if test.err == nil || !strings.HasSuffix(err.Error(), test.err.Error()) { |
| 211 | t.Fatalf("error %v, expected %v", err, test.err) |
| 212 | } |
| 213 | return |
| 214 | } |
| 215 | actual := string(actualBytes) |
| 216 | if actual != test.expected { |
| 217 | t.Fatalf("returned %s, expected %s", actual, test.expected) |
| 218 | } |
| 219 | }) |
| 220 | } |
| 221 | } |
nothing calls this directly
no test coverage detected