diff --git a/.github/workflows/snap-testing.yml b/.github/workflows/snap-testing.yml index f9a8343..25b7928 100644 --- a/.github/workflows/snap-testing.yml +++ b/.github/workflows/snap-testing.yml @@ -54,4 +54,5 @@ jobs: with: name: ${{matrix.name}} channel: ${{matrix.channel}} + platform_channel: ${{matrix.platform_channel}} print_logs: ${{matrix.print_logs}} diff --git a/README.md b/README.md index 9946657..559cf61 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,14 @@ To test all: go test -p 1 ./test/suites/... ``` +Test one with variables, e.g.: +```bash +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 +``` + Test the testing utils: ```bash go test ./test/utils -count=10 diff --git a/test/action.yml b/test/action.yml index ad614e0..d29824b 100644 --- a/test/action.yml +++ b/test/action.yml @@ -18,6 +18,12 @@ 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 used when testing services against the edgexfoundry snap. + This is useful only when 'snap' input is not set. + required: false print_logs: description: | Print snap logs. @@ -48,6 +54,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/app-rfid-llrp-inventory/config_test.go b/test/suites/app-rfid-llrp-inventory/config_test.go index 22cea81..6df34f1 100644 --- a/test/suites/app-rfid-llrp-inventory/config_test.go +++ b/test/suites/app-rfid-llrp-inventory/config_test.go @@ -7,25 +7,17 @@ import ( // Deprecated func TestEnvConfig(t *testing.T) { + utils.SetEnvConfig(t, appRfidLlrpSnap, appRfidLlrpApp, 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, appRfidLlrpApp, 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) { + utils.SetGlobalConfig(t, appRfidLlrpSnap, appRfidLlrpApp, defaultServicePort) } -func TestAppConfig(t *testing.T) { - t.Skip("TODO") +func TestMixedConfig(t *testing.T) { + utils.SetMixedConfig(t, appRfidLlrpSnap, appRfidLlrpApp, 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..fbe2573 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" + appRfidLlrpApp = "app-rfid-llrp-inventory" + appRfidLlrpService = appRfidLlrpSnap + "." + appRfidLlrpApp +) var start = time.Now() diff --git a/test/suites/app-service-configurable/config_test.go b/test/suites/app-service-configurable/config_test.go index edf4b90..bd900ce 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, ascApp, appServiceRulesServicePort) +} - // make sure the port is available before using it - utils.RequirePortAvailable(t, newPort) +func TestAppConfig(t *testing.T) { + utils.SetAppConfig(t, ascSnap, ascApp, appServiceRulesServicePort) +} - 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, ascApp, appServiceRulesServicePort) } -func TestAppConfig(t *testing.T) { - t.Skip("TODO") +func TestMixedConfig(t *testing.T) { + utils.SetMixedConfig(t, ascSnap, ascApp, appServiceRulesServicePort) } 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..6dd6727 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" + ascApp = "app-service-configurable" + ascService = ascSnap + "." + ascApp + defaultProfile = "rules-engine" + appServiceRulesServicePort = "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, appServiceRulesServicePort) + 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..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 "+appRulesEngineServicePort, func(t *testing.T) { - utils.WaitServiceOnline(t, 60, appRulesEngineServicePort) + 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, appRulesEngineServicePort) + utils.RequireListenAllInterfaces(t, false, appServiceRulesServicePort) }) t.Run("listen localhost", func(t *testing.T) { - utils.RequireListenLoopback(t, appRulesEngineServicePort) - utils.RequirePortOpen(t, appRulesEngineServicePort) + utils.RequireListenLoopback(t, appServiceRulesServicePort) + utils.RequirePortOpen(t, appServiceRulesServicePort) }) } diff --git a/test/suites/device-gpio/config_test.go b/test/suites/device-gpio/config_test.go index 39f82bd..7131add 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, deviceGpioApp, defaultServicePort) +} - // make sure the port is available before using it - utils.RequirePortAvailable(t, newPort) +func TestAppConfig(t *testing.T) { + utils.SetAppConfig(t, deviceGpioSnap, deviceGpioApp, 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, deviceGpioApp, defaultServicePort) } -func TestAppConfig(t *testing.T) { - t.Skip("TODO") +func TestMixedConfig(t *testing.T) { + utils.SetMixedConfig(t, deviceGpioSnap, deviceGpioApp, defaultServicePort) } diff --git a/test/suites/device-gpio/main_test.go b/test/suites/device-gpio/main_test.go index 6577dce..956efa8 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" + deviceGpioApp = "device-gpio" + deviceGpioService = deviceGpioSnap + "." + deviceGpioApp +) var start = time.Now() diff --git a/test/suites/device-modbus/config_test.go b/test/suites/device-modbus/config_test.go index 535ab9c..93bfcfb 100644 --- a/test/suites/device-modbus/config_test.go +++ b/test/suites/device-modbus/config_test.go @@ -7,11 +7,17 @@ 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, deviceModbusApp, defaultServicePort) } func TestAppConfig(t *testing.T) { - t.Skip("TODO") + utils.SetAppConfig(t, deviceModbusSnap, deviceModbusApp, defaultServicePort) +} + +func TestGlobalConfig(t *testing.T) { + utils.SetGlobalConfig(t, deviceModbusSnap, deviceModbusApp, defaultServicePort) +} + +func TestMixedConfig(t *testing.T) { + utils.SetMixedConfig(t, deviceModbusSnap, deviceModbusApp, defaultServicePort) } diff --git a/test/suites/device-modbus/main_test.go b/test/suites/device-modbus/main_test.go index 7161d14..c483830 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 = deviceModbusSnap + "." + deviceModbusApp +) var start = time.Now() diff --git a/test/suites/device-mqtt/config_test.go b/test/suites/device-mqtt/config_test.go index c7e2b9e..9661b36 100644 --- a/test/suites/device-mqtt/config_test.go +++ b/test/suites/device-mqtt/config_test.go @@ -5,28 +5,21 @@ import ( "testing" ) +var FullConfigTest = true + // Deprecated func TestEnvConfig(t *testing.T) { - // start clean - utils.SnapStop(t, deviceMqttService) - - t.Run("change service port", func(t *testing.T) { - t.Cleanup(func() { - utils.SnapStop(t, deviceMqttService) - utils.SnapUnset(t, deviceMqttSnap, "env.service.port") - }) - - const newPort = "56789" + utils.SetEnvConfig(t, deviceMqttSnap, deviceMqttApp, defaultServicePort) +} - // make sure the port is available before using it - utils.RequirePortAvailable(t, newPort) +func TestAppConfig(t *testing.T) { + utils.SetAppConfig(t, deviceMqttSnap, deviceMqttApp, defaultServicePort) +} - utils.SnapSet(t, deviceMqttSnap, "env.service.port", newPort) - utils.SnapStart(t, deviceMqttSnap) - utils.WaitServiceOnline(t, 60, newPort) - }) +func TestGlobalConfig(t *testing.T) { + utils.SetGlobalConfig(t, deviceMqttSnap, deviceMqttApp, defaultServicePort) } -func TestAppConfig(t *testing.T) { - t.Skip("TODO") +func TestMixedConfig(t *testing.T) { + utils.SetMixedConfig(t, deviceMqttSnap, deviceMqttApp, defaultServicePort) } diff --git a/test/suites/device-mqtt/main_test.go b/test/suites/device-mqtt/main_test.go index 619d688..129c01f 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" + deviceMqttApp = "device-mqtt" + deviceMqttService = deviceMqttSnap + "." + deviceMqttApp +) var start = time.Now() diff --git a/test/suites/device-rest/config_test.go b/test/suites/device-rest/config_test.go index 8da7e1f..f200eca 100644 --- a/test/suites/device-rest/config_test.go +++ b/test/suites/device-rest/config_test.go @@ -7,25 +7,17 @@ import ( // Deprecated func TestEnvConfig(t *testing.T) { + utils.SetEnvConfig(t, deviceRestSnap, deviceRestApp, defaultServicePort) +} - t.Run("change service port", func(t *testing.T) { - t.Cleanup(func() { - utils.SnapStop(t, deviceRestService) - utils.SnapUnset(t, deviceRestSnap, "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, deviceRestSnap, deviceRestApp, defaultServicePort) +} - utils.SnapStop(t, deviceRestSnap) - utils.SnapSet(t, deviceRestSnap, "env.service.port", newPort) - utils.SnapStart(t, deviceRestSnap) - utils.WaitServiceOnline(t, 60, newPort) - }) +func TestGlobalConfig(t *testing.T) { + utils.SetGlobalConfig(t, deviceRestSnap, deviceRestApp, defaultServicePort) } -func TestAppConfig(t *testing.T) { - t.Skip("TODO") +func TestMixedConfig(t *testing.T) { + utils.SetMixedConfig(t, deviceRestSnap, deviceRestApp, defaultServicePort) } diff --git a/test/suites/device-rest/main_test.go b/test/suites/device-rest/main_test.go index b670473..6109ae5 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" + deviceRestApp = "device-rest" + deviceRestService = deviceRestSnap + "." + deviceRestApp +) var start = time.Now() diff --git a/test/suites/device-rfid-llrp/config_test.go b/test/suites/device-rfid-llrp/config_test.go index e74c82c..6388f65 100644 --- a/test/suites/device-rfid-llrp/config_test.go +++ b/test/suites/device-rfid-llrp/config_test.go @@ -7,25 +7,17 @@ import ( // Deprecated func TestEnvConfig(t *testing.T) { + utils.SetEnvConfig(t, deviceRfidLlrpSnap, deviceRfidApp, 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, 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) { + utils.SetGlobalConfig(t, deviceRfidLlrpSnap, deviceRfidApp, defaultServicePort) } -func TestAppConfig(t *testing.T) { - t.Skip("TODO") +func TestMixedConfig(t *testing.T) { + utils.SetMixedConfig(t, deviceRfidLlrpSnap, deviceRfidApp, defaultServicePort) } diff --git a/test/suites/device-rfid-llrp/main_test.go b/test/suites/device-rfid-llrp/main_test.go index 1f86306..88601f0 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 = deviceRfidLlrpSnap + "." + deviceRfidApp +) var start = time.Now() diff --git a/test/suites/device-snmp/config_test.go b/test/suites/device-snmp/config_test.go index 3e68367..e49655b 100644 --- a/test/suites/device-snmp/config_test.go +++ b/test/suites/device-snmp/config_test.go @@ -7,11 +7,17 @@ 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, deviceSnmpApp, defaultServicePort) } func TestAppConfig(t *testing.T) { - t.Skip("TODO") + utils.SetAppConfig(t, deviceSnmpSnap, deviceSnmpApp, defaultServicePort) +} + +func TestGlobalConfig(t *testing.T) { + utils.SetGlobalConfig(t, deviceSnmpSnap, deviceSnmpApp, defaultServicePort) +} + +func TestMixedConfig(t *testing.T) { + utils.SetMixedConfig(t, deviceSnmpSnap, 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() diff --git a/test/suites/edgexfoundry/config_test.go b/test/suites/edgexfoundry/config_test.go index 84e23cf..0c7e216 100644 --- a/test/suites/edgexfoundry/config_test.go +++ b/test/suites/edgexfoundry/config_test.go @@ -5,36 +5,61 @@ import ( "testing" ) +var FullConfigTest = true + // 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, deviceVirtualApp, deviceVirtualDefaultServicePort) +} + +func TestGlobalConfig(t *testing.T) { + t.Cleanup(func() { + utils.SnapStop(t, deviceVirtualService) + }) + + utils.SnapStart(t, deviceVirtualService) + utils.SetGlobalConfig(t, platformSnap, deviceVirtualApp, deviceVirtualDefaultServicePort) +} + +func TestMixedConfig(t *testing.T) { + t.Cleanup(func() { + utils.SnapStop(t, deviceVirtualService) + }) + + utils.SnapStart(t, deviceVirtualService) + utils.SetMixedConfig(t, platformSnap, deviceVirtualApp, deviceVirtualDefaultServicePort) } diff --git a/test/suites/edgexfoundry/main_test.go b/test/suites/edgexfoundry/main_test.go index d08e8de..c2d406e 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" ) @@ -27,13 +27,17 @@ 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) // 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 +50,7 @@ func TestMain(m *testing.M) { platformSnap, ) + 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/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() diff --git a/test/utils/config.go b/test/utils/config.go new file mode 100644 index 0000000..53e495e --- /dev/null +++ b/test/utils/config.go @@ -0,0 +1,146 @@ +package utils + +import "testing" + +const serviceWaitTimeout = 60 // seconds + +func SetEnvConfig(t *testing.T, snap, app, servicePort string) { + service := snap + "." + app + if !FullConfigTest { + 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) + }) + + 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, service) + + WaitServiceOnline(t, serviceWaitTimeout, newPort) + + // unset env. and validate the default port comes online + SnapUnset(t, snap, "env.service.port") + SnapRestart(t, service) + WaitServiceOnline(t, serviceWaitTimeout, servicePort) + }) + +} + +func SetAppConfig(t *testing.T, snap, app, servicePort string) { + service := snap + "." + app + + // start clean + 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, service) + }) + + 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."+app+".config.service-port", newPort) + SnapStart(t, service) + + 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, serviceWaitTimeout, servicePort) + }) +} + +func SetGlobalConfig(t *testing.T, snap, app, servicePort string) { + service := snap + "." + app + + // start clean + 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, service) + }) + + 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, service) + + WaitServiceOnline(t, serviceWaitTimeout, newPort) + + // unset config. and validate the default port comes online + SnapUnset(t, snap, "config.service-port") + SnapRestart(t, service) + + WaitServiceOnline(t, serviceWaitTimeout, servicePort) + }) +} + +func SetMixedConfig(t *testing.T, snap, app, servicePort string) { + service := snap + "." + app + + if !FullConfigTest { + t.Skip("Full config test is disabled.") + } + // 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) + + WaitServiceOnline(t, serviceWaitTimeout, newAppPort) + }) + +} 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) -} diff --git a/test/utils/env.go b/test/utils/env.go index 7dfd87f..f37a364 100644 --- a/test/utils/env.go +++ b/test/utils/env.go @@ -1,13 +1,17 @@ package utils -import "os" +import ( + "os" + "strconv" +) const ( // environment variables // used to override defaults - platformChannel = "PLATFORM_CHANNEL" - serviceChannel = "SERVICE_CHANNEL" - localSnap = "LOCAL_SNAP" + 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 ( @@ -15,6 +19,7 @@ var ( PlatformChannel = "latest/edge" ServiceChannel = "latest/edge" LocalSnap = "" + FullConfigTest = false ) func init() { @@ -29,4 +34,12 @@ func init() { if v := os.Getenv(localSnap); v != "" { LocalSnap = v } + + if v := os.Getenv(fullConfigTest); v != "" { + var err error + FullConfigTest, err = strconv.ParseBool(v) + if err != nil { + panic(err) + } + } }