github.com/zmap/zlint@v1.1.0/lints/result_test.go (about) 1 package lints 2 3 import ( 4 "encoding/json" 5 "testing" 6 ) 7 8 func TestMarshalingLintStatus(t *testing.T) { 9 testCases := []struct { 10 result LintStatus 11 expectedJSON string 12 }{ 13 { 14 result: Reserved, 15 expectedJSON: `"reserved"`, 16 }, 17 { 18 result: NA, 19 expectedJSON: `"NA"`, 20 }, 21 { 22 result: NE, 23 expectedJSON: `"NE"`, 24 }, 25 { 26 result: Pass, 27 expectedJSON: `"pass"`, 28 }, 29 { 30 result: Notice, 31 expectedJSON: `"info"`, 32 }, 33 { 34 result: Warn, 35 expectedJSON: `"warn"`, 36 }, 37 { 38 result: Error, 39 expectedJSON: `"error"`, 40 }, 41 { 42 result: Fatal, 43 expectedJSON: `"fatal"`, 44 }, 45 } 46 47 for _, tc := range testCases { 48 t.Run(tc.result.String(), func(t *testing.T) { 49 j, err := json.Marshal(tc.result) 50 if err != nil { 51 t.Error("Failed to marshal LintStatus") 52 } 53 if string(j) != tc.expectedJSON { 54 t.Errorf("Expected LintStatus to marshal to JSON %q, got %q", 55 tc.expectedJSON, 56 j) 57 } 58 var in LintStatus 59 if err := json.Unmarshal(j, &in); err != nil { 60 t.Errorf("Expected to unmarshal %q without error. Got %v", j, err) 61 } 62 if in != tc.result { 63 t.Errorf("Expected to unmarshal %q to %#v, got %#v", j, tc.result, in) 64 } 65 }) 66 } 67 68 }