From 900ee1bba57481ed41475b6fa611ec9456f6ccb8 Mon Sep 17 00:00:00 2001 From: Petr Fedchenkov Date: Thu, 12 Nov 2020 16:06:38 +0300 Subject: [PATCH] states list for failed app Signed-off-by: Petr Fedchenkov --- cmd/edenPod.go | 2 +- tests/app/app_test.go | 47 ++++++++++++++++++++++++++++++++++--------- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/cmd/edenPod.go b/cmd/edenPod.go index a59fc150b..4d41fa569 100644 --- a/cmd/edenPod.go +++ b/cmd/edenPod.go @@ -210,7 +210,7 @@ func getPortMapping(appConfig *config.AppInstanceConfig, qemuPorts map[string]st //podPsCmd is a command to list deployed apps var podPsCmd = &cobra.Command{ Use: "ps", - Short: "List podsList", + Short: "List pods", PreRunE: func(cmd *cobra.Command, args []string) error { assignCobraToViper(cmd) _, err := utils.LoadConfigFile(configFile) diff --git a/tests/app/app_test.go b/tests/app/app_test.go index 7e4bdc54a..cbe5be116 100644 --- a/tests/app/app_test.go +++ b/tests/app/app_test.go @@ -16,7 +16,7 @@ import ( var ( timewait = flag.Duration("timewait", time.Minute, "Timewait for items waiting") tc *projects.TestContext - found map[string]string + states map[string][]string ) // TestMain is used to provide setup and teardown for the rest of the @@ -41,6 +41,24 @@ func TestMain(m *testing.M) { os.Exit(res) } +// checkNewLastState returns true if provided state not equals with last +func checkNewLastState(appName, state string) bool { + appStates, ok := states[appName] + if ok { + lastState := appStates[len(appStates)-1] + if lastState != state { + return true + } + } + return false +} + +func checkAndAppendState(appName, state string) { + if checkNewLastState(appName, state) { + states[appName] = append(states[appName], state) + } +} + //checkApp wait for info of ZInfoApp type with state func checkApp(state string, appNames []string) projects.ProcInfoFunc { return func(msg *info.ZInfoMsg) error { @@ -50,7 +68,7 @@ func checkApp(state string, appNames []string) projects.ProcInfoFunc { foundAny := false for _, app := range msg.GetDinfo().AppInstances { if _, inSlice := utils.FindEleInSlice(appNames, app.Name); inSlice { - found[app.Name] = "EXISTS" + checkAndAppendState(app.Name, "EXISTS") foundAny = true } } @@ -68,12 +86,17 @@ func checkApp(state string, appNames []string) projects.ProcInfoFunc { if msg.Ztype == info.ZInfoTypes_ZiApp { app := msg.GetAinfo() if _, inSlice := utils.FindEleInSlice(appNames, app.AppName); inSlice { - found[app.AppName] = app.State.String() + if len(app.AppErr) > 0 { + //if AppErr, show them + checkAndAppendState(app.AppName, fmt.Sprintf("%s: %s", app.State.String(), app.AppErr)) + } else { + checkAndAppendState(app.AppName, app.State.String()) + } } } - if len(found) == len(appNames) { + if len(states) == len(appNames) { for _, appName := range appNames { - if astate, inFoundSlice := found[appName]; inFoundSlice && astate == state { + if !checkNewLastState(appName, state) { out += fmt.Sprintf( "app %s state %s\n", appName, state) @@ -104,17 +127,23 @@ func TestAppStatus(t *testing.T) { args[1:], state, secs) apps := args[1:] - found = make(map[string]string) + states = make(map[string][]string) for _, el := range apps { - found[el] = "no info from controller" + states[el] = []string{"no info from controller"} } tc.AddProcInfo(edgeNode, checkApp(state, apps)) callback := func() { t.Errorf("ASSERTION FAILED: expected apps %s in %s state", apps, state) - for k, v := range found { - t.Errorf("\tactual app %s: %s", k, v) + for k, v := range states { + t.Errorf("\tactual %s: %s", k, v[len(v)-1]) + if checkNewLastState(k, state) { + t.Errorf("\thistory of states for %s:", k) + for _, st := range v { + t.Errorf("\t\t%s", st) + } + } } }