farshidtz / edgex-snap-testing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EdgeX Snap Tests

Test scripts, Github actions, and workflows for the EdgeX Foundry snaps.

graph LR

    subgraph tests [Edgex Snap Testing Project]
        
        builda[[Build Action]] -- 1b --> snapcraft[Snap Build]
        testa[[Test Action]] -- 2c --> gotests[Test Suites]
        
        gotests -- >>PR --> localtestj[Local Test Job]
        localtestj -- 3 --> testa
        
    end

    subgraph source [Source Project]
        Source -- >>PR<br/>>>Push<br/>>>Manual Trigger --> buildj
        
        subgraph snap [Snap Testing Workflow]
            buildj -- 2a --> testj
            buildj[Build Job] -- 1a --> builda
            snapcraft -- 1c --> artifacts[Artifact Snap]
            artifacts -. 1d .-> buildj
            testj[Test Job] -- 2b --> testa
        end
    end
Loading

Test locally

Test one, e.g.:

go test -p 1 ./test/suites/device-mqtt

The -p 1 is set to force sequential run and avoid snapd and logical error.

Set -v for verbose output.

To test all:

go test -p 1 ./test/suites/...

Test one with variables, e.g.:

FULL_CONFIG_TEST=true go test -p 1 ./test/suites/device-mqtt
LOCAL_SNAP="edgex-device-mqtt_2.0.1-dev.15_amd64.snap" go test -p 1 ./test/suites/device-mqtt

Test the testing utils:

go test ./test/utils -count=10

Override behavior

Use environment variables, as defined in test/utils/env.go

Test using Github Actions

This project includes two Github Actions that can be used in workflows to test snaps:

  • build: Checkout code, build the snap, and upload snap as build artifact
  • 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

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/edgex-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/edgex-snap-testing/test@v2
        with:
          name: device-mqtt
          snap: ${{needs.build.outputs.snap}}

About


Languages

Language:Go 100.0%