Skip to content

Commit 53602fe

Browse files
committed
update tests
1 parent e9dab14 commit 53602fe

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

pkg/skaffold/deploy/helm/helm_test.go

+36
Original file line numberDiff line numberDiff line change
@@ -1686,3 +1686,39 @@ MANIFEST:
16861686
---
16871687
%s`, namespace, manifest)
16881688
}
1689+
1690+
func TestHasRunnableHooks(t *testing.T) {
1691+
tests := []struct {
1692+
description string
1693+
cfg latestV1.HelmDeploy
1694+
expected bool
1695+
}{
1696+
{
1697+
description: "no hooks defined",
1698+
cfg: latestV1.HelmDeploy{},
1699+
},
1700+
{
1701+
description: "has pre-deploy hook defined",
1702+
cfg: latestV1.HelmDeploy{
1703+
LifecycleHooks: latestV1.DeployHooks{PreHooks: []latestV1.DeployHookItem{{}}},
1704+
},
1705+
expected: true,
1706+
},
1707+
{
1708+
description: "has post-deploy hook defined",
1709+
cfg: latestV1.HelmDeploy{
1710+
LifecycleHooks: latestV1.DeployHooks{PostHooks: []latestV1.DeployHookItem{{}}},
1711+
},
1712+
expected: true,
1713+
},
1714+
}
1715+
for _, test := range tests {
1716+
testutil.Run(t, test.description, func(t *testutil.T) {
1717+
t.Override(&util.DefaultExecCommand, testutil.CmdRunWithOutput("helm version --client", version31))
1718+
k, err := NewDeployer(context.Background(), &helmConfig{}, &label.DefaultLabeller{}, &test.cfg)
1719+
t.RequireNoError(err)
1720+
actual := k.HasRunnableHooks()
1721+
t.CheckDeepEqual(test.expected, actual)
1722+
})
1723+
}
1724+
}

pkg/skaffold/deploy/kubectl/kubectl_test.go

+35
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,41 @@ func TestGCSManifests(t *testing.T) {
737737
}
738738
}
739739

740+
func TestHasRunnableHooks(t *testing.T) {
741+
tests := []struct {
742+
description string
743+
cfg latestV1.KubectlDeploy
744+
expected bool
745+
}{
746+
{
747+
description: "no hooks defined",
748+
cfg: latestV1.KubectlDeploy{},
749+
},
750+
{
751+
description: "has pre-deploy hook defined",
752+
cfg: latestV1.KubectlDeploy{
753+
LifecycleHooks: latestV1.DeployHooks{PreHooks: []latestV1.DeployHookItem{{}}},
754+
},
755+
expected: true,
756+
},
757+
{
758+
description: "has post-deploy hook defined",
759+
cfg: latestV1.KubectlDeploy{
760+
LifecycleHooks: latestV1.DeployHooks{PostHooks: []latestV1.DeployHookItem{{}}},
761+
},
762+
expected: true,
763+
},
764+
}
765+
for _, test := range tests {
766+
testutil.Run(t, test.description, func(t *testutil.T) {
767+
k, err := NewDeployer(&kubectlConfig{}, &label.DefaultLabeller{}, &test.cfg)
768+
t.RequireNoError(err)
769+
actual := k.HasRunnableHooks()
770+
t.CheckDeepEqual(test.expected, actual)
771+
})
772+
}
773+
}
774+
740775
type kubectlConfig struct {
741776
runcontext.RunContext // Embedded to provide the default values.
742777
workingDir string

pkg/skaffold/deploy/kustomize/kustomize_test.go

+35
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,41 @@ spec:
772772
}
773773
}
774774

775+
func TestHasRunnableHooks(t *testing.T) {
776+
tests := []struct {
777+
description string
778+
cfg latestV1.KustomizeDeploy
779+
expected bool
780+
}{
781+
{
782+
description: "no hooks defined",
783+
cfg: latestV1.KustomizeDeploy{},
784+
},
785+
{
786+
description: "has pre-deploy hook defined",
787+
cfg: latestV1.KustomizeDeploy{
788+
LifecycleHooks: latestV1.DeployHooks{PreHooks: []latestV1.DeployHookItem{{}}},
789+
},
790+
expected: true,
791+
},
792+
{
793+
description: "has post-deploy hook defined",
794+
cfg: latestV1.KustomizeDeploy{
795+
LifecycleHooks: latestV1.DeployHooks{PostHooks: []latestV1.DeployHookItem{{}}},
796+
},
797+
expected: true,
798+
},
799+
}
800+
for _, test := range tests {
801+
testutil.Run(t, test.description, func(t *testutil.T) {
802+
k, err := NewDeployer(&kustomizeConfig{}, &label.DefaultLabeller{}, &test.cfg)
803+
t.RequireNoError(err)
804+
actual := k.HasRunnableHooks()
805+
t.CheckDeepEqual(test.expected, actual)
806+
})
807+
}
808+
}
809+
775810
type kustomizeConfig struct {
776811
runcontext.RunContext // Embedded to provide the default values.
777812
force bool

0 commit comments

Comments
 (0)