github.com/devseccon/trivy@v0.47.1-0.20231123133102-bd902a0bd996/pkg/fanal/analyzer/config/dockerfile/docker_test.go (about)

     1  package dockerfile
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func Test_dockerConfigAnalyzer_Required(t *testing.T) {
    10  	tests := []struct {
    11  		name     string
    12  		filePath string
    13  		want     bool
    14  	}{
    15  		{
    16  			name:     "dockerfile",
    17  			filePath: "dockerfile",
    18  			want:     true,
    19  		},
    20  		{
    21  			name:     "Dockerfile",
    22  			filePath: "Dockerfile",
    23  			want:     true,
    24  		},
    25  		{
    26  			name:     "Dockerfile with ext",
    27  			filePath: "Dockerfile.build",
    28  			want:     true,
    29  		},
    30  		{
    31  			name:     "dockerfile as ext",
    32  			filePath: "build.dockerfile",
    33  			want:     true,
    34  		},
    35  		{
    36  			name:     "Dockerfile in dir",
    37  			filePath: "docker/Dockerfile",
    38  			want:     true,
    39  		},
    40  		{
    41  			name:     "Dockerfile as prefix",
    42  			filePath: "Dockerfilebuild",
    43  			want:     false,
    44  		},
    45  		{
    46  			name:     "Dockerfile as suffix",
    47  			filePath: "buildDockerfile",
    48  			want:     false,
    49  		},
    50  		{
    51  			name:     "Dockerfile as prefix with ext",
    52  			filePath: "Dockerfilebuild.sh",
    53  			want:     false,
    54  		},
    55  		{
    56  			name:     "Dockerfile as suffix with ext",
    57  			filePath: "buildDockerfile.sh",
    58  			want:     false,
    59  		},
    60  		{
    61  			name:     "json",
    62  			filePath: "deployment.json",
    63  			want:     false,
    64  		},
    65  	}
    66  	for _, tt := range tests {
    67  		t.Run(tt.name, func(t *testing.T) {
    68  			s := dockerConfigAnalyzer{}
    69  			got := s.Required(tt.filePath, nil)
    70  			assert.Equal(t, tt.want, got)
    71  		})
    72  	}
    73  }