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

Commit

Permalink
Add tests for snap config options (#53)
Browse files Browse the repository at this point in the history
* Add apps/config options tests for environment variable injection
* Refactoring of config tests with new utility functions
* Expose platform channel to allow override via Github workflows
* Add env var to toggle full config tests
* Correct app-service-configurable default port

Co-authored-by: Mengyi <[email protected]>
  • Loading branch information
farshidtz and MonicaisHer authored Apr 27, 2022
1 parent ed0a32e commit 9747683
Show file tree
Hide file tree
Showing 28 changed files with 370 additions and 192 deletions.
1 change: 1 addition & 0 deletions .github/workflows/snap-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ jobs:
with:
name: ${{matrix.name}}
channel: ${{matrix.channel}}
platform_channel: ${{matrix.platform_channel}}
print_logs: ${{matrix.print_logs}}
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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}}
Expand Down
26 changes: 9 additions & 17 deletions test/suites/app-rfid-llrp-inventory/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
7 changes: 5 additions & 2 deletions test/suites/app-rfid-llrp-inventory/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
30 changes: 10 additions & 20 deletions test/suites/app-service-configurable/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 13 additions & 3 deletions test/suites/app-service-configurable/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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]")
Expand Down
10 changes: 5 additions & 5 deletions test/suites/app-service-configurable/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
28 changes: 10 additions & 18 deletions test/suites/device-gpio/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
7 changes: 5 additions & 2 deletions test/suites/device-gpio/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

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

Expand Down
29 changes: 11 additions & 18 deletions test/suites/device-mqtt/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
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"
deviceMqttApp = "device-mqtt"
deviceMqttService = deviceMqttSnap + "." + deviceMqttApp
)

var start = time.Now()

Expand Down
26 changes: 9 additions & 17 deletions test/suites/device-rest/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
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"
deviceRestApp = "device-rest"
deviceRestService = deviceRestSnap + "." + deviceRestApp
)

var start = time.Now()

Expand Down
Loading

0 comments on commit 9747683

Please sign in to comment.