Skip to content

Commit

Permalink
Add planKubectl test
Browse files Browse the repository at this point in the history
  • Loading branch information
poornima-krishnasamy committed Dec 4, 2023
1 parent 98c7d04 commit d35bdd6
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions pkg/environment/environmentApply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,61 @@ func TestApply_ApplyTerraform(t *testing.T) {
}
}

func TestApply_PlanKubectl(t *testing.T) {
type fields struct {
Options *Options
RequiredEnvVars RequiredEnvVars
Applier Applier
Dir string
}
tests := []struct {
name string
fields fields
KubectlOutputs string
checkExpectations func(t *testing.T, kubectl *mocks.Applier, outputs string, err error)
}{
{
name: "Apply foo namespace",
fields: fields{
Options: &Options{
Namespace: "foobar",
KubecfgPath: "/root/.kube/config",
ClusterCtx: "testctx",
},
RequiredEnvVars: RequiredEnvVars{
clustername: "cluster01",
clusterstatebucket: "clusterstatebucket",
kubernetescluster: "kubernetescluster01",
githubowner: "githubowner",
githubtoken: "githubtoken",
pingdomapitoken: "pingdomApikey",
},
Dir: "/root/foo",
},
KubectlOutputs: "/root/foo",
checkExpectations: func(t *testing.T, apply *mocks.Applier, outputs string, err error) {
apply.AssertCalled(t, "KubectlApply", "foobar", "/root/foo", false)
assert.Nil(t, err)
assert.Len(t, outputs, 9)
},
},
}
for i := range tests {
kubectl := new(mocks.Applier)
kubectl.On("KubectlApply", "foobar", tests[i].fields.Dir, false).Return(tests[i].KubectlOutputs, nil)
a := Apply{
RequiredEnvVars: tests[i].fields.RequiredEnvVars,
Applier: kubectl,
Dir: tests[i].fields.Dir,
Options: tests[i].fields.Options,
}
outputs, err := a.applyKubectl()
t.Run(tests[i].name, func(t *testing.T) {
tests[i].checkExpectations(t, kubectl, outputs, err)
})
}
}

func TestApply_ApplyKubectl(t *testing.T) {
type fields struct {
Options *Options
Expand Down

0 comments on commit d35bdd6

Please sign in to comment.