Skip to content

Commit 068a93e

Browse files
committed
test(installer): cover install/uninstall script contents
Adds two test cases to common_ubuntu_test.go asserting the rendered Install()/Uninstall() scripts reference the new bundle layout (raw kubeadm/kubelet/kubectl binaries, crictl.tar.gz, cni-plugins.tgz, runc, containerd.tar.gz) and contain no leftover dpkg/.deb references -- guarding against the exact regression this branch fixes (templates drifting from what the bundle builder actually packages) without needing a real bundle or host.
1 parent dce5bfc commit 068a93e

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

installer/internal/algo/common_ubuntu_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,58 @@ func TestBaseUbuntuInstallerUninstallKernelModuleCleanup(t *testing.T) {
4343
})
4444
}
4545
}
46+
47+
// TestBaseUbuntuInstallerInstallsBundleContent guards against install.sh.tmpl drifting from what
48+
// the bundle builder (installer/bundle_builder/build-bundle.sh) actually packages: kubeadm,
49+
// kubelet and kubectl as raw binaries, crictl and CNI plugins as tarballs, runc as a raw binary,
50+
// and containerd as a plain (non-deprecated) release tarball -- not apt .deb packages.
51+
func TestBaseUbuntuInstallerInstallsBundleContent(t *testing.T) {
52+
installer, err := algo.NewBaseUbuntuInstaller(context.Background(), "amd64", "test-bundle", "", false)
53+
require.NoError(t, err)
54+
55+
installScript := installer.Install()
56+
57+
wantSubstrings := []string{
58+
`install -m 0755 "$BUNDLE_PATH/kubeadm" /usr/bin/kubeadm`,
59+
`install -m 0755 "$BUNDLE_PATH/kubelet" /usr/bin/kubelet`,
60+
`install -m 0755 "$BUNDLE_PATH/kubectl" /usr/bin/kubectl`,
61+
`tar -C /usr/local/bin -xvf "$BUNDLE_PATH/crictl.tar.gz"`,
62+
`tar -C /opt/cni/bin -xvf "$BUNDLE_PATH/cni-plugins.tgz"`,
63+
`install -m 0755 "$BUNDLE_PATH/runc" /usr/local/sbin/runc`,
64+
`tar -C /usr/local -xvf "$BUNDLE_PATH/containerd.tar.gz"`,
65+
}
66+
for _, want := range wantSubstrings {
67+
assert.Contains(t, installScript, want)
68+
}
69+
70+
unwantedSubstrings := []string{"dpkg --install", ".deb"}
71+
for _, unwanted := range unwantedSubstrings {
72+
assert.NotContains(t, installScript, unwanted)
73+
}
74+
}
75+
76+
// TestBaseUbuntuInstallerUninstallsBundleContent is the removal-side counterpart of
77+
// TestBaseUbuntuInstallerInstallsBundleContent -- every path install.sh.tmpl creates must have a
78+
// matching removal in uninstall.sh.tmpl.
79+
func TestBaseUbuntuInstallerUninstallsBundleContent(t *testing.T) {
80+
installer, err := algo.NewBaseUbuntuInstaller(context.Background(), "amd64", "test-bundle", "", false)
81+
require.NoError(t, err)
82+
83+
uninstallScript := installer.Uninstall()
84+
85+
wantSubstrings := []string{
86+
"rm -f /usr/bin/kubeadm /usr/bin/kubelet /usr/bin/kubectl",
87+
"rm -f /usr/local/sbin/runc",
88+
`tar tzf "$BUNDLE_PATH/crictl.tar.gz"`,
89+
`tar tzf "$BUNDLE_PATH/containerd.tar.gz"`,
90+
"rm -rf /opt/cni/",
91+
}
92+
for _, want := range wantSubstrings {
93+
assert.Contains(t, uninstallScript, want)
94+
}
95+
96+
unwantedSubstrings := []string{"dpkg --purge", "dpkg -l"}
97+
for _, unwanted := range unwantedSubstrings {
98+
assert.NotContains(t, uninstallScript, unwanted)
99+
}
100+
}

0 commit comments

Comments
 (0)