From dc0a4e402bea575815701c8465098fd0564f7f83 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 1 Mar 2024 13:45:21 +0000 Subject: [PATCH 1/3] fix(deps): update module github.com/stretchr/testify to v1.9.0 --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index b96c48a..9f34777 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module github.com/canonical/matter-snap-testing go 1.21.6 -require github.com/stretchr/testify v1.8.4 +require github.com/stretchr/testify v1.9.0 require ( github.com/davecgh/go-spew v1.1.1 // indirect diff --git a/go.sum b/go.sum index e69f1b6..c689bee 100644 --- a/go.sum +++ b/go.sum @@ -11,6 +11,8 @@ github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gt github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From abae29ac5e865f0c5208350bdab63cecb3bdcc5a Mon Sep 17 00:00:00 2001 From: "Lincoln Wallace V. Almeida" Date: Wed, 27 Mar 2024 18:37:18 -0300 Subject: [PATCH 2/3] refact: capitalize env variables to showup in documentation (#24) refact: export env variables to show up in documentation on pkg.go.dev --- .github/workflows/unit-testing.yml | 1 + README.md | 2 ++ env/env.go | 12 ++++++------ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/unit-testing.yml b/.github/workflows/unit-testing.yml index 01894c8..59c7a87 100644 --- a/.github/workflows/unit-testing.yml +++ b/.github/workflows/unit-testing.yml @@ -4,6 +4,7 @@ name: Unit Testing on: pull_request: paths: + - 'env/**' - 'utils/**' - 'go.*' - '.github/workflows/unit-testing.yml' diff --git a/README.md b/README.md index 5406a28..d89d4f5 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Matter Snap Testing +[![Go Reference](https://pkg.go.dev/badge/github.com/canonical/matter-snap-testing.svg)](https://pkg.go.dev/github.com/canonical/matter-snap-testing) + Utility package for testing Matter snaps in Go. Test the testing utils: diff --git a/env/env.go b/env/env.go index 14f9d69..e02af92 100644 --- a/env/env.go +++ b/env/env.go @@ -8,14 +8,14 @@ import ( // Environment variables, used to override defaults const ( // Channel/Revision of the service snap (has default) - envSnapChannel = "SNAP_CHANNEL" + EnvSnapChannel = "SNAP_CHANNEL" // Path to snap instead, used for testing a local snap instead of // downloading from the store - envSnapPath = "SNAP_PATH" + EnvSnapPath = "SNAP_PATH" // Toggle the teardown operations during tests (has default) - envTeardown = "TEARDOWN" + EnvTeardown = "TEARDOWN" ) var ( @@ -47,15 +47,15 @@ func init() { // Read environment variables and perform type conversion/casting func loadEnvVars() { - if v := os.Getenv(envSnapChannel); v != "" { + if v := os.Getenv(EnvSnapChannel); v != "" { snapChannel = v } - if v := os.Getenv(envSnapPath); v != "" { + if v := os.Getenv(EnvSnapPath); v != "" { snapPath = v } - if v := os.Getenv(envTeardown); v != "" { + if v := os.Getenv(EnvTeardown); v != "" { var err error teardown, err = strconv.ParseBool(v) if err != nil { From d04c48d84dd3bf3c9ec10a0e3afc4c356ed34dde Mon Sep 17 00:00:00 2001 From: Lincoln Wallace Date: Mon, 29 Apr 2024 13:47:05 -0300 Subject: [PATCH 3/3] feat: print log before failure of WaitForLogMessage Signed-off-by: Lincoln Wallace --- go.sum | 4 ---- utils/config.go | 9 +++++++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/go.sum b/go.sum index c689bee..c75d976 100644 --- a/go.sum +++ b/go.sum @@ -7,10 +7,6 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= -github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/utils/config.go b/utils/config.go index af0284f..0657528 100644 --- a/utils/config.go +++ b/utils/config.go @@ -1,6 +1,7 @@ package utils import ( + "fmt" "strings" "testing" "time" @@ -9,7 +10,7 @@ import ( ) type Config struct { - TestAutoStart bool + TestAutoStart bool } func TestConfig(t *testing.T, snapName string, conf Config) { @@ -65,5 +66,9 @@ func WaitForLogMessage(t *testing.T, snap, expectedLog string, since time.Time) } } - t.Fatalf("Time out: reached max %d retries.", maxRetry) + t.Logf("Time out: reached max %d retries.", maxRetry) + stdout, _, _ := Exec(t, + fmt.Sprintf("sudo journalctl --lines=20 --no-pager --unit=snap.\"%s\" --priority=notice", snap)) + t.Log(stdout) + t.FailNow() }