github.com/grafana/tanka@v0.26.1-0.20240506093700-c22cfc35c21a/pkg/kubernetes/client/delete_test.go (about)

     1  package client
     2  
     3  import (
     4  	"testing"
     5  
     6  	"k8s.io/apimachinery/pkg/util/sets"
     7  )
     8  
     9  func TestKubectl_deleteCtl(t *testing.T) {
    10  	info := Info{
    11  		Kubeconfig: Config{
    12  			Context: Context{
    13  				Name: "foo-context",
    14  			},
    15  		},
    16  	}
    17  
    18  	type args struct {
    19  		ns   string
    20  		kind string
    21  		name string
    22  		opts DeleteOpts
    23  	}
    24  
    25  	tests := []struct {
    26  		name           string
    27  		args           args
    28  		expectedArgs   []string
    29  		unExpectedArgs []string
    30  	}{
    31  		{
    32  			name: "test default",
    33  			args: args{
    34  				ns:   "foo-ns",
    35  				kind: "deploy",
    36  				name: "foo-deploy",
    37  				opts: DeleteOpts{},
    38  			},
    39  			expectedArgs:   []string{"--context", info.Kubeconfig.Context.Name, "-n", "foo-ns", "deploy", "foo-deploy"},
    40  			unExpectedArgs: []string{"--force", "--dry-run=server"},
    41  		},
    42  		{
    43  			name: "test dry-run",
    44  			args: args{
    45  				opts: DeleteOpts{DryRun: "server"},
    46  			},
    47  			expectedArgs: []string{"--dry-run=server"},
    48  		},
    49  		{
    50  			name: "test force",
    51  			args: args{
    52  				opts: DeleteOpts{Force: true},
    53  			},
    54  			expectedArgs: []string{"--force"},
    55  		},
    56  	}
    57  
    58  	for _, tt := range tests {
    59  		t.Run(tt.name, func(t *testing.T) {
    60  			k := Kubectl{
    61  				info: info,
    62  			}
    63  			got := k.deleteCtl(tt.args.ns, tt.args.kind, tt.args.name, tt.args.opts)
    64  			gotSet := sets.NewString(got.Args...)
    65  			if !gotSet.HasAll(tt.expectedArgs...) {
    66  				t.Errorf("Kubectl.applyCtl() = %v doesn't have (all) expectedArgs='%v'", got.Args, tt.expectedArgs)
    67  			}
    68  			if gotSet.HasAny(tt.unExpectedArgs...) {
    69  				t.Errorf("Kubectl.applyCtl() = %v has (any) unExpectedArgs='%v'", got.Args, tt.unExpectedArgs)
    70  			}
    71  		})
    72  	}
    73  }