Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
Move config testing into util functions, add FULL_CONFIG_TEST option (
Browse files Browse the repository at this point in the history
#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: canonical/edgex-snap-hooks#41
  • Loading branch information
MonicaisHer authored Apr 22, 2022
1 parent 66a0e93 commit f978f6c
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 220 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
114 changes: 6 additions & 108 deletions test/suites/device-mqtt/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
7 changes: 5 additions & 2 deletions test/suites/device-mqtt/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
111 changes: 4 additions & 107 deletions test/suites/device-rest/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
7 changes: 5 additions & 2 deletions test/suites/device-rest/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Loading

0 comments on commit f978f6c

Please sign in to comment.