From 97a9e4ba6525d745d4a26351c5e636d6016fccf1 Mon Sep 17 00:00:00 2001 From: JP Meijers <165929400+jpm-canonical@users.noreply.github.com> Date: Wed, 7 Aug 2024 15:28:31 +0200 Subject: [PATCH] Use matter-snap-testing to handle log files (#74) * Update log file path to directory * Update matter-snap-testing to beta.6 * Remove duplication in log file names --- .github/workflows/build-and-test-snap.yml | 2 +- tests/common.go | 9 --------- tests/go.mod | 4 ++-- tests/go.sum | 8 ++++---- tests/thread_tests/thread_test.go | 11 ++++------- tests/upgrade_test.go | 14 ++++++++------ tests/wifi_test.go | 5 +++-- 7 files changed, 22 insertions(+), 31 deletions(-) diff --git a/.github/workflows/build-and-test-snap.yml b/.github/workflows/build-and-test-snap.yml index bbc87f4..61d8d68 100644 --- a/.github/workflows/build-and-test-snap.yml +++ b/.github/workflows/build-and-test-snap.yml @@ -68,7 +68,7 @@ jobs: uses: actions/upload-artifact@v4 with: name: logs - path: tests/*.log + path: tests/logs/*.log publish-amd64: # Only publish if we are on the main branch 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..4193c0f 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -5,7 +5,7 @@ go 1.22.1 toolchain go1.22.5 require ( - github.com/canonical/matter-snap-testing v1.0.0-beta.4 + github.com/canonical/matter-snap-testing v1.0.0-beta.6 github.com/stretchr/testify v1.9.0 golang.org/x/crypto v0.25.0 ) @@ -14,6 +14,6 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/kr/text v0.2.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/sys v0.22.0 // indirect + golang.org/x/sys v0.23.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/tests/go.sum b/tests/go.sum index 88cfd9c..ea984d0 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -1,5 +1,5 @@ -github.com/canonical/matter-snap-testing v1.0.0-beta.4 h1:fbmKYeGaIFAlugDBx6ehz0U10bG+WcFSgNBo36hxBL0= -github.com/canonical/matter-snap-testing v1.0.0-beta.4/go.mod h1:gQqLfxxUD2Uo1Ua/L1uIuRhTVghAtdS54yhetTOeSIc= +github.com/canonical/matter-snap-testing v1.0.0-beta.6 h1:t2x/gnRdAhkak4Pta+wP56kgE73MpTRUy2Wp6Sse5wo= +github.com/canonical/matter-snap-testing v1.0.0-beta.6/go.mod h1:gQqLfxxUD2Uo1Ua/L1uIuRhTVghAtdS54yhetTOeSIc= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -13,8 +13,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= -golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= -golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM= +golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk= golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/tests/thread_tests/thread_test.go b/tests/thread_tests/thread_test.go index aab4365..0bb4b18 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", 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", 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..90488bd 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 during removal 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, chipToolSnap, 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, chipToolSnap, stdout)) waitForOnOffHandlingByAllClustersApp(t, start) }) @@ -69,14 +71,14 @@ func TestUpgrade(t *testing.T) { } }) - t.Run("Control upgraded snap", func(t *testing.T) { + t.Run("Control after upgrade", func(t *testing.T) { snapVersion := utils.SnapVersion(t, chipToolSnap) snapRevision := utils.SnapRevision(t, chipToolSnap) log.Printf("%s installed version %s build %s\n", chipToolSnap, snapVersion, snapRevision) 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, chipToolSnap, stdout)) waitForOnOffHandlingByAllClustersApp(t, start) }) diff --git a/tests/wifi_test.go b/tests/wifi_test.go index d8faaaf..8ded1b6 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, chipToolSnap, 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, chipToolSnap, stdout)) waitForOnOffHandlingByAllClustersApp(t, start) })