github.com/devseccon/trivy@v0.47.1-0.20231123133102-bd902a0bd996/pkg/fanal/analyzer/config/helm/helm_test.go (about) 1 package helm 2 3 import ( 4 "os" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 "github.com/stretchr/testify/require" 9 ) 10 11 func Test_helmConfigAnalyzer_Required(t *testing.T) { 12 tests := []struct { 13 name string 14 filePath string 15 want bool 16 }{ 17 { 18 name: "yaml", 19 filePath: "Chart.yaml", 20 want: true, 21 }, 22 { 23 name: "yaml - shorthand", 24 filePath: "templates/deployment.yml", 25 want: true, 26 }, 27 { 28 name: "tpl", 29 filePath: "templates/_helpers.tpl", 30 want: true, 31 }, 32 { 33 name: "json", 34 filePath: "values.json", 35 want: true, 36 }, 37 { 38 name: "NOTES.txt", 39 filePath: "templates/NOTES.txt", 40 want: false, 41 }, 42 { 43 name: ".helmignore", 44 filePath: ".helmignore", 45 want: true, 46 }, 47 { 48 name: "testchart.tgz", 49 filePath: "testchart.tgz", 50 want: true, 51 }, 52 { 53 name: "testchart.tar.gz", 54 filePath: "testchart.tar.gz", 55 want: true, 56 }, 57 { 58 name: "nope.tgz", 59 filePath: "nope.tgz", 60 want: true, // it's a tarball after all 61 }, 62 } 63 for _, tt := range tests { 64 t.Run(tt.name, func(t *testing.T) { 65 s := helmConfigAnalyzer{} 66 67 // Create a dummy file info 68 info, err := os.Stat("./helm_test.go") 69 require.NoError(t, err) 70 71 got := s.Required(tt.filePath, info) 72 assert.Equal(t, tt.want, got) 73 }) 74 } 75 }