github.com/anchore/syft@v1.38.2/syft/pkg/cataloger/internal/licenses/names_test.go (about) 1 package licenses 2 3 import ( 4 "testing" 5 ) 6 7 func Test_IsLicenseFile(t *testing.T) { 8 tests := []struct { 9 name string 10 input string 11 want bool 12 }{ 13 // positive cases (should be detected as license files) 14 {"plain LICENSE", "LICENSE", true}, 15 {"lowercase license", "license", true}, 16 {"license with extension", "LICENSE.txt", true}, 17 {"mixed case", "LiCeNsE", true}, 18 {"copying", "COPYING", true}, 19 {"AL2.0", "AL2.0", true}, 20 {"notice", "NOTICE", true}, 21 {"mit-license", "MIT-License", true}, 22 {"unlicense", "UNLICENSE", true}, 23 {"licence variant", "LICENCE", true}, 24 {"license markdown", "license.md", true}, 25 26 // negative cases (should NOT be detected) 27 {"AL1.0", "AL1.0", false}, 28 {"readme", "README", false}, 29 {"readme with ext", "README.md", false}, 30 {"not a license", "not_a_license", false}, 31 {"licensor (prefix-like but not)", "LICENSOR", false}, 32 {"too short (below minLength)", "a", false}, 33 } 34 35 for _, tt := range tests { 36 tt := tt 37 t.Run(tt.name, func(t *testing.T) { 38 t.Parallel() 39 got := IsLicenseFile(tt.input) 40 if got != tt.want { 41 t.Fatalf("IsLicenseFile(%q) = %v, want %v", tt.input, got, tt.want) 42 } 43 }) 44 } 45 }