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/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) 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 } }