MCPcopy Create free account
hub / github.com/prometheus/common / TestTLSVersionMarshalJSON

Function TestTLSVersionMarshalJSON

config/tls_config_test.go:183–221  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

181}
182
183func 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}

Callers

nothing calls this directly

Calls 2

TLSVersionTypeAlias · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected