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

     1  package terraform
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestConfigAnalyzer_Required(t *testing.T) {
    10  	tests := []struct {
    11  		name     string
    12  		filePath string
    13  		want     bool
    14  	}{
    15  		{
    16  			name:     "tf",
    17  			filePath: "/path/to/main.tf",
    18  			want:     true,
    19  		},
    20  		{
    21  			name:     "tf.json",
    22  			filePath: "/path/to/main.tf.json",
    23  			want:     true,
    24  		},
    25  		{
    26  			name:     "tfvars",
    27  			filePath: "/path/to/some.tfvars",
    28  			want:     true,
    29  		},
    30  		{
    31  			name:     "json",
    32  			filePath: "/path/to/some.json",
    33  			want:     false,
    34  		},
    35  		{
    36  			name:     "hcl",
    37  			filePath: "/path/to/main.hcl",
    38  			want:     false,
    39  		},
    40  		{
    41  			name:     "yaml",
    42  			filePath: "deployment.yaml",
    43  			want:     false,
    44  		},
    45  	}
    46  	for _, tt := range tests {
    47  		t.Run(tt.name, func(t *testing.T) {
    48  			a := terraformConfigAnalyzer{}
    49  			got := a.Required(tt.filePath, nil)
    50  			assert.Equal(t, tt.want, got)
    51  		})
    52  	}
    53  }