From 66a0e935aaa1e1c127720f29ac0fe307732c7f59 Mon Sep 17 00:00:00 2001 From: Mengyi Date: Thu, 21 Apr 2022 14:50:31 +0200 Subject: [PATCH 01/24] Add apps/config options tests for environment variable injection (#48) * Add `TestAppConfig()` test * Separate tests * Remove redundant subtest, move unset to cleanup - remove redundant subtest - move unset to cleanup - add comment for existing issue - improve words * Update device-rest's config_test * Do `snap set`, then `snap start` --- test/suites/device-mqtt/config_test.go | 106 +++++++++++++++++++++++-- test/suites/device-rest/config_test.go | 106 +++++++++++++++++++++++-- 2 files changed, 202 insertions(+), 10 deletions(-) diff --git a/test/suites/device-mqtt/config_test.go b/test/suites/device-mqtt/config_test.go index c7e2b9e..76aebdc 100644 --- a/test/suites/device-mqtt/config_test.go +++ b/test/suites/device-mqtt/config_test.go @@ -8,25 +8,121 @@ import ( // Deprecated func TestEnvConfig(t *testing.T) { // start clean - utils.SnapStop(t, deviceMqttService) + utils.SnapStop(t, deviceMqttSnap) t.Run("change service port", func(t *testing.T) { t.Cleanup(func() { - utils.SnapStop(t, deviceMqttService) - utils.SnapUnset(t, deviceMqttSnap, "env.service.port") + utils.SnapUnset(t, deviceMqttSnap, "env") + utils.SnapStop(t, deviceMqttSnap) }) - const newPort = "56789" + const newPort = "11111" // make sure the port is available before using it utils.RequirePortAvailable(t, newPort) + // set env. and validate the new port comes online utils.SnapSet(t, deviceMqttSnap, "env.service.port", newPort) utils.SnapStart(t, deviceMqttSnap) + utils.WaitServiceOnline(t, 60, newPort) + + // unset env. and validate the default port comes online + utils.SnapUnset(t, deviceMqttSnap, "env.service.port") + utils.SnapRestart(t, deviceMqttService) + + utils.WaitServiceOnline(t, 60, defaultServicePort) }) } func TestAppConfig(t *testing.T) { - t.Skip("TODO") + // start clean + utils.SnapStop(t, deviceMqttSnap) + + t.Run("set and unset apps.", func(t *testing.T) { + t.Cleanup(func() { + // temporary using unset apps and unset config together here to do unset apps' job + // until this issue been solved: https://github.com/canonical/edgex-snap-hooks/issues/43 + utils.SnapUnset(t, deviceMqttSnap, "apps.device-mqtt.config.service.port") + utils.SnapUnset(t, deviceMqttSnap, "config.service.port") + utils.SnapStop(t, deviceMqttSnap) + }) + + const newPort = "22222" + + // make sure the port is available before using it + utils.RequirePortAvailable(t, newPort) + + // set apps. and validate the new port comes online + utils.SnapSet(t, deviceMqttSnap, "apps.device-mqtt.config.service.port", newPort) + utils.SnapStart(t, deviceMqttSnap) + + utils.WaitServiceOnline(t, 60, newPort) + + // unset apps. and validate the default port comes online + // temporary using unset apps and unset config together here to do unset apps' job + // until this issue been solved: https://github.com/canonical/edgex-snap-hooks/issues/43 + utils.SnapUnset(t, deviceMqttSnap, "apps.device-mqtt.config.service.port") + utils.SnapUnset(t, deviceMqttSnap, "config.service.port") + utils.SnapRestart(t, deviceMqttService) + + utils.WaitServiceOnline(t, 60, defaultServicePort) + }) +} + +func TestGlobalConfig(t *testing.T) { + // start clean + utils.SnapStop(t, deviceMqttSnap) + + t.Run("set and unset apps.", func(t *testing.T) { + t.Cleanup(func() { + utils.SnapUnset(t, deviceMqttSnap, "config.service.port") + utils.SnapStop(t, deviceMqttSnap) + }) + + const newPort = "33333" + + // make sure the port is available before using it + utils.RequirePortAvailable(t, newPort) + + // set config. and validate the new port comes online + utils.SnapSet(t, deviceMqttSnap, "config.service.port", newPort) + utils.SnapStart(t, deviceMqttSnap) + + utils.WaitServiceOnline(t, 60, newPort) + + // unset config. and validate the default port comes online + utils.SnapUnset(t, deviceMqttSnap, "config.service.port") + utils.SnapRestart(t, deviceMqttService) + + utils.WaitServiceOnline(t, 60, defaultServicePort) + }) +} + +func TestMixedConfig(t *testing.T) { + // start clean + utils.SnapStop(t, deviceMqttSnap) + + t.Run("use apps. and config. for different values", func(t *testing.T) { + t.Cleanup(func() { + utils.SnapUnset(t, deviceMqttSnap, "apps.device-mqtt.config.service.port") + utils.SnapUnset(t, deviceMqttSnap, "config.service.port") + utils.SnapStop(t, deviceMqttService) + }) + + const newAppPort = "44444" + const newConfigPort = "55555" + + // make sure the ports are available before using it + utils.RequirePortAvailable(t, newAppPort) + utils.RequirePortAvailable(t, newConfigPort) + + // set apps. and config. with different values, + // and validate that app-specific option has been picked up because it has higher precedence + utils.SnapSet(t, deviceMqttSnap, "apps.device-mqtt.config.service.port", newAppPort) + utils.SnapSet(t, deviceMqttSnap, "config.service.port", newConfigPort) + utils.SnapStart(t, deviceMqttSnap) + + utils.WaitServiceOnline(t, 60, newAppPort) + }) } diff --git a/test/suites/device-rest/config_test.go b/test/suites/device-rest/config_test.go index 8da7e1f..f8e9641 100644 --- a/test/suites/device-rest/config_test.go +++ b/test/suites/device-rest/config_test.go @@ -7,25 +7,121 @@ import ( // Deprecated func TestEnvConfig(t *testing.T) { + // start clean + utils.SnapStop(t, deviceRestSnap) t.Run("change service port", func(t *testing.T) { t.Cleanup(func() { - utils.SnapStop(t, deviceRestService) - utils.SnapUnset(t, deviceRestSnap, "env.service.port") + utils.SnapUnset(t, deviceRestSnap, "env") + utils.SnapStop(t, deviceRestSnap) }) - const newPort = "56789" + const newPort = "11111" // make sure the port is available before using it utils.RequirePortAvailable(t, newPort) - utils.SnapStop(t, deviceRestSnap) + // set env. and validate the new port comes online utils.SnapSet(t, deviceRestSnap, "env.service.port", newPort) utils.SnapStart(t, deviceRestSnap) + utils.WaitServiceOnline(t, 60, newPort) + + // unset env. and validate the default port comes online + utils.SnapUnset(t, deviceRestSnap, "env.service.port") + utils.SnapRestart(t, deviceRestService) + utils.WaitServiceOnline(t, 60, defaultServicePort) }) } func TestAppConfig(t *testing.T) { - t.Skip("TODO") + // start clean + utils.SnapStop(t, deviceRestSnap) + + t.Run("set and unset apps.", func(t *testing.T) { + t.Cleanup(func() { + // temporary using unset apps and unset config together here to do unset apps' job + // until this issue been solved: https://github.com/canonical/edgex-snap-hooks/issues/43 + utils.SnapUnset(t, deviceRestSnap, "apps.device-rest.config.service.port") + utils.SnapUnset(t, deviceRestSnap, "config.service.port") + utils.SnapStop(t, deviceRestSnap) + }) + + const newPort = "22222" + + // make sure the port is available before using it + utils.RequirePortAvailable(t, newPort) + + // set apps. and validate the new port comes online + utils.SnapSet(t, deviceRestSnap, "apps.device-rest.config.service.port", newPort) + utils.SnapStart(t, deviceRestSnap) + + utils.WaitServiceOnline(t, 60, newPort) + + // unset apps. and validate the default port comes online + // temporary using unset apps and unset config together here to do unset apps' job + // until this issue been solved: https://github.com/canonical/edgex-snap-hooks/issues/43 + utils.SnapUnset(t, deviceRestSnap, "apps.device-rest.config.service.port") + utils.SnapUnset(t, deviceRestSnap, "config.service.port") + utils.SnapRestart(t, deviceRestService) + + utils.WaitServiceOnline(t, 60, defaultServicePort) + }) +} + +func TestGlobalConfig(t *testing.T) { + // start clean + utils.SnapStop(t, deviceRestSnap) + + t.Run("set and unset apps.", func(t *testing.T) { + t.Cleanup(func() { + utils.SnapUnset(t, deviceRestSnap, "config.service.port") + utils.SnapStop(t, deviceRestSnap) + }) + + const newPort = "33333" + + // make sure the port is available before using it + utils.RequirePortAvailable(t, newPort) + + // set config. and validate the new port comes online + utils.SnapSet(t, deviceRestSnap, "config.service.port", newPort) + utils.SnapStart(t, deviceRestSnap) + + utils.WaitServiceOnline(t, 60, newPort) + + // unset config. and validate the default port comes online + utils.SnapUnset(t, deviceRestSnap, "config.service.port") + utils.SnapRestart(t, deviceRestService) + + utils.WaitServiceOnline(t, 60, defaultServicePort) + }) +} + +func TestMixedConfig(t *testing.T) { + // start clean + utils.SnapStop(t, deviceRestSnap) + + t.Run("use apps. and config. for different values", func(t *testing.T) { + t.Cleanup(func() { + utils.SnapUnset(t, deviceRestSnap, "apps.device-rest.config.service.port") + utils.SnapUnset(t, deviceRestSnap, "config.service.port") + utils.SnapStop(t, deviceRestService) + }) + + const newAppPort = "44444" + const newConfigPort = "55555" + + // make sure the ports are available before using it + utils.RequirePortAvailable(t, newAppPort) + utils.RequirePortAvailable(t, newConfigPort) + + // set apps. and config. with different values, + // and validate that app-specific option has been picked up because it has higher precedence + utils.SnapSet(t, deviceRestSnap, "apps.device-rest.config.service.port", newAppPort) + utils.SnapSet(t, deviceRestSnap, "config.service.port", newConfigPort) + utils.SnapStart(t, deviceRestSnap) + + utils.WaitServiceOnline(t, 60, newAppPort) + }) } From f978f6ceeff2e8b9bf012f4f615458633f60ba03 Mon Sep 17 00:00:00 2001 From: Mengyi Date: Fri, 22 Apr 2022 12:28:36 +0200 Subject: [PATCH 02/24] Move config testing into util functions, add `FULL_CONFIG_TEST` option (#49) * Add `TestAppConfig()` test * Separate tests * Remove redundant subtest, move unset to cleanup - remove redundant subtest - move unset to cleanup - add comment for existing issue - improve words * Update device-rest's config_test * Do `snap set`, then `snap start` * Setting FULL_CONFIG_TEST make skipping of config subtests optional * Move config testing into util functions * Use boolean for `FullConfigTest`, add message for `t.Skip()` * Update `if else` and README format * Add `config-enabled` for new version hooks new version hooks: https://github.com/canonical/edgex-snap-hooks/pull/41 --- README.md | 8 ++ test/suites/device-mqtt/config_test.go | 114 ++------------------ test/suites/device-mqtt/main_test.go | 7 +- test/suites/device-rest/config_test.go | 111 +------------------ test/suites/device-rest/main_test.go | 7 +- test/utils/config.go | 143 +++++++++++++++++++++++++ test/utils/env.go | 11 +- 7 files changed, 181 insertions(+), 220 deletions(-) create mode 100644 test/utils/config.go diff --git a/README.md b/README.md index d04aed5..6442e74 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,14 @@ To test all: go test -p 1 ./test/suites/... ``` +Test one with variables, e.g.: +```bash +FULL_CONFIG_TEST=on go test -p 1 ./test/suites/device-mqtt +``` +```bash +LOCAL_SNAP="edgex-device-mqtt_2.0.1-dev.15_amd64.snap" go test -p 1 ./test/suites/device-mqtt +``` + Test the testing utils: ```bash go test ./test/utils -count=10 diff --git a/test/suites/device-mqtt/config_test.go b/test/suites/device-mqtt/config_test.go index 76aebdc..1abcf28 100644 --- a/test/suites/device-mqtt/config_test.go +++ b/test/suites/device-mqtt/config_test.go @@ -7,122 +7,20 @@ import ( // Deprecated func TestEnvConfig(t *testing.T) { - // start clean - utils.SnapStop(t, deviceMqttSnap) - - t.Run("change service port", func(t *testing.T) { - t.Cleanup(func() { - utils.SnapUnset(t, deviceMqttSnap, "env") - utils.SnapStop(t, deviceMqttSnap) - }) - - const newPort = "11111" - - // make sure the port is available before using it - utils.RequirePortAvailable(t, newPort) - - // set env. and validate the new port comes online - utils.SnapSet(t, deviceMqttSnap, "env.service.port", newPort) - utils.SnapStart(t, deviceMqttSnap) - - utils.WaitServiceOnline(t, 60, newPort) - - // unset env. and validate the default port comes online - utils.SnapUnset(t, deviceMqttSnap, "env.service.port") - utils.SnapRestart(t, deviceMqttService) - - utils.WaitServiceOnline(t, 60, defaultServicePort) - }) + utils.FullConfigTest = true + utils.SetEnvConfig(t, deviceMqttSnap, deviceMqttService, defaultServicePort) } func TestAppConfig(t *testing.T) { - // start clean - utils.SnapStop(t, deviceMqttSnap) - - t.Run("set and unset apps.", func(t *testing.T) { - t.Cleanup(func() { - // temporary using unset apps and unset config together here to do unset apps' job - // until this issue been solved: https://github.com/canonical/edgex-snap-hooks/issues/43 - utils.SnapUnset(t, deviceMqttSnap, "apps.device-mqtt.config.service.port") - utils.SnapUnset(t, deviceMqttSnap, "config.service.port") - utils.SnapStop(t, deviceMqttSnap) - }) - - const newPort = "22222" - - // make sure the port is available before using it - utils.RequirePortAvailable(t, newPort) - - // set apps. and validate the new port comes online - utils.SnapSet(t, deviceMqttSnap, "apps.device-mqtt.config.service.port", newPort) - utils.SnapStart(t, deviceMqttSnap) - - utils.WaitServiceOnline(t, 60, newPort) - - // unset apps. and validate the default port comes online - // temporary using unset apps and unset config together here to do unset apps' job - // until this issue been solved: https://github.com/canonical/edgex-snap-hooks/issues/43 - utils.SnapUnset(t, deviceMqttSnap, "apps.device-mqtt.config.service.port") - utils.SnapUnset(t, deviceMqttSnap, "config.service.port") - utils.SnapRestart(t, deviceMqttService) - - utils.WaitServiceOnline(t, 60, defaultServicePort) - }) + utils.SetAppConfig(t, deviceMqttSnap, deviceMqttService, appName, defaultServicePort) } func TestGlobalConfig(t *testing.T) { // start clean - utils.SnapStop(t, deviceMqttSnap) - - t.Run("set and unset apps.", func(t *testing.T) { - t.Cleanup(func() { - utils.SnapUnset(t, deviceMqttSnap, "config.service.port") - utils.SnapStop(t, deviceMqttSnap) - }) - - const newPort = "33333" - - // make sure the port is available before using it - utils.RequirePortAvailable(t, newPort) - - // set config. and validate the new port comes online - utils.SnapSet(t, deviceMqttSnap, "config.service.port", newPort) - utils.SnapStart(t, deviceMqttSnap) - - utils.WaitServiceOnline(t, 60, newPort) - - // unset config. and validate the default port comes online - utils.SnapUnset(t, deviceMqttSnap, "config.service.port") - utils.SnapRestart(t, deviceMqttService) - - utils.WaitServiceOnline(t, 60, defaultServicePort) - }) + utils.SetGlobalConfig(t, deviceMqttSnap, deviceMqttService, defaultServicePort) } func TestMixedConfig(t *testing.T) { - // start clean - utils.SnapStop(t, deviceMqttSnap) - - t.Run("use apps. and config. for different values", func(t *testing.T) { - t.Cleanup(func() { - utils.SnapUnset(t, deviceMqttSnap, "apps.device-mqtt.config.service.port") - utils.SnapUnset(t, deviceMqttSnap, "config.service.port") - utils.SnapStop(t, deviceMqttService) - }) - - const newAppPort = "44444" - const newConfigPort = "55555" - - // make sure the ports are available before using it - utils.RequirePortAvailable(t, newAppPort) - utils.RequirePortAvailable(t, newConfigPort) - - // set apps. and config. with different values, - // and validate that app-specific option has been picked up because it has higher precedence - utils.SnapSet(t, deviceMqttSnap, "apps.device-mqtt.config.service.port", newAppPort) - utils.SnapSet(t, deviceMqttSnap, "config.service.port", newConfigPort) - utils.SnapStart(t, deviceMqttSnap) - - utils.WaitServiceOnline(t, 60, newAppPort) - }) + utils.FullConfigTest = true + utils.SetMixedConfig(t, deviceMqttSnap, deviceMqttService, appName, defaultServicePort) } diff --git a/test/suites/device-mqtt/main_test.go b/test/suites/device-mqtt/main_test.go index 619d688..fc50aa3 100644 --- a/test/suites/device-mqtt/main_test.go +++ b/test/suites/device-mqtt/main_test.go @@ -8,8 +8,11 @@ import ( "time" ) -const deviceMqttSnap = "edgex-device-mqtt" -const deviceMqttService = "edgex-device-mqtt.device-mqtt" +const ( + deviceMqttSnap = "edgex-device-mqtt" + appName = "device-mqtt" + deviceMqttService = deviceMqttSnap + "." + appName +) var start = time.Now() diff --git a/test/suites/device-rest/config_test.go b/test/suites/device-rest/config_test.go index f8e9641..79e9da2 100644 --- a/test/suites/device-rest/config_test.go +++ b/test/suites/device-rest/config_test.go @@ -7,121 +7,18 @@ import ( // Deprecated func TestEnvConfig(t *testing.T) { - // start clean - utils.SnapStop(t, deviceRestSnap) - - t.Run("change service port", func(t *testing.T) { - t.Cleanup(func() { - utils.SnapUnset(t, deviceRestSnap, "env") - utils.SnapStop(t, deviceRestSnap) - }) - - const newPort = "11111" - - // make sure the port is available before using it - utils.RequirePortAvailable(t, newPort) - - // set env. and validate the new port comes online - utils.SnapSet(t, deviceRestSnap, "env.service.port", newPort) - utils.SnapStart(t, deviceRestSnap) - - utils.WaitServiceOnline(t, 60, newPort) - - // unset env. and validate the default port comes online - utils.SnapUnset(t, deviceRestSnap, "env.service.port") - utils.SnapRestart(t, deviceRestService) - utils.WaitServiceOnline(t, 60, defaultServicePort) - }) + utils.SetEnvConfig(t, deviceRestSnap, deviceRestService, defaultServicePort) } func TestAppConfig(t *testing.T) { - // start clean - utils.SnapStop(t, deviceRestSnap) - - t.Run("set and unset apps.", func(t *testing.T) { - t.Cleanup(func() { - // temporary using unset apps and unset config together here to do unset apps' job - // until this issue been solved: https://github.com/canonical/edgex-snap-hooks/issues/43 - utils.SnapUnset(t, deviceRestSnap, "apps.device-rest.config.service.port") - utils.SnapUnset(t, deviceRestSnap, "config.service.port") - utils.SnapStop(t, deviceRestSnap) - }) - - const newPort = "22222" - - // make sure the port is available before using it - utils.RequirePortAvailable(t, newPort) - - // set apps. and validate the new port comes online - utils.SnapSet(t, deviceRestSnap, "apps.device-rest.config.service.port", newPort) - utils.SnapStart(t, deviceRestSnap) - - utils.WaitServiceOnline(t, 60, newPort) - - // unset apps. and validate the default port comes online - // temporary using unset apps and unset config together here to do unset apps' job - // until this issue been solved: https://github.com/canonical/edgex-snap-hooks/issues/43 - utils.SnapUnset(t, deviceRestSnap, "apps.device-rest.config.service.port") - utils.SnapUnset(t, deviceRestSnap, "config.service.port") - utils.SnapRestart(t, deviceRestService) - - utils.WaitServiceOnline(t, 60, defaultServicePort) - }) + utils.SetAppConfig(t, deviceRestSnap, deviceRestService, appName, defaultServicePort) } func TestGlobalConfig(t *testing.T) { // start clean - utils.SnapStop(t, deviceRestSnap) - - t.Run("set and unset apps.", func(t *testing.T) { - t.Cleanup(func() { - utils.SnapUnset(t, deviceRestSnap, "config.service.port") - utils.SnapStop(t, deviceRestSnap) - }) - - const newPort = "33333" - - // make sure the port is available before using it - utils.RequirePortAvailable(t, newPort) - - // set config. and validate the new port comes online - utils.SnapSet(t, deviceRestSnap, "config.service.port", newPort) - utils.SnapStart(t, deviceRestSnap) - - utils.WaitServiceOnline(t, 60, newPort) - - // unset config. and validate the default port comes online - utils.SnapUnset(t, deviceRestSnap, "config.service.port") - utils.SnapRestart(t, deviceRestService) - - utils.WaitServiceOnline(t, 60, defaultServicePort) - }) + utils.SetGlobalConfig(t, deviceRestSnap, deviceRestService, defaultServicePort) } func TestMixedConfig(t *testing.T) { - // start clean - utils.SnapStop(t, deviceRestSnap) - - t.Run("use apps. and config. for different values", func(t *testing.T) { - t.Cleanup(func() { - utils.SnapUnset(t, deviceRestSnap, "apps.device-rest.config.service.port") - utils.SnapUnset(t, deviceRestSnap, "config.service.port") - utils.SnapStop(t, deviceRestService) - }) - - const newAppPort = "44444" - const newConfigPort = "55555" - - // make sure the ports are available before using it - utils.RequirePortAvailable(t, newAppPort) - utils.RequirePortAvailable(t, newConfigPort) - - // set apps. and config. with different values, - // and validate that app-specific option has been picked up because it has higher precedence - utils.SnapSet(t, deviceRestSnap, "apps.device-rest.config.service.port", newAppPort) - utils.SnapSet(t, deviceRestSnap, "config.service.port", newConfigPort) - utils.SnapStart(t, deviceRestSnap) - - utils.WaitServiceOnline(t, 60, newAppPort) - }) + utils.SetMixedConfig(t, deviceRestSnap, deviceRestService, appName, defaultServicePort) } diff --git a/test/suites/device-rest/main_test.go b/test/suites/device-rest/main_test.go index b670473..7e7e9bf 100644 --- a/test/suites/device-rest/main_test.go +++ b/test/suites/device-rest/main_test.go @@ -8,8 +8,11 @@ import ( "time" ) -const deviceRestSnap = "edgex-device-rest" -const deviceRestService = "edgex-device-rest.device-rest" +const ( + deviceRestSnap = "edgex-device-rest" + appName = "device-rest" + deviceRestService = deviceRestSnap + "." + appName +) var start = time.Now() diff --git a/test/utils/config.go b/test/utils/config.go new file mode 100644 index 0000000..b1eb69a --- /dev/null +++ b/test/utils/config.go @@ -0,0 +1,143 @@ +package utils + +import "testing" + +func SetEnvConfig(t *testing.T, snap, service, defaultServicePort string) { + if !FullConfigTest { + // make this subtest optional to save testing time, + t.Skip("Full config test is disabled by default, and similar full config tests have been operated in device-mqtt test suite.") + } else { + // start clean + SnapStop(t, snap) + + t.Run("change service port", func(t *testing.T) { + t.Cleanup(func() { + SnapUnset(t, snap, "env") + SnapStop(t, snap) + }) + + const newPort = "11111" + + // make sure the port is available before using it + RequirePortAvailable(t, newPort) + + // set env. and validate the new port comes online + SnapSet(t, snap, "env.service.port", newPort) + SnapStart(t, snap) + + WaitServiceOnline(t, 60, newPort) + + // unset env. and validate the default port comes online + SnapUnset(t, snap, "env.service.port") + SnapRestart(t, service) + WaitServiceOnline(t, 60, defaultServicePort) + }) + } +} + +func SetAppConfig(t *testing.T, snap, service, appName, defaultServicePort string) { + // start clean + SnapStop(t, snap) + + t.Run("set and unset apps.", func(t *testing.T) { + t.Cleanup(func() { + // temporary using unset apps and unset config together here to do unset apps' job + // until this issue been solved: https://github.com/canonical/edgex-snap-hooks/issues/43 + SnapUnset(t, snap, "apps."+appName+".config.service.port") + SnapUnset(t, snap, "config.service.port") + SnapStop(t, snap) + }) + + const newPort = "22222" + + // enable new apps option to aviod mixed options issue with old env option + SnapSet(t, snap, "config-enabled", "true") + + // make sure the port is available before using it + RequirePortAvailable(t, newPort) + + // set apps. and validate the new port comes online + SnapSet(t, snap, "apps."+appName+".config.service.port", newPort) + SnapStart(t, snap) + + WaitServiceOnline(t, 60, newPort) + + // unset apps. and validate the default port comes online + // temporary using unset apps and unset config together here to do unset apps' job + // until this issue been solved: https://github.com/canonical/edgex-snap-hooks/issues/43 + SnapUnset(t, snap, "apps."+appName+".config.service.port") + SnapUnset(t, snap, "config.service.port") + SnapRestart(t, service) + + WaitServiceOnline(t, 60, defaultServicePort) + }) +} + +func SetGlobalConfig(t *testing.T, snap, service, defaultServicePort string) { + // start clean + SnapStop(t, snap) + + t.Run("set and unset apps.", func(t *testing.T) { + t.Cleanup(func() { + SnapUnset(t, snap, "config.service.port") + SnapStop(t, snap) + }) + + const newPort = "33333" + + // enable new config option to aviod mixed options issue with old env option + SnapSet(t, snap, "config-enabled", "true") + + // make sure the port is available before using it + RequirePortAvailable(t, newPort) + + // set config. and validate the new port comes online + SnapSet(t, snap, "config.service.port", newPort) + SnapStart(t, snap) + + WaitServiceOnline(t, 60, newPort) + + // unset config. and validate the default port comes online + SnapUnset(t, snap, "config.service.port") + SnapRestart(t, service) + + WaitServiceOnline(t, 60, defaultServicePort) + }) +} + +func SetMixedConfig(t *testing.T, snap, service, appName, defaultServicePort string) { + if !FullConfigTest { + // make this subtest optional to save testing time, + // similar full config tests have been operated in device-mqtt test suite + t.Skip("Full config test is disabled by default, and similar full config tests have been operated in device-mqtt test suite.") + } else { + // start clean + SnapStop(t, snap) + + t.Run("use apps. and config. for different values", func(t *testing.T) { + t.Cleanup(func() { + SnapUnset(t, snap, "apps."+appName+".config.service.port") + SnapUnset(t, snap, "config.service.port") + SnapStop(t, service) + }) + + const newAppPort = "44444" + const newConfigPort = "55555" + + // enable new apps/config options to aviod mixed options issue with old env option + SnapSet(t, snap, "config-enabled", "true") + + // make sure the ports are available before using it + RequirePortAvailable(t, newAppPort) + RequirePortAvailable(t, newConfigPort) + + // set apps. and config. with different values, + // and validate that app-specific option has been picked up because it has higher precedence + SnapSet(t, snap, "apps."+appName+".config.service.port", newAppPort) + SnapSet(t, snap, "config.service.port", newConfigPort) + SnapStart(t, snap) + + WaitServiceOnline(t, 60, newAppPort) + }) + } +} diff --git a/test/utils/env.go b/test/utils/env.go index 7dfd87f..c65fb9d 100644 --- a/test/utils/env.go +++ b/test/utils/env.go @@ -1,6 +1,9 @@ package utils -import "os" +import ( + "os" + "strconv" +) const ( // environment variables @@ -8,6 +11,7 @@ const ( platformChannel = "PLATFORM_CHANNEL" serviceChannel = "SERVICE_CHANNEL" localSnap = "LOCAL_SNAP" + fullConfigTest = "FULL_CONFIG_TEST" ) var ( @@ -15,6 +19,7 @@ var ( PlatformChannel = "latest/edge" ServiceChannel = "latest/edge" LocalSnap = "" + FullConfigTest = false ) func init() { @@ -29,4 +34,8 @@ func init() { if v := os.Getenv(localSnap); v != "" { LocalSnap = v } + + if v := os.Getenv(fullConfigTest); v != "" { + FullConfigTest, _ = strconv.ParseBool(v) + } } From 99de32c5ed66bca21f67d73596f6006b38347352 Mon Sep 17 00:00:00 2001 From: Mengyi Date: Fri, 22 Apr 2022 19:00:44 +0200 Subject: [PATCH 03/24] Remove extra `unset config`, add cleanup for `config-enabled` (#51) --- test/utils/config.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/test/utils/config.go b/test/utils/config.go index b1eb69a..85589c3 100644 --- a/test/utils/config.go +++ b/test/utils/config.go @@ -41,10 +41,8 @@ func SetAppConfig(t *testing.T, snap, service, appName, defaultServicePort strin t.Run("set and unset apps.", func(t *testing.T) { t.Cleanup(func() { - // temporary using unset apps and unset config together here to do unset apps' job - // until this issue been solved: https://github.com/canonical/edgex-snap-hooks/issues/43 - SnapUnset(t, snap, "apps."+appName+".config.service.port") - SnapUnset(t, snap, "config.service.port") + SnapUnset(t, snap, "apps") + SnapUnset(t, snap, "config-enabled") SnapStop(t, snap) }) @@ -63,10 +61,7 @@ func SetAppConfig(t *testing.T, snap, service, appName, defaultServicePort strin WaitServiceOnline(t, 60, newPort) // unset apps. and validate the default port comes online - // temporary using unset apps and unset config together here to do unset apps' job - // until this issue been solved: https://github.com/canonical/edgex-snap-hooks/issues/43 SnapUnset(t, snap, "apps."+appName+".config.service.port") - SnapUnset(t, snap, "config.service.port") SnapRestart(t, service) WaitServiceOnline(t, 60, defaultServicePort) @@ -79,7 +74,8 @@ func SetGlobalConfig(t *testing.T, snap, service, defaultServicePort string) { t.Run("set and unset apps.", func(t *testing.T) { t.Cleanup(func() { - SnapUnset(t, snap, "config.service.port") + SnapUnset(t, snap, "config") + SnapUnset(t, snap, "config-enabled") SnapStop(t, snap) }) @@ -116,8 +112,9 @@ func SetMixedConfig(t *testing.T, snap, service, appName, defaultServicePort str t.Run("use apps. and config. for different values", func(t *testing.T) { t.Cleanup(func() { - SnapUnset(t, snap, "apps."+appName+".config.service.port") - SnapUnset(t, snap, "config.service.port") + SnapUnset(t, snap, "apps") + SnapUnset(t, snap, "config") + SnapUnset(t, snap, "config-enabled") SnapStop(t, service) }) From b4451bc1ad112409c6052cee925cd077544298a1 Mon Sep 17 00:00:00 2001 From: Mengyi Date: Mon, 25 Apr 2022 10:12:45 +0200 Subject: [PATCH 04/24] Update device-gpio's config_test (#50) --- test/suites/device-gpio/config_test.go | 28 +++++++++----------------- test/suites/device-gpio/main_test.go | 7 +++++-- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/test/suites/device-gpio/config_test.go b/test/suites/device-gpio/config_test.go index 39f82bd..abcb6ad 100644 --- a/test/suites/device-gpio/config_test.go +++ b/test/suites/device-gpio/config_test.go @@ -7,26 +7,18 @@ import ( // Deprecated func TestEnvConfig(t *testing.T) { - // start clean - utils.SnapStop(t, deviceGpioService) - - t.Run("change service port", func(t *testing.T) { - t.Cleanup(func() { - utils.SnapStop(t, deviceGpioService) - utils.SnapUnset(t, deviceGpioSnap, "env.service.port") - }) - - const newPort = "56789" + utils.SetEnvConfig(t, deviceGpioSnap, deviceGpioService, defaultServicePort) +} - // make sure the port is available before using it - utils.RequirePortAvailable(t, newPort) +func TestAppConfig(t *testing.T) { + utils.SetAppConfig(t, deviceGpioSnap, deviceGpioService, appName, defaultServicePort) +} - utils.SnapSet(t, deviceGpioSnap, "env.service.port", newPort) - utils.SnapStart(t, deviceGpioSnap) - utils.WaitServiceOnline(t, 60, newPort) - }) +func TestGlobalConfig(t *testing.T) { + // start clean + utils.SetGlobalConfig(t, deviceGpioSnap, deviceGpioService, defaultServicePort) } -func TestAppConfig(t *testing.T) { - t.Skip("TODO") +func TestMixedConfig(t *testing.T) { + utils.SetMixedConfig(t, deviceGpioSnap, deviceGpioService, appName, defaultServicePort) } diff --git a/test/suites/device-gpio/main_test.go b/test/suites/device-gpio/main_test.go index 6577dce..b400f7f 100644 --- a/test/suites/device-gpio/main_test.go +++ b/test/suites/device-gpio/main_test.go @@ -8,8 +8,11 @@ import ( "time" ) -const deviceGpioSnap = "edgex-device-gpio" -const deviceGpioService = "edgex-device-gpio.device-gpio" +const ( + deviceGpioSnap = "edgex-device-gpio" + appName = "device-gpio" + deviceGpioService = deviceGpioSnap + "." + appName +) var start = time.Now() From 3ac67ea566c3ed1e022395094d83430ac85f0b8e Mon Sep 17 00:00:00 2001 From: Farshid Tavakolizadeh Date: Mon, 25 Apr 2022 11:27:23 +0200 Subject: [PATCH 05/24] Change value of FULL_CONFIG_TEST to boolean --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6442e74..a86996a 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ go test -p 1 ./test/suites/... Test one with variables, e.g.: ```bash -FULL_CONFIG_TEST=on go test -p 1 ./test/suites/device-mqtt +FULL_CONFIG_TEST=true go test -p 1 ./test/suites/device-mqtt ``` ```bash LOCAL_SNAP="edgex-device-mqtt_2.0.1-dev.15_amd64.snap" go test -p 1 ./test/suites/device-mqtt @@ -94,4 +94,4 @@ graph LR testj[Test Job] --> testa end end -``` \ No newline at end of file +``` From 82601a91bad2d01fa3abfec8c8635519e6201ec1 Mon Sep 17 00:00:00 2001 From: Mengyi Date: Mon, 25 Apr 2022 11:55:33 +0200 Subject: [PATCH 06/24] Update app-service-configurable's config test (#52) --- .../app-service-configurable/config_test.go | 30 +++++++------------ .../app-service-configurable/main_test.go | 16 ++++++++-- .../app-service-configurable/network_test.go | 10 +++---- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/test/suites/app-service-configurable/config_test.go b/test/suites/app-service-configurable/config_test.go index edf4b90..81321a9 100644 --- a/test/suites/app-service-configurable/config_test.go +++ b/test/suites/app-service-configurable/config_test.go @@ -10,33 +10,23 @@ import ( ) const profile = "http-export" -const appRulesEngineServicePort = "59720" // Deprecated func TestEnvConfig(t *testing.T) { - // start clean - utils.SnapStop(t, ascService) - - t.Run("change service port", func(t *testing.T) { - t.Cleanup(func() { - utils.SnapStop(t, ascService) - utils.SnapUnset(t, ascSnap, "env.service.port") - utils.SnapSet(t, ascSnap, "env.service.port", appRulesEngineServicePort) - }) - - const newPort = "56789" + utils.SetEnvConfig(t, ascSnap, ascService, appSrviceRulesServicePort) +} - // make sure the port is available before using it - utils.RequirePortAvailable(t, newPort) +func TestAppConfig(t *testing.T) { + utils.SetAppConfig(t, ascSnap, ascService, appName, appSrviceRulesServicePort) +} - utils.SnapSet(t, ascSnap, "env.service.port", newPort) - utils.SnapStart(t, ascSnap) - utils.WaitServiceOnline(t, 60, newPort) - }) +func TestGlobalConfig(t *testing.T) { + // start clean + utils.SetGlobalConfig(t, ascSnap, ascService, appSrviceRulesServicePort) } -func TestAppConfig(t *testing.T) { - t.Skip("TODO") +func TestMixedConfig(t *testing.T) { + utils.SetMixedConfig(t, ascSnap, ascService, appName, appSrviceRulesServicePort) } func TestProfileConfig(t *testing.T) { diff --git a/test/suites/app-service-configurable/main_test.go b/test/suites/app-service-configurable/main_test.go index 33f8247..e354a71 100644 --- a/test/suites/app-service-configurable/main_test.go +++ b/test/suites/app-service-configurable/main_test.go @@ -8,9 +8,13 @@ import ( "time" ) -const ascSnap = "edgex-app-service-configurable" -const ascService = "edgex-app-service-configurable.app-service-configurable" -const defaultProfile = "rules-engine" +const ( + ascSnap = "edgex-app-service-configurable" + appName = "app-service-configurable" + ascService = ascSnap + "." + appName + defaultProfile = "rules-engine" + appSrviceRulesServicePort = "59701" +) var start = time.Now() @@ -46,6 +50,12 @@ func TestMain(m *testing.M) { // set profile to rules engine utils.SnapSet(nil, ascSnap, "profile", defaultProfile) + // Start the service so that the default config gets uploaded to consul. + // Otherwise, settings that get passed using environment variables on first start get uploaded + // and become the default. + utils.SnapStart(nil, ascService) + utils.WaitServiceOnline(nil, 60, appSrviceRulesServicePort) + exitCode := m.Run() log.Println("[TEARDOWN]") diff --git a/test/suites/app-service-configurable/network_test.go b/test/suites/app-service-configurable/network_test.go index f476d77..10a3b83 100644 --- a/test/suites/app-service-configurable/network_test.go +++ b/test/suites/app-service-configurable/network_test.go @@ -12,16 +12,16 @@ func TestNetworkInterface(t *testing.T) { utils.SnapStart(t, ascService) - t.Run("listen default port "+appRulesEngineServicePort, func(t *testing.T) { - utils.WaitServiceOnline(t, 60, appRulesEngineServicePort) + t.Run("listen default port "+appSrviceRulesServicePort, func(t *testing.T) { + utils.WaitServiceOnline(t, 60, appSrviceRulesServicePort) }) t.Run("not listen on all interfaces", func(t *testing.T) { - utils.RequireListenAllInterfaces(t, false, appRulesEngineServicePort) + utils.RequireListenAllInterfaces(t, false, appSrviceRulesServicePort) }) t.Run("listen localhost", func(t *testing.T) { - utils.RequireListenLoopback(t, appRulesEngineServicePort) - utils.RequirePortOpen(t, appRulesEngineServicePort) + utils.RequireListenLoopback(t, appSrviceRulesServicePort) + utils.RequirePortOpen(t, appSrviceRulesServicePort) }) } From b77c7f417b9edb815f49c21557aa026fd33cd27e Mon Sep 17 00:00:00 2001 From: Farshid Tavakolizadeh Date: Mon, 25 Apr 2022 13:03:38 +0200 Subject: [PATCH 07/24] Add dev channels for rest, mqtt, asc, gpio --- .github/workflows/snap-testing.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/snap-testing.yml b/.github/workflows/snap-testing.yml index f9a8343..d525fe4 100644 --- a/.github/workflows/snap-testing.yml +++ b/.github/workflows/snap-testing.yml @@ -16,14 +16,18 @@ jobs: matrix: include: - name: device-mqtt + channel: edge/pr-365 - name: ekuiper - name: app-service-configurable + channel: edge/pr-407 - name: device-gpio + channel: edge/pr-25 - name: device-rest + channel: edge/pr-177 - name: device-snmp From d8ba008d7af1768e4e2b75edb4d9f0f993be39fb Mon Sep 17 00:00:00 2001 From: Farshid Tavakolizadeh Date: Mon, 25 Apr 2022 13:19:16 +0200 Subject: [PATCH 08/24] Replace config keys to use hyphen as separator --- test/utils/config.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/utils/config.go b/test/utils/config.go index 85589c3..40b82ed 100644 --- a/test/utils/config.go +++ b/test/utils/config.go @@ -55,13 +55,13 @@ func SetAppConfig(t *testing.T, snap, service, appName, defaultServicePort strin RequirePortAvailable(t, newPort) // set apps. and validate the new port comes online - SnapSet(t, snap, "apps."+appName+".config.service.port", newPort) + SnapSet(t, snap, "apps."+appName+".config.service-port", newPort) SnapStart(t, snap) WaitServiceOnline(t, 60, newPort) // unset apps. and validate the default port comes online - SnapUnset(t, snap, "apps."+appName+".config.service.port") + SnapUnset(t, snap, "apps."+appName+".config.service-port") SnapRestart(t, service) WaitServiceOnline(t, 60, defaultServicePort) @@ -88,13 +88,13 @@ func SetGlobalConfig(t *testing.T, snap, service, defaultServicePort string) { RequirePortAvailable(t, newPort) // set config. and validate the new port comes online - SnapSet(t, snap, "config.service.port", newPort) + SnapSet(t, snap, "config.service-port", newPort) SnapStart(t, snap) WaitServiceOnline(t, 60, newPort) // unset config. and validate the default port comes online - SnapUnset(t, snap, "config.service.port") + SnapUnset(t, snap, "config.service-port") SnapRestart(t, service) WaitServiceOnline(t, 60, defaultServicePort) @@ -130,8 +130,8 @@ func SetMixedConfig(t *testing.T, snap, service, appName, defaultServicePort str // set apps. and config. with different values, // and validate that app-specific option has been picked up because it has higher precedence - SnapSet(t, snap, "apps."+appName+".config.service.port", newAppPort) - SnapSet(t, snap, "config.service.port", newConfigPort) + SnapSet(t, snap, "apps."+appName+".config.service-port", newAppPort) + SnapSet(t, snap, "config.service-port", newConfigPort) SnapStart(t, snap) WaitServiceOnline(t, 60, newAppPort) From 5d1ce60477bdea4b1a3f2abdaa9f6105f0d1dd61 Mon Sep 17 00:00:00 2001 From: Farshid Tavakolizadeh Date: Mon, 25 Apr 2022 16:56:56 +0200 Subject: [PATCH 09/24] Add config tests for app-rfid-llrp-inventory (#54) --- .github/workflows/snap-testing.yml | 1 + .../app-rfid-llrp-inventory/config_test.go | 27 +++++++------------ .../app-rfid-llrp-inventory/main_test.go | 7 +++-- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/.github/workflows/snap-testing.yml b/.github/workflows/snap-testing.yml index d525fe4..e2deadd 100644 --- a/.github/workflows/snap-testing.yml +++ b/.github/workflows/snap-testing.yml @@ -43,6 +43,7 @@ jobs: - name: device-rfid-llrp - name: app-rfid-llrp-inventory + channel: edge/pr-74 # use local action to test diff --git a/test/suites/app-rfid-llrp-inventory/config_test.go b/test/suites/app-rfid-llrp-inventory/config_test.go index 22cea81..121f92a 100644 --- a/test/suites/app-rfid-llrp-inventory/config_test.go +++ b/test/suites/app-rfid-llrp-inventory/config_test.go @@ -7,25 +7,18 @@ import ( // Deprecated func TestEnvConfig(t *testing.T) { + utils.SetEnvConfig(t, appRfidLlrpSnap, appRfidLlrpService, defaultServicePort) +} - t.Run("change service port", func(t *testing.T) { - t.Cleanup(func() { - utils.SnapStop(t, appRfidLlrpService) - utils.SnapUnset(t, appRfidLlrpSnap, "env.service.port") - }) - - const newPort = "56789" - - // make sure the port is available before using it - utils.RequirePortAvailable(t, newPort) +func TestAppConfig(t *testing.T) { + utils.SetAppConfig(t, appRfidLlrpSnap, appRfidLlrpService, appName, defaultServicePort) +} - utils.SnapStop(t, appRfidLlrpSnap) - utils.SnapSet(t, appRfidLlrpSnap, "env.service.port", newPort) - utils.SnapStart(t, appRfidLlrpSnap) - utils.WaitServiceOnline(t, 60, newPort) - }) +func TestGlobalConfig(t *testing.T) { + // start clean + utils.SetGlobalConfig(t, appRfidLlrpSnap, appRfidLlrpService, defaultServicePort) } -func TestAppConfig(t *testing.T) { - t.Skip("TODO") +func TestMixedConfig(t *testing.T) { + utils.SetMixedConfig(t, appRfidLlrpSnap, appRfidLlrpService, appName, defaultServicePort) } diff --git a/test/suites/app-rfid-llrp-inventory/main_test.go b/test/suites/app-rfid-llrp-inventory/main_test.go index 021bc03..841049e 100644 --- a/test/suites/app-rfid-llrp-inventory/main_test.go +++ b/test/suites/app-rfid-llrp-inventory/main_test.go @@ -8,8 +8,11 @@ import ( "time" ) -const appRfidLlrpSnap = "edgex-app-rfid-llrp-inventory" -const appRfidLlrpService = "edgex-app-rfid-llrp-inventory.app-rfid-llrp-inventory" +const ( + appRfidLlrpSnap = "edgex-app-rfid-llrp-inventory" + appName = "app-rfid-llrp-inventory" + appRfidLlrpService = appRfidLlrpSnap + "." + appName +) var start = time.Now() From a481b766ab67b64a54c1c2542f9d1e520afbfd17 Mon Sep 17 00:00:00 2001 From: Farshid Tavakolizadeh Date: Mon, 25 Apr 2022 17:30:21 +0200 Subject: [PATCH 10/24] Add config testing for device-modbus (#55) * Add config testing for device-modbus * Add snap channel for ci testing --- .github/workflows/snap-testing.yml | 1 + test/suites/device-modbus/config_test.go | 15 +++++++++++---- test/suites/device-modbus/main_test.go | 7 +++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/.github/workflows/snap-testing.yml b/.github/workflows/snap-testing.yml index e2deadd..938651e 100644 --- a/.github/workflows/snap-testing.yml +++ b/.github/workflows/snap-testing.yml @@ -32,6 +32,7 @@ jobs: - name: device-snmp - name: device-modbus + channel: edge/pr-336 - name: edgexfoundry diff --git a/test/suites/device-modbus/config_test.go b/test/suites/device-modbus/config_test.go index 535ab9c..589f418 100644 --- a/test/suites/device-modbus/config_test.go +++ b/test/suites/device-modbus/config_test.go @@ -7,11 +7,18 @@ import ( // Deprecated func TestEnvConfig(t *testing.T) { - t.Run("change service port", func(t *testing.T) { - utils.TestEnvChangeServicePort(t, deviceModbusSnap, defaultServicePort) - }) + utils.SetEnvConfig(t, deviceModbusSnap, deviceModbusService, defaultServicePort) } func TestAppConfig(t *testing.T) { - t.Skip("TODO") + utils.SetAppConfig(t, deviceModbusSnap, deviceModbusService, deviceModbusApp, defaultServicePort) +} + +func TestGlobalConfig(t *testing.T) { + // start clean + utils.SetGlobalConfig(t, deviceModbusSnap, deviceModbusService, defaultServicePort) +} + +func TestMixedConfig(t *testing.T) { + utils.SetMixedConfig(t, deviceModbusSnap, deviceModbusService, deviceModbusApp, defaultServicePort) } diff --git a/test/suites/device-modbus/main_test.go b/test/suites/device-modbus/main_test.go index 7161d14..1051a24 100644 --- a/test/suites/device-modbus/main_test.go +++ b/test/suites/device-modbus/main_test.go @@ -8,8 +8,11 @@ import ( "time" ) -const deviceModbusSnap = "edgex-device-modbus" -const deviceModbusService = "edgex-device-modbus.device-modbus" +const ( + deviceModbusSnap = "edgex-device-modbus" + deviceModbusApp = "device-modbus" + deviceModbusService = "edgex-device-modbus." + deviceModbusApp +) var start = time.Now() From 018ca2b8b5c9ca5ea6a605eb8880c441c09c7cb9 Mon Sep 17 00:00:00 2001 From: Farshid Tavakolizadeh Date: Mon, 25 Apr 2022 21:18:23 +0200 Subject: [PATCH 11/24] Add config tests for device-rfid-llrp (#57) --- test/suites/device-rfid-llrp/config_test.go | 27 ++++++++------------- test/suites/device-rfid-llrp/main_test.go | 7 ++++-- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/test/suites/device-rfid-llrp/config_test.go b/test/suites/device-rfid-llrp/config_test.go index e74c82c..248743c 100644 --- a/test/suites/device-rfid-llrp/config_test.go +++ b/test/suites/device-rfid-llrp/config_test.go @@ -7,25 +7,18 @@ import ( // Deprecated func TestEnvConfig(t *testing.T) { + utils.SetEnvConfig(t, deviceRfidLlrpSnap, deviceRfidLlrpService, defaultServicePort) +} - t.Run("change service port", func(t *testing.T) { - t.Cleanup(func() { - utils.SnapStop(t, deviceRfidLlrpService) - utils.SnapUnset(t, deviceRfidLlrpSnap, "env.service.port") - }) - - const newPort = "56789" - - // make sure the port is available before using it - utils.RequirePortAvailable(t, newPort) +func TestAppConfig(t *testing.T) { + utils.SetAppConfig(t, deviceRfidLlrpSnap, deviceRfidLlrpService, deviceRfidApp, defaultServicePort) +} - utils.SnapStop(t, deviceRfidLlrpSnap) - utils.SnapSet(t, deviceRfidLlrpSnap, "env.service.port", newPort) - utils.SnapStart(t, deviceRfidLlrpSnap) - utils.WaitServiceOnline(t, 60, newPort) - }) +func TestGlobalConfig(t *testing.T) { + // start clean + utils.SetGlobalConfig(t, deviceRfidLlrpSnap, deviceRfidLlrpService, defaultServicePort) } -func TestAppConfig(t *testing.T) { - t.Skip("TODO") +func TestMixedConfig(t *testing.T) { + utils.SetMixedConfig(t, deviceRfidLlrpSnap, deviceRfidLlrpService, deviceRfidApp, defaultServicePort) } diff --git a/test/suites/device-rfid-llrp/main_test.go b/test/suites/device-rfid-llrp/main_test.go index 1f86306..f2f3c23 100644 --- a/test/suites/device-rfid-llrp/main_test.go +++ b/test/suites/device-rfid-llrp/main_test.go @@ -8,8 +8,11 @@ import ( "time" ) -const deviceRfidLlrpSnap = "edgex-device-rfid-llrp" -const deviceRfidLlrpService = "edgex-device-rfid-llrp.device-rfid-llrp" +const ( + deviceRfidLlrpSnap = "edgex-device-rfid-llrp" + deviceRfidApp = "device-rfid-llrp" + deviceRfidLlrpService = "edgex-device-rfid-llrp." + deviceRfidApp +) var start = time.Now() From 6edd8bb00fe4063cfdbabc2eef5e79a96ce1ca82 Mon Sep 17 00:00:00 2001 From: Farshid Tavakolizadeh Date: Mon, 25 Apr 2022 21:25:40 +0200 Subject: [PATCH 12/24] Add dev channel for device-rfid-llrp --- .github/workflows/snap-testing.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/snap-testing.yml b/.github/workflows/snap-testing.yml index 938651e..3ff55a2 100644 --- a/.github/workflows/snap-testing.yml +++ b/.github/workflows/snap-testing.yml @@ -42,6 +42,7 @@ jobs: - name: ui - name: device-rfid-llrp + channel: edge/pr-75 - name: app-rfid-llrp-inventory channel: edge/pr-74 From 3d4e6d12d8311eafbb119e45699e4137d49de8bc Mon Sep 17 00:00:00 2001 From: Farshid Tavakolizadeh Date: Tue, 26 Apr 2022 10:38:37 +0200 Subject: [PATCH 13/24] Add config testing for device-snmp (#58) * Add config testing for device-snmp * Add dev channel to ci workflow --- .github/workflows/snap-testing.yml | 1 + test/suites/device-snmp/config_test.go | 15 +++++++++++---- test/suites/device-snmp/main_test.go | 7 +++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/.github/workflows/snap-testing.yml b/.github/workflows/snap-testing.yml index 3ff55a2..19f275e 100644 --- a/.github/workflows/snap-testing.yml +++ b/.github/workflows/snap-testing.yml @@ -30,6 +30,7 @@ jobs: channel: edge/pr-177 - name: device-snmp + channel: edge/pr-160 - name: device-modbus channel: edge/pr-336 diff --git a/test/suites/device-snmp/config_test.go b/test/suites/device-snmp/config_test.go index 3e68367..473d6ec 100644 --- a/test/suites/device-snmp/config_test.go +++ b/test/suites/device-snmp/config_test.go @@ -7,11 +7,18 @@ import ( // Deprecated func TestEnvConfig(t *testing.T) { - t.Run("change service port", func(t *testing.T) { - utils.TestEnvChangeServicePort(t, deviceSnmpSnap, defaultServicePort) - }) + utils.SetEnvConfig(t, deviceSnmpSnap, deviceSnmpService, defaultServicePort) } func TestAppConfig(t *testing.T) { - t.Skip("TODO") + utils.SetAppConfig(t, deviceSnmpSnap, deviceSnmpService, deviceSnmpApp, defaultServicePort) +} + +func TestGlobalConfig(t *testing.T) { + // start clean + utils.SetGlobalConfig(t, deviceSnmpSnap, deviceSnmpService, defaultServicePort) +} + +func TestMixedConfig(t *testing.T) { + utils.SetMixedConfig(t, deviceSnmpSnap, deviceSnmpService, deviceSnmpApp, defaultServicePort) } diff --git a/test/suites/device-snmp/main_test.go b/test/suites/device-snmp/main_test.go index 13022ca..c0a2e6f 100644 --- a/test/suites/device-snmp/main_test.go +++ b/test/suites/device-snmp/main_test.go @@ -8,8 +8,11 @@ import ( "time" ) -const deviceSnmpSnap = "edgex-device-snmp" -const deviceSnmpService = "edgex-device-snmp.device-snmp" +const ( + deviceSnmpSnap = "edgex-device-snmp" + deviceSnmpApp = "device-snmp" + deviceSnmpService = deviceSnmpSnap + "." + deviceSnmpApp +) var start = time.Now() From 84f9a67203e7f9636098cb4b2316f206eff4e1c7 Mon Sep 17 00:00:00 2001 From: Mengyi Date: Tue, 26 Apr 2022 17:42:19 +0200 Subject: [PATCH 14/24] Update edgex-go's config test (#56) * Update edgex-go's config test * Restart device-virtual * Trigger GitHub action with branch config * start/stop service instead of snap * start/stop platformSnap outside of utils * pass Github action channel to PLATFORM_CHANNEL * start platformSnap * change github action branch back to main * only start/stop affected service, rename `snapAppName` to `deviceVirtualService` * use branch config for github action testing * Revert trigger to main --- .github/workflows/snap-testing.yml | 2 + test/action.yml | 6 +++ test/suites/edgexfoundry/config_test.go | 49 ++++++++++++++++++------ test/suites/edgexfoundry/main_test.go | 10 +++-- test/suites/edgexfoundry/network_test.go | 4 +- test/utils/config.go | 22 +++++------ 6 files changed, 64 insertions(+), 29 deletions(-) diff --git a/.github/workflows/snap-testing.yml b/.github/workflows/snap-testing.yml index 19f275e..ba8b55a 100644 --- a/.github/workflows/snap-testing.yml +++ b/.github/workflows/snap-testing.yml @@ -36,6 +36,7 @@ jobs: channel: edge/pr-336 - name: edgexfoundry + platform_channel: edge/pr-3986 - name: cli print_logs: false @@ -62,4 +63,5 @@ jobs: with: name: ${{matrix.name}} channel: ${{matrix.channel}} + platform_channel: ${{matrix.platform_channel}} print_logs: ${{matrix.print_logs}} diff --git a/test/action.yml b/test/action.yml index ad614e0..7ea7c32 100644 --- a/test/action.yml +++ b/test/action.yml @@ -18,6 +18,11 @@ inputs: Channel for downloading the snap from store. This is useful only when 'snap' input is not set. required: false + platform_channel: + description: | + Channel for downloading the edgexfoundry snap from store. + This is useful only when 'snap' input is not set. + required: false print_logs: description: | Print snap logs. @@ -48,6 +53,7 @@ runs: working-directory: ${{github.action_path}} env: LOCAL_SNAP: ${{steps.path.outputs.local_snap}} + PLATFORM_CHANNEL: ${{inputs.platform_channel}} SERVICE_CHANNEL: ${{inputs.channel}} run: | go test -p 1 -timeout 30m -v ./suites/${{inputs.name}} diff --git a/test/suites/edgexfoundry/config_test.go b/test/suites/edgexfoundry/config_test.go index 84e23cf..b83a5a1 100644 --- a/test/suites/edgexfoundry/config_test.go +++ b/test/suites/edgexfoundry/config_test.go @@ -7,34 +7,59 @@ import ( // Deprecated func TestEnvConfig(t *testing.T) { + const newPort = "11111" + const envServicePort = "env." + deviceVirtualApp + ".service.port" + + // start clean + utils.SnapStop(t, deviceVirtualService) t.Cleanup(func() { - utils.SnapStop(t, snapAppName) + utils.SnapUnset(t, platformSnap, envServicePort) + utils.SnapStop(t, deviceVirtualService) }) t.Run("change device-virtual service port", func(t *testing.T) { - const newPort = "56789" - const envServicePort = "env.device-virtual.service.port" // make sure the port is available before using it utils.RequirePortAvailable(t, newPort) - // check if service port can be changed - utils.SnapStop(t, snapAppName) + // set env. and validate the new port comes online utils.SnapSet(t, platformSnap, envServicePort, newPort) - utils.SnapStart(t, snapAppName) + utils.SnapStart(t, deviceVirtualService) utils.WaitServiceOnline(t, 60, newPort) - // check if service port can be unset and revert to the default - utils.SnapStop(t, snapAppName) + // unset env. and validate the default port comes online utils.SnapUnset(t, platformSnap, envServicePort) - utils.SnapStart(t, snapAppName) + utils.SnapRestart(t, deviceVirtualService) utils.WaitServiceOnline(t, 60, deviceVirtualDefaultServicePort) - utils.SnapStop(t, snapAppName) - utils.SnapUnset(t, platformSnap, envServicePort) }) } func TestAppConfig(t *testing.T) { - t.Skip("TODO") + t.Cleanup(func() { + utils.SnapStop(t, deviceVirtualService) + }) + + utils.SnapStart(t, deviceVirtualService) + utils.SetAppConfig(t, platformSnap, deviceVirtualService, deviceVirtualApp, deviceVirtualDefaultServicePort) +} + +func TestGlobalConfig(t *testing.T) { + t.Cleanup(func() { + utils.SnapStop(t, deviceVirtualService) + }) + + utils.SnapStart(t, deviceVirtualService) + utils.SetGlobalConfig(t, platformSnap, deviceVirtualService, deviceVirtualDefaultServicePort) +} + +func TestMixedConfig(t *testing.T) { + utils.FullConfigTest = true + + t.Cleanup(func() { + utils.SnapStop(t, deviceVirtualService) + }) + + utils.SnapStart(t, deviceVirtualService) + utils.SetMixedConfig(t, platformSnap, deviceVirtualService, deviceVirtualApp, deviceVirtualDefaultServicePort) } diff --git a/test/suites/edgexfoundry/main_test.go b/test/suites/edgexfoundry/main_test.go index d08e8de..50a4861 100644 --- a/test/suites/edgexfoundry/main_test.go +++ b/test/suites/edgexfoundry/main_test.go @@ -9,9 +9,9 @@ import ( ) const ( - platformSnap = "edgexfoundry" - deviceVirtualApp = "device-virtual" - snapAppName = platformSnap + "." + deviceVirtualApp + platformSnap = "edgexfoundry" + deviceVirtualApp = "device-virtual" + deviceVirtualService = platformSnap + "." + deviceVirtualApp deviceVirtualDefaultServicePort = "59900" ) @@ -33,7 +33,7 @@ func TestMain(m *testing.M) { utils.WaitPlatformOnline(nil) // make sure device-virtual service starts and comes online before starting the tests - utils.SnapSet(nil, platformSnap, deviceVirtualApp, "on") + utils.SnapStart(nil, deviceVirtualService) utils.WaitServiceOnline(nil, 60, deviceVirtualDefaultServicePort) exitCode := m.Run() @@ -46,5 +46,7 @@ func TestMain(m *testing.M) { platformSnap, ) + utils.FullConfigTest = false + os.Exit(exitCode) } diff --git a/test/suites/edgexfoundry/network_test.go b/test/suites/edgexfoundry/network_test.go index 51ccc6f..a6ef360 100644 --- a/test/suites/edgexfoundry/network_test.go +++ b/test/suites/edgexfoundry/network_test.go @@ -7,11 +7,11 @@ import ( func TestNetworkInterface(t *testing.T) { t.Cleanup(func() { - utils.SnapStop(t, snapAppName) + utils.SnapStop(t, deviceVirtualService) }) // check network interface status for device-virtual service - utils.SnapStart(t, snapAppName) + utils.SnapStart(t, deviceVirtualService) t.Run("listen default port "+deviceVirtualDefaultServicePort, func(t *testing.T) { utils.WaitServiceOnline(t, 60, deviceVirtualDefaultServicePort) diff --git a/test/utils/config.go b/test/utils/config.go index 40b82ed..3e13afa 100644 --- a/test/utils/config.go +++ b/test/utils/config.go @@ -8,12 +8,12 @@ func SetEnvConfig(t *testing.T, snap, service, defaultServicePort string) { t.Skip("Full config test is disabled by default, and similar full config tests have been operated in device-mqtt test suite.") } else { // start clean - SnapStop(t, snap) + SnapStop(t, service) t.Run("change service port", func(t *testing.T) { t.Cleanup(func() { SnapUnset(t, snap, "env") - SnapStop(t, snap) + SnapStop(t, service) }) const newPort = "11111" @@ -23,7 +23,7 @@ func SetEnvConfig(t *testing.T, snap, service, defaultServicePort string) { // set env. and validate the new port comes online SnapSet(t, snap, "env.service.port", newPort) - SnapStart(t, snap) + SnapStart(t, service) WaitServiceOnline(t, 60, newPort) @@ -37,13 +37,13 @@ func SetEnvConfig(t *testing.T, snap, service, defaultServicePort string) { func SetAppConfig(t *testing.T, snap, service, appName, defaultServicePort string) { // start clean - SnapStop(t, snap) + SnapStop(t, service) t.Run("set and unset apps.", func(t *testing.T) { t.Cleanup(func() { SnapUnset(t, snap, "apps") SnapUnset(t, snap, "config-enabled") - SnapStop(t, snap) + SnapStop(t, service) }) const newPort = "22222" @@ -56,7 +56,7 @@ func SetAppConfig(t *testing.T, snap, service, appName, defaultServicePort strin // set apps. and validate the new port comes online SnapSet(t, snap, "apps."+appName+".config.service-port", newPort) - SnapStart(t, snap) + SnapStart(t, service) WaitServiceOnline(t, 60, newPort) @@ -70,13 +70,13 @@ func SetAppConfig(t *testing.T, snap, service, appName, defaultServicePort strin func SetGlobalConfig(t *testing.T, snap, service, defaultServicePort string) { // start clean - SnapStop(t, snap) + SnapStop(t, service) t.Run("set and unset apps.", func(t *testing.T) { t.Cleanup(func() { SnapUnset(t, snap, "config") SnapUnset(t, snap, "config-enabled") - SnapStop(t, snap) + SnapStop(t, service) }) const newPort = "33333" @@ -89,7 +89,7 @@ func SetGlobalConfig(t *testing.T, snap, service, defaultServicePort string) { // set config. and validate the new port comes online SnapSet(t, snap, "config.service-port", newPort) - SnapStart(t, snap) + SnapStart(t, service) WaitServiceOnline(t, 60, newPort) @@ -108,7 +108,7 @@ func SetMixedConfig(t *testing.T, snap, service, appName, defaultServicePort str t.Skip("Full config test is disabled by default, and similar full config tests have been operated in device-mqtt test suite.") } else { // start clean - SnapStop(t, snap) + SnapStop(t, service) t.Run("use apps. and config. for different values", func(t *testing.T) { t.Cleanup(func() { @@ -132,7 +132,7 @@ func SetMixedConfig(t *testing.T, snap, service, appName, defaultServicePort str // and validate that app-specific option has been picked up because it has higher precedence SnapSet(t, snap, "apps."+appName+".config.service-port", newAppPort) SnapSet(t, snap, "config.service-port", newConfigPort) - SnapStart(t, snap) + SnapStart(t, service) WaitServiceOnline(t, 60, newAppPort) }) From 7b692a11ded68f39687b437f438f332eee526587 Mon Sep 17 00:00:00 2001 From: Mengyi Wang Date: Wed, 27 Apr 2022 11:44:16 +0200 Subject: [PATCH 15/24] remove unused configure.go --- test/utils/configure.go | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 test/utils/configure.go diff --git a/test/utils/configure.go b/test/utils/configure.go deleted file mode 100644 index 2eb20c7..0000000 --- a/test/utils/configure.go +++ /dev/null @@ -1,28 +0,0 @@ -package utils - -import "testing" - -func TestEnvChangeServicePort(t *testing.T, snapName, defaultServicePort string) { - const envServicePort = "env.service.port" - const newPort = "56789" - - t.Cleanup(func() { - SnapStop(t, snapName) - SnapUnset(t, snapName, envServicePort) - }) - - // make sure the port is available before using it - RequirePortAvailable(t, newPort) - - // check if service port can be changed - SnapStop(t, snapName) - SnapSet(t, snapName, envServicePort, newPort) - SnapStart(t, snapName) - WaitServiceOnline(t, 60, newPort) - - // check if service port can be unset and revert to the default - SnapStop(t, snapName) - SnapUnset(t, snapName, envServicePort) - SnapStart(t, snapName) - WaitServiceOnline(t, 60, defaultServicePort) -} From 4cbb9e6ef4045f092106d6f9c971ada1c9ea0ad2 Mon Sep 17 00:00:00 2001 From: Mengyi Wang Date: Wed, 27 Apr 2022 11:45:37 +0200 Subject: [PATCH 16/24] rename each app --- test/suites/app-rfid-llrp-inventory/main_test.go | 4 ++-- test/suites/app-service-configurable/main_test.go | 10 +++++----- test/suites/device-gpio/main_test.go | 4 ++-- test/suites/device-modbus/main_test.go | 2 +- test/suites/device-mqtt/main_test.go | 4 ++-- test/suites/device-rest/main_test.go | 4 ++-- test/suites/device-rfid-llrp/main_test.go | 2 +- test/suites/ekuiper/main_test.go | 7 +++++-- test/suites/ui/main_test.go | 7 +++++-- 9 files changed, 25 insertions(+), 19 deletions(-) diff --git a/test/suites/app-rfid-llrp-inventory/main_test.go b/test/suites/app-rfid-llrp-inventory/main_test.go index 841049e..fbe2573 100644 --- a/test/suites/app-rfid-llrp-inventory/main_test.go +++ b/test/suites/app-rfid-llrp-inventory/main_test.go @@ -10,8 +10,8 @@ import ( const ( appRfidLlrpSnap = "edgex-app-rfid-llrp-inventory" - appName = "app-rfid-llrp-inventory" - appRfidLlrpService = appRfidLlrpSnap + "." + appName + appRfidLlrpApp = "app-rfid-llrp-inventory" + appRfidLlrpService = appRfidLlrpSnap + "." + appRfidLlrpApp ) var start = time.Now() diff --git a/test/suites/app-service-configurable/main_test.go b/test/suites/app-service-configurable/main_test.go index e354a71..264524d 100644 --- a/test/suites/app-service-configurable/main_test.go +++ b/test/suites/app-service-configurable/main_test.go @@ -9,11 +9,11 @@ import ( ) const ( - ascSnap = "edgex-app-service-configurable" - appName = "app-service-configurable" - ascService = ascSnap + "." + appName - defaultProfile = "rules-engine" - appSrviceRulesServicePort = "59701" + ascSnap = "edgex-app-service-configurable" + ascApp = "app-service-configurable" + ascService = ascSnap + "." + ascApp + defaultProfile = "rules-engine" + appServiceRulesServicePort = "59701" ) var start = time.Now() diff --git a/test/suites/device-gpio/main_test.go b/test/suites/device-gpio/main_test.go index b400f7f..956efa8 100644 --- a/test/suites/device-gpio/main_test.go +++ b/test/suites/device-gpio/main_test.go @@ -10,8 +10,8 @@ import ( const ( deviceGpioSnap = "edgex-device-gpio" - appName = "device-gpio" - deviceGpioService = deviceGpioSnap + "." + appName + deviceGpioApp = "device-gpio" + deviceGpioService = deviceGpioSnap + "." + deviceGpioApp ) var start = time.Now() diff --git a/test/suites/device-modbus/main_test.go b/test/suites/device-modbus/main_test.go index 1051a24..c483830 100644 --- a/test/suites/device-modbus/main_test.go +++ b/test/suites/device-modbus/main_test.go @@ -11,7 +11,7 @@ import ( const ( deviceModbusSnap = "edgex-device-modbus" deviceModbusApp = "device-modbus" - deviceModbusService = "edgex-device-modbus." + deviceModbusApp + deviceModbusService = deviceModbusSnap + "." + deviceModbusApp ) var start = time.Now() diff --git a/test/suites/device-mqtt/main_test.go b/test/suites/device-mqtt/main_test.go index fc50aa3..129c01f 100644 --- a/test/suites/device-mqtt/main_test.go +++ b/test/suites/device-mqtt/main_test.go @@ -10,8 +10,8 @@ import ( const ( deviceMqttSnap = "edgex-device-mqtt" - appName = "device-mqtt" - deviceMqttService = deviceMqttSnap + "." + appName + deviceMqttApp = "device-mqtt" + deviceMqttService = deviceMqttSnap + "." + deviceMqttApp ) var start = time.Now() diff --git a/test/suites/device-rest/main_test.go b/test/suites/device-rest/main_test.go index 7e7e9bf..6109ae5 100644 --- a/test/suites/device-rest/main_test.go +++ b/test/suites/device-rest/main_test.go @@ -10,8 +10,8 @@ import ( const ( deviceRestSnap = "edgex-device-rest" - appName = "device-rest" - deviceRestService = deviceRestSnap + "." + appName + deviceRestApp = "device-rest" + deviceRestService = deviceRestSnap + "." + deviceRestApp ) var start = time.Now() diff --git a/test/suites/device-rfid-llrp/main_test.go b/test/suites/device-rfid-llrp/main_test.go index f2f3c23..88601f0 100644 --- a/test/suites/device-rfid-llrp/main_test.go +++ b/test/suites/device-rfid-llrp/main_test.go @@ -11,7 +11,7 @@ import ( const ( deviceRfidLlrpSnap = "edgex-device-rfid-llrp" deviceRfidApp = "device-rfid-llrp" - deviceRfidLlrpService = "edgex-device-rfid-llrp." + deviceRfidApp + deviceRfidLlrpService = deviceRfidLlrpSnap + "." + deviceRfidApp ) var start = time.Now() diff --git a/test/suites/ekuiper/main_test.go b/test/suites/ekuiper/main_test.go index 47b7dc2..e19d369 100644 --- a/test/suites/ekuiper/main_test.go +++ b/test/suites/ekuiper/main_test.go @@ -8,8 +8,11 @@ import ( "time" ) -const ekuiperSnap = "edgex-ekuiper" -const ekuiperService = "edgex-ekuiper.kuiper" +const ( + ekuiperSnap = "edgex-ekuiper" + ekuiperApp = "kuiper" + ekuiperService = ekuiperSnap + "." + ekuiperApp +) var start = time.Now() diff --git a/test/suites/ui/main_test.go b/test/suites/ui/main_test.go index dfba74a..145d366 100644 --- a/test/suites/ui/main_test.go +++ b/test/suites/ui/main_test.go @@ -8,8 +8,11 @@ import ( "time" ) -const uiSnap = "edgex-ui" -const uiService = "edgex-ui.edgex-ui" +const ( + uiSnap = "edgex-ui" + uiApp = "edgex-ui" + uiService = uiSnap + "." + uiApp +) var start = time.Now() From cfc1e65c4a6962757feeddb09b6c660b63751ce7 Mon Sep 17 00:00:00 2001 From: Mengyi Wang Date: Wed, 27 Apr 2022 11:49:44 +0200 Subject: [PATCH 17/24] construct `service` using `snap` and `app` --- .../app-rfid-llrp-inventory/config_test.go | 8 ++++---- .../app-service-configurable/config_test.go | 8 ++++---- test/suites/device-gpio/config_test.go | 8 ++++---- test/suites/device-modbus/config_test.go | 8 ++++---- test/suites/device-mqtt/config_test.go | 10 ++++------ test/suites/device-rest/config_test.go | 8 ++++---- test/suites/device-rfid-llrp/config_test.go | 8 ++++---- test/suites/device-snmp/config_test.go | 8 ++++---- test/suites/edgexfoundry/config_test.go | 6 +++--- test/utils/config.go | 20 ++++++++++++------- 10 files changed, 48 insertions(+), 44 deletions(-) diff --git a/test/suites/app-rfid-llrp-inventory/config_test.go b/test/suites/app-rfid-llrp-inventory/config_test.go index 121f92a..f13d726 100644 --- a/test/suites/app-rfid-llrp-inventory/config_test.go +++ b/test/suites/app-rfid-llrp-inventory/config_test.go @@ -7,18 +7,18 @@ import ( // Deprecated func TestEnvConfig(t *testing.T) { - utils.SetEnvConfig(t, appRfidLlrpSnap, appRfidLlrpService, defaultServicePort) + utils.SetEnvConfig(t, appRfidLlrpSnap, appRfidLlrpApp, defaultServicePort) } func TestAppConfig(t *testing.T) { - utils.SetAppConfig(t, appRfidLlrpSnap, appRfidLlrpService, appName, defaultServicePort) + utils.SetAppConfig(t, appRfidLlrpSnap, appRfidLlrpApp, defaultServicePort) } func TestGlobalConfig(t *testing.T) { // start clean - utils.SetGlobalConfig(t, appRfidLlrpSnap, appRfidLlrpService, defaultServicePort) + utils.SetGlobalConfig(t, appRfidLlrpSnap, appRfidLlrpApp, defaultServicePort) } func TestMixedConfig(t *testing.T) { - utils.SetMixedConfig(t, appRfidLlrpSnap, appRfidLlrpService, appName, defaultServicePort) + utils.SetMixedConfig(t, appRfidLlrpSnap, appRfidLlrpApp, defaultServicePort) } diff --git a/test/suites/app-service-configurable/config_test.go b/test/suites/app-service-configurable/config_test.go index 81321a9..bd900ce 100644 --- a/test/suites/app-service-configurable/config_test.go +++ b/test/suites/app-service-configurable/config_test.go @@ -13,20 +13,20 @@ const profile = "http-export" // Deprecated func TestEnvConfig(t *testing.T) { - utils.SetEnvConfig(t, ascSnap, ascService, appSrviceRulesServicePort) + utils.SetEnvConfig(t, ascSnap, ascApp, appServiceRulesServicePort) } func TestAppConfig(t *testing.T) { - utils.SetAppConfig(t, ascSnap, ascService, appName, appSrviceRulesServicePort) + utils.SetAppConfig(t, ascSnap, ascApp, appServiceRulesServicePort) } func TestGlobalConfig(t *testing.T) { // start clean - utils.SetGlobalConfig(t, ascSnap, ascService, appSrviceRulesServicePort) + utils.SetGlobalConfig(t, ascSnap, ascApp, appServiceRulesServicePort) } func TestMixedConfig(t *testing.T) { - utils.SetMixedConfig(t, ascSnap, ascService, appName, appSrviceRulesServicePort) + utils.SetMixedConfig(t, ascSnap, ascApp, appServiceRulesServicePort) } func TestProfileConfig(t *testing.T) { diff --git a/test/suites/device-gpio/config_test.go b/test/suites/device-gpio/config_test.go index abcb6ad..7131add 100644 --- a/test/suites/device-gpio/config_test.go +++ b/test/suites/device-gpio/config_test.go @@ -7,18 +7,18 @@ import ( // Deprecated func TestEnvConfig(t *testing.T) { - utils.SetEnvConfig(t, deviceGpioSnap, deviceGpioService, defaultServicePort) + utils.SetEnvConfig(t, deviceGpioSnap, deviceGpioApp, defaultServicePort) } func TestAppConfig(t *testing.T) { - utils.SetAppConfig(t, deviceGpioSnap, deviceGpioService, appName, defaultServicePort) + utils.SetAppConfig(t, deviceGpioSnap, deviceGpioApp, defaultServicePort) } func TestGlobalConfig(t *testing.T) { // start clean - utils.SetGlobalConfig(t, deviceGpioSnap, deviceGpioService, defaultServicePort) + utils.SetGlobalConfig(t, deviceGpioSnap, deviceGpioApp, defaultServicePort) } func TestMixedConfig(t *testing.T) { - utils.SetMixedConfig(t, deviceGpioSnap, deviceGpioService, appName, defaultServicePort) + utils.SetMixedConfig(t, deviceGpioSnap, deviceGpioApp, defaultServicePort) } diff --git a/test/suites/device-modbus/config_test.go b/test/suites/device-modbus/config_test.go index 589f418..356e361 100644 --- a/test/suites/device-modbus/config_test.go +++ b/test/suites/device-modbus/config_test.go @@ -7,18 +7,18 @@ import ( // Deprecated func TestEnvConfig(t *testing.T) { - utils.SetEnvConfig(t, deviceModbusSnap, deviceModbusService, defaultServicePort) + utils.SetEnvConfig(t, deviceModbusSnap, deviceModbusApp, defaultServicePort) } func TestAppConfig(t *testing.T) { - utils.SetAppConfig(t, deviceModbusSnap, deviceModbusService, deviceModbusApp, defaultServicePort) + utils.SetAppConfig(t, deviceModbusSnap, deviceModbusApp, defaultServicePort) } func TestGlobalConfig(t *testing.T) { // start clean - utils.SetGlobalConfig(t, deviceModbusSnap, deviceModbusService, defaultServicePort) + utils.SetGlobalConfig(t, deviceModbusSnap, deviceModbusApp, defaultServicePort) } func TestMixedConfig(t *testing.T) { - utils.SetMixedConfig(t, deviceModbusSnap, deviceModbusService, deviceModbusApp, defaultServicePort) + utils.SetMixedConfig(t, deviceModbusSnap, deviceModbusApp, defaultServicePort) } diff --git a/test/suites/device-mqtt/config_test.go b/test/suites/device-mqtt/config_test.go index 1abcf28..5bbea7b 100644 --- a/test/suites/device-mqtt/config_test.go +++ b/test/suites/device-mqtt/config_test.go @@ -7,20 +7,18 @@ import ( // Deprecated func TestEnvConfig(t *testing.T) { - utils.FullConfigTest = true - utils.SetEnvConfig(t, deviceMqttSnap, deviceMqttService, defaultServicePort) + utils.SetEnvConfig(t, deviceMqttSnap, deviceMqttApp, defaultServicePort) } func TestAppConfig(t *testing.T) { - utils.SetAppConfig(t, deviceMqttSnap, deviceMqttService, appName, defaultServicePort) + utils.SetAppConfig(t, deviceMqttSnap, deviceMqttApp, defaultServicePort) } func TestGlobalConfig(t *testing.T) { // start clean - utils.SetGlobalConfig(t, deviceMqttSnap, deviceMqttService, defaultServicePort) + utils.SetGlobalConfig(t, deviceMqttSnap, deviceMqttApp, defaultServicePort) } func TestMixedConfig(t *testing.T) { - utils.FullConfigTest = true - utils.SetMixedConfig(t, deviceMqttSnap, deviceMqttService, appName, defaultServicePort) + utils.SetMixedConfig(t, deviceMqttSnap, deviceMqttApp, defaultServicePort) } diff --git a/test/suites/device-rest/config_test.go b/test/suites/device-rest/config_test.go index 79e9da2..d618923 100644 --- a/test/suites/device-rest/config_test.go +++ b/test/suites/device-rest/config_test.go @@ -7,18 +7,18 @@ import ( // Deprecated func TestEnvConfig(t *testing.T) { - utils.SetEnvConfig(t, deviceRestSnap, deviceRestService, defaultServicePort) + utils.SetEnvConfig(t, deviceRestSnap, deviceRestApp, defaultServicePort) } func TestAppConfig(t *testing.T) { - utils.SetAppConfig(t, deviceRestSnap, deviceRestService, appName, defaultServicePort) + utils.SetAppConfig(t, deviceRestSnap, deviceRestApp, defaultServicePort) } func TestGlobalConfig(t *testing.T) { // start clean - utils.SetGlobalConfig(t, deviceRestSnap, deviceRestService, defaultServicePort) + utils.SetGlobalConfig(t, deviceRestSnap, deviceRestApp, defaultServicePort) } func TestMixedConfig(t *testing.T) { - utils.SetMixedConfig(t, deviceRestSnap, deviceRestService, appName, defaultServicePort) + utils.SetMixedConfig(t, deviceRestSnap, deviceRestApp, defaultServicePort) } diff --git a/test/suites/device-rfid-llrp/config_test.go b/test/suites/device-rfid-llrp/config_test.go index 248743c..0057c34 100644 --- a/test/suites/device-rfid-llrp/config_test.go +++ b/test/suites/device-rfid-llrp/config_test.go @@ -7,18 +7,18 @@ import ( // Deprecated func TestEnvConfig(t *testing.T) { - utils.SetEnvConfig(t, deviceRfidLlrpSnap, deviceRfidLlrpService, defaultServicePort) + utils.SetEnvConfig(t, deviceRfidLlrpSnap, deviceRfidApp, defaultServicePort) } func TestAppConfig(t *testing.T) { - utils.SetAppConfig(t, deviceRfidLlrpSnap, deviceRfidLlrpService, deviceRfidApp, defaultServicePort) + utils.SetAppConfig(t, deviceRfidLlrpSnap, deviceRfidApp, defaultServicePort) } func TestGlobalConfig(t *testing.T) { // start clean - utils.SetGlobalConfig(t, deviceRfidLlrpSnap, deviceRfidLlrpService, defaultServicePort) + utils.SetGlobalConfig(t, deviceRfidLlrpSnap, deviceRfidApp, defaultServicePort) } func TestMixedConfig(t *testing.T) { - utils.SetMixedConfig(t, deviceRfidLlrpSnap, deviceRfidLlrpService, deviceRfidApp, defaultServicePort) + utils.SetMixedConfig(t, deviceRfidLlrpSnap, deviceRfidApp, defaultServicePort) } diff --git a/test/suites/device-snmp/config_test.go b/test/suites/device-snmp/config_test.go index 473d6ec..570d799 100644 --- a/test/suites/device-snmp/config_test.go +++ b/test/suites/device-snmp/config_test.go @@ -7,18 +7,18 @@ import ( // Deprecated func TestEnvConfig(t *testing.T) { - utils.SetEnvConfig(t, deviceSnmpSnap, deviceSnmpService, defaultServicePort) + utils.SetEnvConfig(t, deviceSnmpSnap, deviceSnmpApp, defaultServicePort) } func TestAppConfig(t *testing.T) { - utils.SetAppConfig(t, deviceSnmpSnap, deviceSnmpService, deviceSnmpApp, defaultServicePort) + utils.SetAppConfig(t, deviceSnmpSnap, deviceSnmpApp, defaultServicePort) } func TestGlobalConfig(t *testing.T) { // start clean - utils.SetGlobalConfig(t, deviceSnmpSnap, deviceSnmpService, defaultServicePort) + utils.SetGlobalConfig(t, deviceSnmpSnap, deviceSnmpApp, defaultServicePort) } func TestMixedConfig(t *testing.T) { - utils.SetMixedConfig(t, deviceSnmpSnap, deviceSnmpService, deviceSnmpApp, defaultServicePort) + utils.SetMixedConfig(t, deviceSnmpSnap, deviceSnmpApp, defaultServicePort) } diff --git a/test/suites/edgexfoundry/config_test.go b/test/suites/edgexfoundry/config_test.go index b83a5a1..7cda408 100644 --- a/test/suites/edgexfoundry/config_test.go +++ b/test/suites/edgexfoundry/config_test.go @@ -41,7 +41,7 @@ func TestAppConfig(t *testing.T) { }) utils.SnapStart(t, deviceVirtualService) - utils.SetAppConfig(t, platformSnap, deviceVirtualService, deviceVirtualApp, deviceVirtualDefaultServicePort) + utils.SetAppConfig(t, platformSnap, deviceVirtualApp, deviceVirtualDefaultServicePort) } func TestGlobalConfig(t *testing.T) { @@ -50,7 +50,7 @@ func TestGlobalConfig(t *testing.T) { }) utils.SnapStart(t, deviceVirtualService) - utils.SetGlobalConfig(t, platformSnap, deviceVirtualService, deviceVirtualDefaultServicePort) + utils.SetGlobalConfig(t, platformSnap, deviceVirtualApp, deviceVirtualDefaultServicePort) } func TestMixedConfig(t *testing.T) { @@ -61,5 +61,5 @@ func TestMixedConfig(t *testing.T) { }) utils.SnapStart(t, deviceVirtualService) - utils.SetMixedConfig(t, platformSnap, deviceVirtualService, deviceVirtualApp, deviceVirtualDefaultServicePort) + utils.SetMixedConfig(t, platformSnap, deviceVirtualApp, deviceVirtualDefaultServicePort) } diff --git a/test/utils/config.go b/test/utils/config.go index 3e13afa..6aa68a1 100644 --- a/test/utils/config.go +++ b/test/utils/config.go @@ -2,7 +2,8 @@ package utils import "testing" -func SetEnvConfig(t *testing.T, snap, service, defaultServicePort string) { +func SetEnvConfig(t *testing.T, snap, app, servicePort string) { + service := snap + "." + app if !FullConfigTest { // make this subtest optional to save testing time, t.Skip("Full config test is disabled by default, and similar full config tests have been operated in device-mqtt test suite.") @@ -34,8 +35,9 @@ func SetEnvConfig(t *testing.T, snap, service, defaultServicePort string) { }) } } +func SetAppConfig(t *testing.T, snap, app, servicePort string) { + service := snap + "." + app -func SetAppConfig(t *testing.T, snap, service, appName, defaultServicePort string) { // start clean SnapStop(t, service) @@ -55,20 +57,22 @@ func SetAppConfig(t *testing.T, snap, service, appName, defaultServicePort strin RequirePortAvailable(t, newPort) // set apps. and validate the new port comes online - SnapSet(t, snap, "apps."+appName+".config.service-port", newPort) + SnapSet(t, snap, "apps."+app+".config.service-port", newPort) SnapStart(t, service) WaitServiceOnline(t, 60, newPort) // unset apps. and validate the default port comes online - SnapUnset(t, snap, "apps."+appName+".config.service-port") + SnapUnset(t, snap, "apps."+app+".config.service-port") SnapRestart(t, service) WaitServiceOnline(t, 60, defaultServicePort) }) } -func SetGlobalConfig(t *testing.T, snap, service, defaultServicePort string) { +func SetGlobalConfig(t *testing.T, snap, app, servicePort string) { + service := snap + "." + app + // start clean SnapStop(t, service) @@ -101,7 +105,9 @@ func SetGlobalConfig(t *testing.T, snap, service, defaultServicePort string) { }) } -func SetMixedConfig(t *testing.T, snap, service, appName, defaultServicePort string) { +func SetMixedConfig(t *testing.T, snap, app, servicePort string) { + service := snap + "." + app + if !FullConfigTest { // make this subtest optional to save testing time, // similar full config tests have been operated in device-mqtt test suite @@ -130,7 +136,7 @@ func SetMixedConfig(t *testing.T, snap, service, appName, defaultServicePort str // set apps. and config. with different values, // and validate that app-specific option has been picked up because it has higher precedence - SnapSet(t, snap, "apps."+appName+".config.service-port", newAppPort) + SnapSet(t, snap, "apps."+app+".config.service-port", newAppPort) SnapSet(t, snap, "config.service-port", newConfigPort) SnapStart(t, service) From 90531fe4c0881449eb92dd693eb54174d2f0294d Mon Sep 17 00:00:00 2001 From: Mengyi Wang Date: Wed, 27 Apr 2022 11:51:11 +0200 Subject: [PATCH 18/24] remove not needed `else` after `t.SKip()` --- test/utils/config.go | 108 +++++++++++++++++++++---------------------- 1 file changed, 53 insertions(+), 55 deletions(-) diff --git a/test/utils/config.go b/test/utils/config.go index 6aa68a1..fa27607 100644 --- a/test/utils/config.go +++ b/test/utils/config.go @@ -5,36 +5,36 @@ import "testing" func SetEnvConfig(t *testing.T, snap, app, servicePort string) { service := snap + "." + app if !FullConfigTest { - // make this subtest optional to save testing time, - t.Skip("Full config test is disabled by default, and similar full config tests have been operated in device-mqtt test suite.") - } else { - // start clean - SnapStop(t, service) + t.Skip("Full config test is disabled.") + } + // start clean + SnapStop(t, service) - t.Run("change service port", func(t *testing.T) { - t.Cleanup(func() { - SnapUnset(t, snap, "env") - SnapStop(t, service) - }) + t.Run("change service port", func(t *testing.T) { + t.Cleanup(func() { + SnapUnset(t, snap, "env") + SnapStop(t, service) + }) + + const newPort = "11111" - const newPort = "11111" + // make sure the port is available before using it + RequirePortAvailable(t, newPort) - // make sure the port is available before using it - RequirePortAvailable(t, newPort) + // set env. and validate the new port comes online + SnapSet(t, snap, "env.service.port", newPort) + SnapStart(t, service) - // set env. and validate the new port comes online - SnapSet(t, snap, "env.service.port", newPort) - SnapStart(t, service) + WaitServiceOnline(t, 60, newPort) - WaitServiceOnline(t, 60, newPort) + // unset env. and validate the default port comes online + SnapUnset(t, snap, "env.service.port") + SnapRestart(t, service) + WaitServiceOnline(t, 60, servicePort) + }) - // unset env. and validate the default port comes online - SnapUnset(t, snap, "env.service.port") - SnapRestart(t, service) - WaitServiceOnline(t, 60, defaultServicePort) - }) - } } + func SetAppConfig(t *testing.T, snap, app, servicePort string) { service := snap + "." + app @@ -109,38 +109,36 @@ func SetMixedConfig(t *testing.T, snap, app, servicePort string) { service := snap + "." + app if !FullConfigTest { - // make this subtest optional to save testing time, - // similar full config tests have been operated in device-mqtt test suite - t.Skip("Full config test is disabled by default, and similar full config tests have been operated in device-mqtt test suite.") - } else { - // start clean - SnapStop(t, service) - - t.Run("use apps. and config. for different values", func(t *testing.T) { - t.Cleanup(func() { - SnapUnset(t, snap, "apps") - SnapUnset(t, snap, "config") - SnapUnset(t, snap, "config-enabled") - SnapStop(t, service) - }) - - const newAppPort = "44444" - const newConfigPort = "55555" - - // enable new apps/config options to aviod mixed options issue with old env option - SnapSet(t, snap, "config-enabled", "true") - - // make sure the ports are available before using it - RequirePortAvailable(t, newAppPort) - RequirePortAvailable(t, newConfigPort) - - // set apps. and config. with different values, - // and validate that app-specific option has been picked up because it has higher precedence - SnapSet(t, snap, "apps."+app+".config.service-port", newAppPort) - SnapSet(t, snap, "config.service-port", newConfigPort) - SnapStart(t, service) + t.Skip("Full config test is disabled.") + } + // start clean + SnapStop(t, service) - WaitServiceOnline(t, 60, newAppPort) + t.Run("use apps. and config. for different values", func(t *testing.T) { + t.Cleanup(func() { + SnapUnset(t, snap, "apps") + SnapUnset(t, snap, "config") + SnapUnset(t, snap, "config-enabled") + SnapStop(t, service) }) - } + + const newAppPort = "44444" + const newConfigPort = "55555" + + // enable new apps/config options to aviod mixed options issue with old env option + SnapSet(t, snap, "config-enabled", "true") + + // make sure the ports are available before using it + RequirePortAvailable(t, newAppPort) + RequirePortAvailable(t, newConfigPort) + + // set apps. and config. with different values, + // and validate that app-specific option has been picked up because it has higher precedence + SnapSet(t, snap, "apps."+app+".config.service-port", newAppPort) + SnapSet(t, snap, "config.service-port", newConfigPort) + SnapStart(t, service) + + WaitServiceOnline(t, 60, newAppPort) + }) + } From ee4a90fbe911fefd1dbb4e90d9bd83482eab83d6 Mon Sep 17 00:00:00 2001 From: Mengyi Wang Date: Wed, 27 Apr 2022 11:53:18 +0200 Subject: [PATCH 19/24] rename vars --- test/suites/app-service-configurable/main_test.go | 2 +- test/suites/app-service-configurable/network_test.go | 10 +++++----- test/utils/config.go | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/suites/app-service-configurable/main_test.go b/test/suites/app-service-configurable/main_test.go index 264524d..6dd6727 100644 --- a/test/suites/app-service-configurable/main_test.go +++ b/test/suites/app-service-configurable/main_test.go @@ -54,7 +54,7 @@ func TestMain(m *testing.M) { // Otherwise, settings that get passed using environment variables on first start get uploaded // and become the default. utils.SnapStart(nil, ascService) - utils.WaitServiceOnline(nil, 60, appSrviceRulesServicePort) + utils.WaitServiceOnline(nil, 60, appServiceRulesServicePort) exitCode := m.Run() diff --git a/test/suites/app-service-configurable/network_test.go b/test/suites/app-service-configurable/network_test.go index 10a3b83..903884f 100644 --- a/test/suites/app-service-configurable/network_test.go +++ b/test/suites/app-service-configurable/network_test.go @@ -12,16 +12,16 @@ func TestNetworkInterface(t *testing.T) { utils.SnapStart(t, ascService) - t.Run("listen default port "+appSrviceRulesServicePort, func(t *testing.T) { - utils.WaitServiceOnline(t, 60, appSrviceRulesServicePort) + t.Run("listen default port "+appServiceRulesServicePort, func(t *testing.T) { + utils.WaitServiceOnline(t, 60, appServiceRulesServicePort) }) t.Run("not listen on all interfaces", func(t *testing.T) { - utils.RequireListenAllInterfaces(t, false, appSrviceRulesServicePort) + utils.RequireListenAllInterfaces(t, false, appServiceRulesServicePort) }) t.Run("listen localhost", func(t *testing.T) { - utils.RequireListenLoopback(t, appSrviceRulesServicePort) - utils.RequirePortOpen(t, appSrviceRulesServicePort) + utils.RequireListenLoopback(t, appServiceRulesServicePort) + utils.RequirePortOpen(t, appServiceRulesServicePort) }) } diff --git a/test/utils/config.go b/test/utils/config.go index fa27607..4790740 100644 --- a/test/utils/config.go +++ b/test/utils/config.go @@ -66,7 +66,7 @@ func SetAppConfig(t *testing.T, snap, app, servicePort string) { SnapUnset(t, snap, "apps."+app+".config.service-port") SnapRestart(t, service) - WaitServiceOnline(t, 60, defaultServicePort) + WaitServiceOnline(t, 60, servicePort) }) } @@ -101,7 +101,7 @@ func SetGlobalConfig(t *testing.T, snap, app, servicePort string) { SnapUnset(t, snap, "config.service-port") SnapRestart(t, service) - WaitServiceOnline(t, 60, defaultServicePort) + WaitServiceOnline(t, 60, servicePort) }) } From 7a1f36a0cdf9e97a2108bc94a332cd2f8ab18de3 Mon Sep 17 00:00:00 2001 From: Mengyi Wang Date: Wed, 27 Apr 2022 11:55:01 +0200 Subject: [PATCH 20/24] move `FullConfigTest` out of each function, and do cleanup --- test/suites/device-mqtt/config_test.go | 2 ++ test/suites/device-mqtt/main_test.go | 2 ++ test/suites/edgexfoundry/config_test.go | 4 ++-- test/suites/edgexfoundry/main_test.go | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/test/suites/device-mqtt/config_test.go b/test/suites/device-mqtt/config_test.go index 5bbea7b..ea47f09 100644 --- a/test/suites/device-mqtt/config_test.go +++ b/test/suites/device-mqtt/config_test.go @@ -5,6 +5,8 @@ import ( "testing" ) +var FullConfigTest = true + // Deprecated func TestEnvConfig(t *testing.T) { utils.SetEnvConfig(t, deviceMqttSnap, deviceMqttApp, defaultServicePort) diff --git a/test/suites/device-mqtt/main_test.go b/test/suites/device-mqtt/main_test.go index 129c01f..48023a4 100644 --- a/test/suites/device-mqtt/main_test.go +++ b/test/suites/device-mqtt/main_test.go @@ -56,5 +56,7 @@ func TestMain(m *testing.M) { "edgexfoundry", ) + FullConfigTest = false + os.Exit(exitCode) } diff --git a/test/suites/edgexfoundry/config_test.go b/test/suites/edgexfoundry/config_test.go index 7cda408..0c7e216 100644 --- a/test/suites/edgexfoundry/config_test.go +++ b/test/suites/edgexfoundry/config_test.go @@ -5,6 +5,8 @@ import ( "testing" ) +var FullConfigTest = true + // Deprecated func TestEnvConfig(t *testing.T) { const newPort = "11111" @@ -54,8 +56,6 @@ func TestGlobalConfig(t *testing.T) { } func TestMixedConfig(t *testing.T) { - utils.FullConfigTest = true - t.Cleanup(func() { utils.SnapStop(t, deviceVirtualService) }) diff --git a/test/suites/edgexfoundry/main_test.go b/test/suites/edgexfoundry/main_test.go index 50a4861..0e32891 100644 --- a/test/suites/edgexfoundry/main_test.go +++ b/test/suites/edgexfoundry/main_test.go @@ -46,7 +46,7 @@ func TestMain(m *testing.M) { platformSnap, ) - utils.FullConfigTest = false + FullConfigTest = false os.Exit(exitCode) } From 5c8b6ec649a5887b3c6f6d90cbdcc3780d0324b9 Mon Sep 17 00:00:00 2001 From: Mengyi Wang Date: Wed, 27 Apr 2022 11:55:42 +0200 Subject: [PATCH 21/24] install with `ServiceChannel` when test edgexfoundry --- test/suites/edgexfoundry/main_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/suites/edgexfoundry/main_test.go b/test/suites/edgexfoundry/main_test.go index 0e32891..c2d406e 100644 --- a/test/suites/edgexfoundry/main_test.go +++ b/test/suites/edgexfoundry/main_test.go @@ -27,7 +27,11 @@ func TestMain(m *testing.M) { platformSnap, ) - utils.SnapInstallFromStore(nil, platformSnap, utils.PlatformChannel) + if utils.LocalSnap != "" { + utils.SnapInstallFromFile(nil, utils.LocalSnap) + } else { + utils.SnapInstallFromStore(nil, platformSnap, utils.ServiceChannel) + } // make sure all services are online before starting the tests utils.WaitPlatformOnline(nil) From 08c27ff2eb42571f1122c109565e729cd3e0dd40 Mon Sep 17 00:00:00 2001 From: Mengyi Wang Date: Wed, 27 Apr 2022 11:56:08 +0200 Subject: [PATCH 22/24] update description for `platform_channel` --- test/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/test/action.yml b/test/action.yml index 7ea7c32..d29824b 100644 --- a/test/action.yml +++ b/test/action.yml @@ -21,6 +21,7 @@ inputs: platform_channel: description: | Channel for downloading the edgexfoundry snap from store. + This is used when testing services against the edgexfoundry snap. This is useful only when 'snap' input is not set. required: false print_logs: From e7e0c79ccad1309ce4a0603bd3ae3c548ce70bf3 Mon Sep 17 00:00:00 2001 From: Mengyi Wang Date: Wed, 27 Apr 2022 11:56:46 +0200 Subject: [PATCH 23/24] remove temporary pr channels --- .github/workflows/snap-testing.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/workflows/snap-testing.yml b/.github/workflows/snap-testing.yml index ba8b55a..060809e 100644 --- a/.github/workflows/snap-testing.yml +++ b/.github/workflows/snap-testing.yml @@ -16,27 +16,20 @@ jobs: matrix: include: - name: device-mqtt - channel: edge/pr-365 - name: ekuiper - name: app-service-configurable - channel: edge/pr-407 - name: device-gpio - channel: edge/pr-25 - name: device-rest - channel: edge/pr-177 - name: device-snmp - channel: edge/pr-160 - name: device-modbus - channel: edge/pr-336 - name: edgexfoundry - platform_channel: edge/pr-3986 - name: cli print_logs: false @@ -44,10 +37,9 @@ jobs: - name: ui - name: device-rfid-llrp - channel: edge/pr-75 - name: app-rfid-llrp-inventory - channel: edge/pr-74 + # use local action to test From 2d1d34aaefbbd2dae07a61f1ea4f5ab0a2ca160a Mon Sep 17 00:00:00 2001 From: Farshid Tavakolizadeh Date: Wed, 27 Apr 2022 12:59:11 +0200 Subject: [PATCH 24/24] Minor cleanup - remove obsolete comments - add comments for env vars - constant for service wait timeouts in config - error handling for boolean parsing --- .github/workflows/snap-testing.yml | 1 - .../app-rfid-llrp-inventory/config_test.go | 1 - test/suites/device-modbus/config_test.go | 1 - test/suites/device-mqtt/config_test.go | 1 - test/suites/device-mqtt/main_test.go | 2 -- test/suites/device-rest/config_test.go | 1 - test/suites/device-rfid-llrp/config_test.go | 1 - test/suites/device-snmp/config_test.go | 1 - test/utils/config.go | 16 +++++++++------- test/utils/env.go | 14 +++++++++----- 10 files changed, 18 insertions(+), 21 deletions(-) diff --git a/.github/workflows/snap-testing.yml b/.github/workflows/snap-testing.yml index 060809e..25b7928 100644 --- a/.github/workflows/snap-testing.yml +++ b/.github/workflows/snap-testing.yml @@ -39,7 +39,6 @@ jobs: - name: device-rfid-llrp - name: app-rfid-llrp-inventory - # use local action to test diff --git a/test/suites/app-rfid-llrp-inventory/config_test.go b/test/suites/app-rfid-llrp-inventory/config_test.go index f13d726..6df34f1 100644 --- a/test/suites/app-rfid-llrp-inventory/config_test.go +++ b/test/suites/app-rfid-llrp-inventory/config_test.go @@ -15,7 +15,6 @@ func TestAppConfig(t *testing.T) { } func TestGlobalConfig(t *testing.T) { - // start clean utils.SetGlobalConfig(t, appRfidLlrpSnap, appRfidLlrpApp, defaultServicePort) } diff --git a/test/suites/device-modbus/config_test.go b/test/suites/device-modbus/config_test.go index 356e361..93bfcfb 100644 --- a/test/suites/device-modbus/config_test.go +++ b/test/suites/device-modbus/config_test.go @@ -15,7 +15,6 @@ func TestAppConfig(t *testing.T) { } func TestGlobalConfig(t *testing.T) { - // start clean utils.SetGlobalConfig(t, deviceModbusSnap, deviceModbusApp, defaultServicePort) } diff --git a/test/suites/device-mqtt/config_test.go b/test/suites/device-mqtt/config_test.go index ea47f09..9661b36 100644 --- a/test/suites/device-mqtt/config_test.go +++ b/test/suites/device-mqtt/config_test.go @@ -17,7 +17,6 @@ func TestAppConfig(t *testing.T) { } func TestGlobalConfig(t *testing.T) { - // start clean utils.SetGlobalConfig(t, deviceMqttSnap, deviceMqttApp, defaultServicePort) } diff --git a/test/suites/device-mqtt/main_test.go b/test/suites/device-mqtt/main_test.go index 48023a4..129c01f 100644 --- a/test/suites/device-mqtt/main_test.go +++ b/test/suites/device-mqtt/main_test.go @@ -56,7 +56,5 @@ func TestMain(m *testing.M) { "edgexfoundry", ) - FullConfigTest = false - os.Exit(exitCode) } diff --git a/test/suites/device-rest/config_test.go b/test/suites/device-rest/config_test.go index d618923..f200eca 100644 --- a/test/suites/device-rest/config_test.go +++ b/test/suites/device-rest/config_test.go @@ -15,7 +15,6 @@ func TestAppConfig(t *testing.T) { } func TestGlobalConfig(t *testing.T) { - // start clean utils.SetGlobalConfig(t, deviceRestSnap, deviceRestApp, defaultServicePort) } diff --git a/test/suites/device-rfid-llrp/config_test.go b/test/suites/device-rfid-llrp/config_test.go index 0057c34..6388f65 100644 --- a/test/suites/device-rfid-llrp/config_test.go +++ b/test/suites/device-rfid-llrp/config_test.go @@ -15,7 +15,6 @@ func TestAppConfig(t *testing.T) { } func TestGlobalConfig(t *testing.T) { - // start clean utils.SetGlobalConfig(t, deviceRfidLlrpSnap, deviceRfidApp, defaultServicePort) } diff --git a/test/suites/device-snmp/config_test.go b/test/suites/device-snmp/config_test.go index 570d799..e49655b 100644 --- a/test/suites/device-snmp/config_test.go +++ b/test/suites/device-snmp/config_test.go @@ -15,7 +15,6 @@ func TestAppConfig(t *testing.T) { } func TestGlobalConfig(t *testing.T) { - // start clean utils.SetGlobalConfig(t, deviceSnmpSnap, deviceSnmpApp, defaultServicePort) } diff --git a/test/utils/config.go b/test/utils/config.go index 4790740..53e495e 100644 --- a/test/utils/config.go +++ b/test/utils/config.go @@ -2,6 +2,8 @@ package utils import "testing" +const serviceWaitTimeout = 60 // seconds + func SetEnvConfig(t *testing.T, snap, app, servicePort string) { service := snap + "." + app if !FullConfigTest { @@ -25,12 +27,12 @@ func SetEnvConfig(t *testing.T, snap, app, servicePort string) { SnapSet(t, snap, "env.service.port", newPort) SnapStart(t, service) - WaitServiceOnline(t, 60, newPort) + WaitServiceOnline(t, serviceWaitTimeout, newPort) // unset env. and validate the default port comes online SnapUnset(t, snap, "env.service.port") SnapRestart(t, service) - WaitServiceOnline(t, 60, servicePort) + WaitServiceOnline(t, serviceWaitTimeout, servicePort) }) } @@ -60,13 +62,13 @@ func SetAppConfig(t *testing.T, snap, app, servicePort string) { SnapSet(t, snap, "apps."+app+".config.service-port", newPort) SnapStart(t, service) - WaitServiceOnline(t, 60, newPort) + WaitServiceOnline(t, serviceWaitTimeout, newPort) // unset apps. and validate the default port comes online SnapUnset(t, snap, "apps."+app+".config.service-port") SnapRestart(t, service) - WaitServiceOnline(t, 60, servicePort) + WaitServiceOnline(t, serviceWaitTimeout, servicePort) }) } @@ -95,13 +97,13 @@ func SetGlobalConfig(t *testing.T, snap, app, servicePort string) { SnapSet(t, snap, "config.service-port", newPort) SnapStart(t, service) - WaitServiceOnline(t, 60, newPort) + WaitServiceOnline(t, serviceWaitTimeout, newPort) // unset config. and validate the default port comes online SnapUnset(t, snap, "config.service-port") SnapRestart(t, service) - WaitServiceOnline(t, 60, servicePort) + WaitServiceOnline(t, serviceWaitTimeout, servicePort) }) } @@ -138,7 +140,7 @@ func SetMixedConfig(t *testing.T, snap, app, servicePort string) { SnapSet(t, snap, "config.service-port", newConfigPort) SnapStart(t, service) - WaitServiceOnline(t, 60, newAppPort) + WaitServiceOnline(t, serviceWaitTimeout, newAppPort) }) } diff --git a/test/utils/env.go b/test/utils/env.go index c65fb9d..f37a364 100644 --- a/test/utils/env.go +++ b/test/utils/env.go @@ -8,10 +8,10 @@ import ( const ( // environment variables // used to override defaults - platformChannel = "PLATFORM_CHANNEL" - serviceChannel = "SERVICE_CHANNEL" - localSnap = "LOCAL_SNAP" - fullConfigTest = "FULL_CONFIG_TEST" + platformChannel = "PLATFORM_CHANNEL" // edgexfoundry channel when testing other snaps (has default) + serviceChannel = "SERVICE_CHANNEL" // channel of the snap to be tested (has default) + localSnap = "LOCAL_SNAP" // path to local snap to be tested instead of downloading from a channel + fullConfigTest = "FULL_CONFIG_TEST" // toggle full config tests (has default) ) var ( @@ -36,6 +36,10 @@ func init() { } if v := os.Getenv(fullConfigTest); v != "" { - FullConfigTest, _ = strconv.ParseBool(v) + var err error + FullConfigTest, err = strconv.ParseBool(v) + if err != nil { + panic(err) + } } }