From f7c127fca6199f67eb113d44bded417fa1ccfc4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Borov=C4=8Danin?= Date: Tue, 15 Oct 2024 10:01:12 +0200 Subject: [PATCH] NOISSUE - Fix CI tests (#31) Signed-off-by: Dusan Borovcanin --- .codecov.yml | 7 +++++++ .github/workflows/tests.yml | 6 ++++-- .golangci.yml | 4 +--- README.md | 5 ++++- tools/e2e/e2e.go | 18 +++++++++--------- twins/mongodb/twins_test.go | 2 +- 6 files changed, 26 insertions(+), 16 deletions(-) create mode 100644 .codecov.yml diff --git a/.codecov.yml b/.codecov.yml new file mode 100644 index 0000000..5868fb1 --- /dev/null +++ b/.codecov.yml @@ -0,0 +1,7 @@ +# Copyright (c) Abstract Machines +# SPDX-License-Identifier: Apache-2.0 + +# CoAP is temporarily ignored since we don't have tests for it yet. +coverage: + ignore: + - "cmd/*" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5f9b28c..da22ba5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -116,8 +116,10 @@ jobs: run: | go test --race -v -count=1 -coverprofile=coverage/twins.out ./twins/... + - name: Upload coverage + uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV }} - directory: ./coverage/ - name: codecov-umbrella + files: ./coverage/*.out + codecov_yml_path: .codecov.yml verbose: true diff --git a/.golangci.yml b/.golangci.yml index 89ad8f9..d9fc7e5 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -28,7 +28,6 @@ linters-settings: alias: repoerr - pkg: github.com/absmach/magistrala/pkg/sdk/mocks alias: sdkmocks - gocritic: enabled-checks: - importShadow @@ -84,8 +83,7 @@ linters: - dogsled - errchkjson - errname - - execinquery - - exportloopref + - copyloopvar - ginkgolinter - gocheckcompilerdirectives - gofumpt diff --git a/README.md b/README.md index 91fa8a3..7de8de6 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ -# contrib +# Magistrala Contrib reository + +[![codecov](https://codecov.io/gh/absmach/mg-contrib/graph/badge.svg?token=0OD8Qw0Mxd)](https://codecov.io/gh/absmach/mg-contrib) + Extra bits that didn't make it into the main Magistrala repository diff --git a/tools/e2e/e2e.go b/tools/e2e/e2e.go index e72c125..9d8f15c 100644 --- a/tools/e2e/e2e.go +++ b/tools/e2e/e2e.go @@ -250,19 +250,19 @@ func createThings(s sdk.SDK, conf Config, token string) ([]sdk.Thing, error) { for i := 0; i < batches; i++ { ths, err := createThingsInBatch(s, conf, token, batchSize) if err != nil { - return []sdk.Thing{}, fmt.Errorf("Failed to create the things: %w", err) + return []sdk.Thing{}, fmt.Errorf("failed to create the things: %w", err) } things = append(things, ths...) } ths, err := createThingsInBatch(s, conf, token, conf.Num%uint64(batchSize)) if err != nil { - return []sdk.Thing{}, fmt.Errorf("Failed to create the things: %w", err) + return []sdk.Thing{}, fmt.Errorf("failed to create the things: %w", err) } things = append(things, ths...) } else { ths, err := createThingsInBatch(s, conf, token, conf.Num) if err != nil { - return []sdk.Thing{}, fmt.Errorf("Failed to create the things: %w", err) + return []sdk.Thing{}, fmt.Errorf("failed to create the things: %w", err) } things = append(things, ths...) } @@ -295,19 +295,19 @@ func createChannels(s sdk.SDK, conf Config, token string) ([]sdk.Channel, error) for i := 0; i < batches; i++ { chs, err := createChannelsInBatch(s, conf, token, batchSize) if err != nil { - return []sdk.Channel{}, fmt.Errorf("Failed to create the channels: %w", err) + return []sdk.Channel{}, fmt.Errorf("failed to create the channels: %w", err) } channels = append(channels, chs...) } chs, err := createChannelsInBatch(s, conf, token, conf.Num%uint64(batchSize)) if err != nil { - return []sdk.Channel{}, fmt.Errorf("Failed to create the channels: %w", err) + return []sdk.Channel{}, fmt.Errorf("failed to create the channels: %w", err) } channels = append(channels, chs...) } else { chs, err := createChannelsInBatch(s, conf, token, conf.Num) if err != nil { - return []sdk.Channel{}, fmt.Errorf("Failed to create the channels: %w", err) + return []sdk.Channel{}, fmt.Errorf("failed to create the channels: %w", err) } channels = append(channels, chs...) } @@ -572,7 +572,7 @@ func messaging(s sdk.SDK, conf Config, token string, things []sdk.Thing, channel func sendHTTPMessage(s sdk.SDK, msg string, thing sdk.Thing, chanID string) error { if err := s.SendMessage(chanID, msg, thing.Credentials.Secret); err != nil { - return fmt.Errorf("HTTP failed to send message from thing %s to channel %s: %w", thing.ID, chanID, err) + return fmt.Errorf("failed to send HTTP message from thing %s to channel %s: %w", thing.ID, chanID, err) } return nil @@ -581,7 +581,7 @@ func sendHTTPMessage(s sdk.SDK, msg string, thing sdk.Thing, chanID string) erro func sendCoAPMessage(msg string, thing sdk.Thing, chanID string) error { cmd := exec.Command("coap-cli", "post", fmt.Sprintf("channels/%s/messages", chanID), "--auth", thing.Credentials.Secret, "-d", msg) if _, err := cmd.CombinedOutput(); err != nil { - return fmt.Errorf("CoAP failed to send message from thing %s to channel %s: %w", thing.ID, chanID, err) + return fmt.Errorf("failed to send CoAP message from thing %s to channel %s: %w", thing.ID, chanID, err) } return nil @@ -590,7 +590,7 @@ func sendCoAPMessage(msg string, thing sdk.Thing, chanID string) error { func sendMQTTMessage(msg string, thing sdk.Thing, chanID string) error { cmd := exec.Command("mosquitto_pub", "--id-prefix", "magistrala", "-u", thing.ID, "-P", thing.Credentials.Secret, "-t", fmt.Sprintf("channels/%s/messages", chanID), "-h", "localhost", "-m", msg) if _, err := cmd.CombinedOutput(); err != nil { - return fmt.Errorf("MQTT failed to send message from thing %s to channel %s: %w", thing.ID, chanID, err) + return fmt.Errorf("failed to send MQTT message from thing %s to channel %s: %w", thing.ID, chanID, err) } return nil diff --git a/twins/mongodb/twins_test.go b/twins/mongodb/twins_test.go index fbbbe90..ea39bcc 100644 --- a/twins/mongodb/twins_test.go +++ b/twins/mongodb/twins_test.go @@ -40,7 +40,7 @@ var ( invalidName = strings.Repeat("m", maxNameSize+1) ) -func Testtwinsave(t *testing.T) { +func TestTwinSave(t *testing.T) { client, err := mongo.Connect(context.Background(), options.Client().ApplyURI(addr)) require.Nil(t, err, fmt.Sprintf("Creating new MongoDB client expected to succeed: %s.\n", err))