github.com/devseccon/trivy@v0.47.1-0.20231123133102-bd902a0bd996/pkg/flag/kubernetes_flags_test.go (about)

     1  package flag
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/samber/lo"
     7  	"github.com/stretchr/testify/assert"
     8  	corev1 "k8s.io/api/core/v1"
     9  )
    10  
    11  func TestOptionToToleration(t *testing.T) {
    12  
    13  	tests := []struct {
    14  		name               string
    15  		tolerationsOptions []string
    16  		want               []corev1.Toleration
    17  	}{
    18  		{
    19  			name:               "no execute",
    20  			tolerationsOptions: []string{"key1=CriticalAddonsOnly:NoExecute:3600"},
    21  			want: []corev1.Toleration{
    22  				{
    23  					Key:               "key1",
    24  					Operator:          "Equal",
    25  					Value:             "CriticalAddonsOnly",
    26  					Effect:            "NoExecute",
    27  					TolerationSeconds: lo.ToPtr(int64(3600)),
    28  				},
    29  			},
    30  		},
    31  		{
    32  			name:               "no schedule",
    33  			tolerationsOptions: []string{"key1=CriticalAddonsOnly:NoSchedule"},
    34  			want: []corev1.Toleration{
    35  				{
    36  					Key:      "key1",
    37  					Operator: "Equal",
    38  					Value:    "CriticalAddonsOnly",
    39  					Effect:   "NoSchedule",
    40  				},
    41  			},
    42  		},
    43  	}
    44  	for _, tt := range tests {
    45  		t.Run(tt.name, func(t *testing.T) {
    46  			got, err := optionToTolerations(tt.tolerationsOptions)
    47  			assert.NoError(t, err)
    48  			assert.Equal(t, got, tt.want)
    49  		})
    50  	}
    51  }