Skip to content

Commit

Permalink
WIP on IENG-1144-update-deps
Browse files Browse the repository at this point in the history
  • Loading branch information
jpm-canonical committed Aug 1, 2024
1 parent 4ce0d56 commit 2ef629b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 23 deletions.
9 changes: 0 additions & 9 deletions tests/common.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package tests

import (
"os"
"strings"
"testing"
"time"

"github.com/canonical/matter-snap-testing/env"
"github.com/canonical/matter-snap-testing/utils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -39,12 +36,6 @@ func InstallChipTool(t *testing.T) {
utils.SnapConnect(t, chipToolSnap+":process-control", "")
}

func writeLogFile(t *testing.T, label string, b []byte) {
assert.NoError(t,
os.WriteFile(strings.ReplaceAll(t.Name(), "/", "-")+"-"+label+".log", b, 0644),
)
}

func waitForOnOffHandlingByAllClustersApp(t *testing.T, start time.Time) {
// 0x6 is the Matter Cluster ID for on-off
// Using cluster ID here because of a buffering issue in the log stream:
Expand Down
2 changes: 2 additions & 0 deletions tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ require (
golang.org/x/sys v0.22.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/canonical/matter-snap-testing => /home/jpmeijers/matter-snap-testing
11 changes: 4 additions & 7 deletions tests/thread_tests/thread_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package thread_tests

import (
"os"
"testing"
"time"

Expand All @@ -18,17 +17,15 @@ func TestAllClustersAppThread(t *testing.T) {

t.Run("Commission", func(t *testing.T) {
stdout, _, _ := utils.Exec(t, "chip-tool pairing code-thread 110 hex:"+trimmedActiveDataset+" 34970112332 2>&1")
assert.NoError(t,
os.WriteFile("chip-tool-thread-pairing.log", []byte(stdout), 0644),
)

assert.NoError(t, utils.WriteLogFile(t, "chip-tool-thread-pairing", []byte(stdout)))
})

t.Run("Control", func(t *testing.T) {
start := time.Now()
stdout, _, _ := utils.Exec(t, "chip-tool onoff toggle 110 1 2>&1")
assert.NoError(t,
os.WriteFile("chip-tool-thread-onoff.log", []byte(stdout), 0644),
)

assert.NoError(t, utils.WriteLogFile(t, "chip-tool-thread-onoff", []byte(stdout)))

// 0x6 is the Matter Cluster ID for on-off
// Using cluster ID here because of a buffering issue in the log stream:
Expand Down
12 changes: 7 additions & 5 deletions tests/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ import (

"github.com/canonical/matter-snap-testing/env"
"github.com/canonical/matter-snap-testing/utils"
"github.com/stretchr/testify/assert"
)

func TestUpgrade(t *testing.T) {
start := time.Now()

t.Cleanup(func() {
// Remove snaps, ignoring errors
utils.SnapRemove(nil, allClustersSnap)
utils.SnapDumpLogs(nil, start, allClustersSnap)

utils.SnapRemove(nil, chipToolSnap)

utils.SnapDumpLogs(t, start, allClustersSnap)
})

// Start clean
Expand Down Expand Up @@ -46,7 +48,7 @@ func TestUpgrade(t *testing.T) {

t.Run("Commission", func(t *testing.T) {
stdout, _, _ := utils.Exec(t, "chip-tool pairing onnetwork 110 20202021 2>&1")
writeLogFile(t, "chip-tool-pairing", []byte(stdout))
assert.NoError(t, utils.WriteLogFile(t, "chip-tool-pairing", []byte(stdout)))
})

t.Run("Control before upgrade", func(t *testing.T) {
Expand All @@ -56,7 +58,7 @@ func TestUpgrade(t *testing.T) {

start := time.Now()
stdout, _, _ := utils.Exec(t, "chip-tool onoff on 110 1 2>&1")
writeLogFile(t, "chip-tool-onoff", []byte(stdout))
assert.NoError(t, utils.WriteLogFile(t, "chip-tool-onoff", []byte(stdout)))

waitForOnOffHandlingByAllClustersApp(t, start)
})
Expand All @@ -76,7 +78,7 @@ func TestUpgrade(t *testing.T) {

start := time.Now()
stdout, _, _ := utils.Exec(t, "chip-tool onoff off 110 1 2>&1")
writeLogFile(t, "chip-tool-onoff", []byte(stdout))
assert.NoError(t, utils.WriteLogFile(t, "chip-tool-onoff", []byte(stdout)))

waitForOnOffHandlingByAllClustersApp(t, start)
})
Expand Down
5 changes: 3 additions & 2 deletions tests/wifi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"github.com/canonical/matter-snap-testing/utils"
"github.com/stretchr/testify/assert"
)

func TestAllClustersAppWiFi(t *testing.T) {
Expand Down Expand Up @@ -35,12 +36,12 @@ func TestAllClustersAppWiFi(t *testing.T) {

t.Run("Commission", func(t *testing.T) {
stdout, _, _ := utils.Exec(t, "chip-tool pairing onnetwork 110 20202021 2>&1")
writeLogFile(t, "chip-tool-pairing", []byte(stdout))
assert.NoError(t, utils.WriteLogFile(t, "chip-tool-pairing", []byte(stdout)))
})

t.Run("Control", func(t *testing.T) {
stdout, _, _ := utils.Exec(t, "chip-tool onoff toggle 110 1 2>&1")
writeLogFile(t, "chip-tool-toggle", []byte(stdout))
assert.NoError(t, utils.WriteLogFile(t, "chip-tool-toggle", []byte(stdout)))

waitForOnOffHandlingByAllClustersApp(t, start)
})
Expand Down

0 comments on commit 2ef629b

Please sign in to comment.