github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/syft/internal/sourcemetadata/names_test.go (about) 1 package sourcemetadata 2 3 import ( 4 "reflect" 5 "testing" 6 7 "github.com/google/go-cmp/cmp" 8 "github.com/stretchr/testify/assert" 9 "github.com/stretchr/testify/require" 10 ) 11 12 func TestAllNames(t *testing.T) { 13 // note: this is a form of completion testing relative to the current code base. 14 15 expected, err := DiscoverTypeNames() 16 require.NoError(t, err) 17 18 actual := AllTypeNames() 19 20 // ensure that the codebase (from ast analysis) reflects the latest code generated state 21 if !assert.ElementsMatch(t, expected, actual) { 22 t.Errorf("metadata types not fully represented: \n%s", cmp.Diff(expected, actual)) 23 t.Log("did you add a new source.*Metadata type without updating the JSON schema?") 24 t.Log("if so, you need to update the schema version and regenerate the JSON schema (make generate-json-schema)") 25 } 26 27 for _, ty := range AllTypes() { 28 assert.NotEmpty(t, JSONName(ty), "metadata type %q does not have a JSON name", reflect.TypeOf(ty).Name()) 29 } 30 }