Skip to content

Commit

Permalink
Merge pull request #38 from drf/fix-coverage
Browse files Browse the repository at this point in the history
Fix coverage and tests
  • Loading branch information
bettio authored Feb 11, 2022
2 parents a477b95 + 5445e8e commit 6d09424
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/e2e-test-workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
6 changes: 3 additions & 3 deletions device/protocol_mqtt_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 7 additions & 9 deletions e2e_tests/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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() {
Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit 6d09424

Please sign in to comment.