Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>
This commit is contained in:
Mukundan Sundararajan 2023-08-31 11:39:42 +05:30
parent 8c0ebdcdc8
commit dd77acd778
1 changed files with 22 additions and 14 deletions

View File

@ -199,7 +199,7 @@ func GetTestsOnUninstall(details VersionDetails, opts TestOptions) []TestCase {
{"crds exist on uninstall " + details.RuntimeVersion, CRDTest(details, opts)},
{"clusterroles not exist " + details.RuntimeVersion, ClusterRolesTest(details, opts)},
{"clusterrolebindings not exist " + details.RuntimeVersion, ClusterRoleBindingsTest(details, opts)},
{"check components exist on uninstall " + details.RuntimeVersion, componentsTestOnUninstall(opts.UninstallAll)},
{"check components exist on uninstall " + details.RuntimeVersion, componentsTestOnUninstall(opts)},
{"check httpendpoints exist on uninstall " + details.RuntimeVersion, httpEndpointsTestOnUninstall(opts)},
{"check mtls error " + details.RuntimeVersion, uninstallMTLSTest()},
{"check status error " + details.RuntimeVersion, statusTestOnUninstall()},
@ -310,7 +310,7 @@ func ComponentsTestOnInstallUpgrade(opts TestOptions) func(t *testing.T) {
t.Log("check applied component exists")
output, err := spawn.Command(daprPath, "components", "-k")
require.NoError(t, err, "expected no error on calling dapr components")
componentOutputCheck(t, output, false)
componentOutputCheck(t, opts, output)
}
}
@ -853,7 +853,7 @@ func uninstallMTLSTest() func(t *testing.T) {
}
}
func componentsTestOnUninstall(all bool) func(t *testing.T) {
func componentsTestOnUninstall(opts TestOptions) func(t *testing.T) {
return func(t *testing.T) {
daprPath := GetDaprPath()
// On Dapr uninstall CRDs are not removed, consequently the components will not be removed.
@ -861,10 +861,10 @@ func componentsTestOnUninstall(all bool) func(t *testing.T) {
// For now the components remain.
output, err := spawn.Command(daprPath, "components", "-k")
require.NoError(t, err, "expected no error on calling dapr components")
componentOutputCheck(t, output, all)
componentOutputCheck(t, opts, output)
// If --all, then the below does not need to run.
if all {
if opts.UninstallAll {
output, err = spawn.Command("kubectl", "delete", "-f", "../testdata/namespace.yaml")
require.NoError(t, err, "expected no error on kubectl delete")
t.Log(output)
@ -928,20 +928,26 @@ func statusTestOnUninstall() func(t *testing.T) {
}
}
func componentOutputCheck(t *testing.T, output string, all bool) {
func componentOutputCheck(t *testing.T, opts TestOptions, output string) {
output = strings.TrimSpace(output) // remove empty string.
lines := strings.Split(output, "\n")
for i, line := range lines {
t.Logf("num:%d line:%+v", i, line)
}
if all {
if opts.UninstallAll {
assert.Equal(t, 2, len(lines), "expected at 0 components and 2 output lines")
return
}
lines = strings.Split(output, "\n")[2:] // remove header and warning message.
if opts.DevEnabled {
// default, test statestore.
// default pubsub.
// 3 components
assert.Equal(t, 3, len(lines), "expected 3 components")
} else {
assert.Equal(t, 2, len(lines), "expected 2 components") // default and test namespace components.
// for fresh cluster only one component yaml has been applied.
@ -949,9 +955,11 @@ func componentOutputCheck(t *testing.T, output string, all bool) {
defaultNsFields := strings.Fields(lines[1])
// Fields splits on space, so Created time field might be split again.
// Scopes are only applied in for this scenario in tests.
namespaceComponentOutputCheck(t, testNsFields, "test")
namespaceComponentOutputCheck(t, defaultNsFields, "default")
}
}
func namespaceComponentOutputCheck(t *testing.T, fields []string, namespace string) {
assert.GreaterOrEqual(t, len(fields), 6, "expected at least 6 fields in components output")