From 893de7293b4406cb10d9ce0232fb26b725f5916f Mon Sep 17 00:00:00 2001 From: Dario Freddi Date: Thu, 10 Feb 2022 10:33:42 +0100 Subject: [PATCH 1/2] Fix Errorf invocations upon failure Signed-off-by: Dario Freddi --- device/protocol_mqtt_v1.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/device/protocol_mqtt_v1.go b/device/protocol_mqtt_v1.go index 00d3e1c..c7a995c 100644 --- a/device/protocol_mqtt_v1.go +++ b/device/protocol_mqtt_v1.go @@ -23,8 +23,8 @@ import ( "strings" "time" - mqtt "github.com/ispirata/paho.mqtt.golang" "github.com/astarte-platform/astarte-go/interfaces" + mqtt "github.com/ispirata/paho.mqtt.golang" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/primitive" ) @@ -325,7 +325,7 @@ func (d *Device) SetProperty(interfaceName, path string, value interface{}) erro iface, ok := d.interfaces[interfaceName] if ok { if iface.Type != interfaces.PropertiesType { - return fmt.Errorf("SetProperty can be used only on Property Interfaces", interfaceName) + return fmt.Errorf("SetProperty can be used only on Property Interfaces, used on %s instead", interfaceName) } // Validate the message if err := interfaces.ValidateIndividualMessage(iface, path, value); err != nil { @@ -354,7 +354,7 @@ func (d *Device) UnsetProperty(interfaceName, path string) error { iface, ok := d.interfaces[interfaceName] if ok { if iface.Type != interfaces.PropertiesType { - return fmt.Errorf("UnsetProperty can be used only on Property Interfaces", interfaceName) + return fmt.Errorf("UnsetProperty can be used only on Property Interfaces, used on %s instead", interfaceName) } // Validate the path and whether it can allow unset mapping, err := interfaces.InterfaceMappingFromPath(iface, path) From 5445e8e828f971c6176c8a07d94a0cda790131e2 Mon Sep 17 00:00:00 2001 From: Dario Freddi Date: Thu, 10 Feb 2022 10:34:20 +0100 Subject: [PATCH 2/2] test: Fix coverage report and testing command This further abstracts the test invocation making it so that it is no longer required to invoke it from the e2e_tests directory. Signed-off-by: Dario Freddi --- .github/workflows/e2e-test-workflow.yaml | 10 +++++----- e2e_tests/e2e_test.go | 16 +++++++--------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/.github/workflows/e2e-test-workflow.yaml b/.github/workflows/e2e-test-workflow.yaml index cc4a2e4..a8b03ea 100644 --- a/.github/workflows/e2e-test-workflow.yaml +++ b/.github/workflows/e2e-test-workflow.yaml @@ -9,7 +9,7 @@ on: jobs: e2e-test: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - name: Checkout sources uses: actions/checkout@v2 @@ -24,12 +24,13 @@ jobs: run: | DEVICE_ID=$(astartectl utils device-id generate-random) echo "E2E_DEVICE_ID=$DEVICE_ID" >> $GITHUB_ENV - CREDENTIALS_SECRET=$(astartectl pairing agent register --compact-output "$DEVICE_ID") + CREDENTIALS_SECRET=$(astartectl pairing agent register --compact-output -- "$DEVICE_ID") echo "E2E_CREDENTIALS_SECRET=$CREDENTIALS_SECRET" >> $GITHUB_ENV JWT=$(astartectl utils gen-jwt all-realm-apis) echo "E2E_JWT=$JWT" >> $GITHUB_ENV echo "E2E_REALM=test" >> $GITHUB_ENV echo "E2E_ASTARTE_URL=https://api.autotest.astarte-platform.org" >> $GITHUB_ENV + echo "E2E_INTERFACES_DIR=$GITHUB_WORKSPACE/e2e_tests/test/interfaces" >> $GITHUB_ENV - name: Setup go uses: actions/setup-go@v2 with: @@ -42,8 +43,7 @@ jobs: echo $E2E_JWT echo $E2E_REALM echo $E2E_ASTARTE_URL - go test -v -timeout 20m -coverprofile=coverage.txt -covermode=atomic - working-directory: ./e2e_tests - shell: bash + echo $E2E_INTERFACES_DIR + go test -v -race -timeout 20m -coverprofile=coverage.txt -covermode=atomic -coverpkg=./... ./... - name: Upload coverage report uses: codecov/codecov-action@v2 diff --git a/e2e_tests/e2e_test.go b/e2e_tests/e2e_test.go index ee95b7c..2ac4a4a 100644 --- a/e2e_tests/e2e_test.go +++ b/e2e_tests/e2e_test.go @@ -71,8 +71,8 @@ func (suite *EndToEndSuite) SetupSuite() { suite.realm = os.Getenv("E2E_REALM") suite.deviceID = os.Getenv("E2E_DEVICE_ID") suite.credentialsSecret = os.Getenv("E2E_CREDENTIALS_SECRET") - suite.devicePersistencyDir = "test/persistency" - suite.interfaceDirectory = "test/interfaces" + suite.devicePersistencyDir, _ = ioutil.TempDir("", "astarte2e") + suite.interfaceDirectory = os.Getenv("E2E_INTERFACES_DIR") suite.setupAPIClient() suite.setupDevice() @@ -81,6 +81,7 @@ func (suite *EndToEndSuite) SetupSuite() { func (suite *EndToEndSuite) TearDownSuite() { suite.d.Disconnect(make(chan<- error)) time.Sleep(3 * time.Second) + os.RemoveAll(suite.devicePersistencyDir) } func (suite *EndToEndSuite) TestDatastreamIndividualDevice() { @@ -255,17 +256,14 @@ func toDate(value interface{}) time.Time { func loadInterfaces(d *device.Device, interfaceDirectory string) error { files, _ := ioutil.ReadDir(interfaceDirectory) + var err error for _, f := range files { fmt.Println(f.Name()) - byteValue, err := ioutil.ReadFile(interfaceDirectory + "/" + f.Name()) - if err != nil { + var iface interfaces.AstarteInterface + if iface, err = interfaces.ParseInterfaceFromFile(interfaceDirectory + "/" + f.Name()); err != nil { return err } - iface := interfaces.AstarteInterface{} - if iface, err = interfaces.ParseInterface(byteValue); err != nil { - return err - } - if err := d.AddInterface(iface); err != nil { + if err = d.AddInterface(iface); err != nil { return err } }