diff --git a/pkg/util/kubectl/main.go b/pkg/util/kubectl/cmd.go similarity index 76% rename from pkg/util/kubectl/main.go rename to pkg/util/kubectl/cmd.go index d8e44e1f1..fad22b2ef 100644 --- a/pkg/util/kubectl/main.go +++ b/pkg/util/kubectl/cmd.go @@ -7,8 +7,16 @@ import ( "github.com/devstream-io/devstream/pkg/util/log" ) -const APPLY string = "apply" -const DELETE string = "delete" +const ( + CREATE string = "create" + APPLY string = "apply" + DELETE string = "delete" +) + +// KubeCreate runs "kubectl create -f filename" +func KubeCreate(filename string) error { + return kubectlAction(CREATE, filename) +} // KubeApply runs "kubectl apply -f filename" func KubeApply(filename string) error { diff --git a/pkg/util/kubectl/cmd_test.go b/pkg/util/kubectl/cmd_test.go new file mode 100644 index 000000000..eb563cad0 --- /dev/null +++ b/pkg/util/kubectl/cmd_test.go @@ -0,0 +1,80 @@ +package kubectl + +import ( + "testing" +) + +var fileName = "nginx-deployment.yaml" + +func TestKubeCreate(t *testing.T) { + tests := []struct { + name string + filename string + wantErr bool + }{ + // TODO: Add test cases. + {"base", fileName, true}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := KubeCreate(tt.filename); (err != nil) != tt.wantErr { + t.Errorf("KubeCreate() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestKubeApply(t *testing.T) { + tests := []struct { + name string + filename string + wantErr bool + }{ + // TODO: Add test cases. + {"base", fileName, true}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := KubeApply(tt.filename); (err != nil) != tt.wantErr { + t.Errorf("KubeApply() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestKubeDelete(t *testing.T) { + tests := []struct { + name string + filename string + wantErr bool + }{ + // TODO: Add test cases. + {"base", fileName, true}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := KubeDelete(tt.filename); (err != nil) != tt.wantErr { + t.Errorf("KubeDelete() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func Test_kubectlAction(t *testing.T) { + tests := []struct { + name string + action string + filename string + wantErr bool + }{ + // TODO: Add test cases. + {"base", APPLY, fileName, true}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := kubectlAction(tt.action, tt.filename); (err != nil) != tt.wantErr { + t.Errorf("kubectlAction() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +}