Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: print jornalctl log before failure of WaitForLogMessage #29

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/unit-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ name: Unit Testing
on:
pull_request:
paths:
- 'env/**'
- 'utils/**'
- 'go.*'
- '.github/workflows/unit-testing.yml'
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
12 changes: 6 additions & 6 deletions env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/canonical/matter-snap-testing

go 1.22.1

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
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ 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=
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=
Expand Down
9 changes: 7 additions & 2 deletions utils/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package utils

import (
"fmt"
"strings"
"testing"
"time"
Expand All @@ -9,7 +10,7 @@ import (
)

type Config struct {
TestAutoStart bool
TestAutoStart bool
}

func TestConfig(t *testing.T, snapName string, conf Config) {
Expand Down Expand Up @@ -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()
}