■ ■ ■ ■ ■ ■
syft/formats/syftjson/decoder_test.go
skipped 1 lines 2 2 3 3 import ( 4 4 "bytes" 5 + "errors" 6 + "fmt" 5 7 "strings" 6 8 "testing" 7 9 skipped 42 lines 50 52 } 51 53 } 52 54 55 + func TestOutOfDateParser(t *testing.T) { 56 + tests := []struct { 57 + name string 58 + documentVersion string 59 + parserVersion string 60 + want error 61 + }{{ 62 + name: "no warning when doc version is older", 63 + documentVersion: "1.0.9", 64 + parserVersion: "3.1.0", 65 + }, { 66 + name: "warning when parser is older", 67 + documentVersion: "4.3.2", 68 + parserVersion: "3.1.0", 69 + want: fmt.Errorf("document has schema version %s, but parser has older schema version (%s)", "4.3.2", "3.1.0"), 70 + }, { 71 + name: "warning when document version is unparseable", 72 + documentVersion: "some-nonsense", 73 + parserVersion: "3.1.0", 74 + want: fmt.Errorf("error comparing document schema version with parser schema version: %w", errors.New("Invalid Semantic Version")), 75 + }, { 76 + name: "warning when parser version is unparseable", 77 + documentVersion: "7.1.0", 78 + parserVersion: "some-nonsense", 79 + want: fmt.Errorf("error comparing document schema version with parser schema version: %w", errors.New("Invalid Semantic Version")), 80 + }} 81 + 82 + for _, tt := range tests { 83 + t.Run(tt.name, func(t *testing.T) { 84 + got := checkSupportedSchema(tt.documentVersion, tt.parserVersion) 85 + assert.Equal(t, tt.want, got) 86 + }) 87 + } 88 + } 89 +