diff --git a/tests/common.go b/tests/common.go index c227e53..45b018f 100644 --- a/tests/common.go +++ b/tests/common.go @@ -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" ) @@ -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: diff --git a/tests/go.mod b/tests/go.mod index 1380952..0effdbe 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -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 diff --git a/tests/thread_tests/thread_test.go b/tests/thread_tests/thread_test.go index aab4365..ec77941 100644 --- a/tests/thread_tests/thread_test.go +++ b/tests/thread_tests/thread_test.go @@ -1,7 +1,6 @@ package thread_tests import ( - "os" "testing" "time" @@ -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: diff --git a/tests/upgrade_test.go b/tests/upgrade_test.go index e4f6979..9f0fb09 100644 --- a/tests/upgrade_test.go +++ b/tests/upgrade_test.go @@ -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 @@ -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) { @@ -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) }) @@ -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) }) diff --git a/tests/wifi_test.go b/tests/wifi_test.go index d8faaaf..79695b0 100644 --- a/tests/wifi_test.go +++ b/tests/wifi_test.go @@ -5,6 +5,7 @@ import ( "time" "github.com/canonical/matter-snap-testing/utils" + "github.com/stretchr/testify/assert" ) func TestAllClustersAppWiFi(t *testing.T) { @@ -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) })