Skip to content

Commit

Permalink
Refactor test utils and suites (#8)
Browse files Browse the repository at this point in the history
* Move utils package to top

* Move Chip Tool tests to https://github.com/canonical/chip-tool-snap

* Remove obsolete code and doc

* Update unit testing triggers
  • Loading branch information
farshidtz authored Jan 29, 2024
1 parent 0f3c7fc commit e27c6bf
Show file tree
Hide file tree
Showing 23 changed files with 11 additions and 567 deletions.
38 changes: 0 additions & 38 deletions .github/workflows/config-provider-testing.yml

This file was deleted.

117 changes: 0 additions & 117 deletions .github/workflows/snap-testing.yml

This file was deleted.

9 changes: 5 additions & 4 deletions .github/workflows/unit-testing.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# This workflow performs unit testing on utility packages
# This workflow performs unit testing on the utility package
name: Unit Testing

on:
pull_request:
branches: [ main ]
paths:
- 'test/utils/**'
- 'utils/**'
- '.github/unit-testing.yml'
- 'go.*'
# manual trigger
workflow_dispatch:

Expand All @@ -20,4 +21,4 @@ jobs:
with:
go-version: 1.*

- run: go test ./test/utils -count=100
- run: go test ./utils -count=100
16 changes: 0 additions & 16 deletions .github/workflows/versioning.yml

This file was deleted.

2 changes: 0 additions & 2 deletions .gitignore

This file was deleted.

89 changes: 4 additions & 85 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,89 +1,8 @@
# Matter Snap Tests (WIP)
Test scripts, Github actions, and workflows for the [Matter](https://github.com/project-chip/connectedhomeip/tree/master) snaps.
# Matter Snap Testing

The following diagram shows the Snap Testing workflow for building and testing snaps from upstream source code:
```mermaid
---
title: Snap Testing Workflow
---
flowchart LR
subgraph build [Build Job]
builda[[Build Action]] --> Source
--> Build[Build Snap]
--> Snap[/Artifact<br>Snap/]
end
subgraph test [Test Job]
Snap -.-> testa[[Test Action]]
--> gotests[Go Test Suites]
--> Logs[/Artifact<br>Logs/]
end
```

The Github Workflow configurations (triggers, jobs, etc) are maintained in respective upstream source codes.
The Github Actions and testing suites are maintained in this repository.

## Test locally
This section includes example command to run tests.

Useful `go test` flags are:
- `-v` is to enable verbose output
- `-failfast` makes the test stop after first failure
- `-timeout 60m` extends the timeout to longer than the default 10m
- `-count 1` is to avoid Go test caching for example when testing a rebuilt snap

#### Run one testing suite
```bash
go test -v -failfast -count 1 ./test/suites/chip-tool
```

#### Run all suites
```bash
go test -p 1 -timeout 60m -failfast -count 1 ./test/suites/...
```
Utility package for testing Matter snaps in Go.

#### Run one suite with env variables
The environment variables are defined in [test/utils/env.go](./test/utils/env.go)

#### Test the testing utils
```bash
go test ./test/utils -count=10
Test the testing utils:
```

## Test using Github Actions
This project includes two Github Actions that can be used in workflows to test snaps:
* [build](./build): Checkout code, build the snap, and upload snap as build artifact
* [test](./test): Download the snap from build artifacts (optional) and run smoke tests

A workflow that uses both the actions from `v2` branch may look as follows:

`.github/workflows/snap.yml`
```yaml
name: Snap Testing

on:
pull_request:
branches: [ main ]
# allow manual trigger
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Build and upload snap
id: build
uses: canonical/matter-snap-testing/build@v2
outputs:
snap: ${{steps.build.outputs.snap}}

test:
needs: build
runs-on: ubuntu-latest
steps:
- name: Download and test snap
uses: canonical/matter-snap-testing/test@v2
with:
name: device-mqtt
snap: ${{needs.build.outputs.snap}}
go test ./utils -count=100
```
42 changes: 0 additions & 42 deletions build/action.yml

This file was deleted.

4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module matter-snap-testing
module github.com/canonical/matter-snap-testing

go 1.17
go 1.21.6

require github.com/stretchr/testify v1.8.3

Expand Down
7 changes: 0 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
Expand All @@ -8,16 +7,10 @@ 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/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
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=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading

0 comments on commit e27c6bf

Please sign in to comment.