diff --git a/.github/workflows/check-generated-files.yml b/.github/workflows/check-generated-files.yml index 2bcec3075..bc33c4267 100644 --- a/.github/workflows/check-generated-files.yml +++ b/.github/workflows/check-generated-files.yml @@ -31,7 +31,7 @@ jobs: base: main filters: | proto: - # - ".github/workflows/check-generated-files.yml" + - ".github/workflows/check-generated-files.yml" - "auth.proto" - "auth/*.pb.go" - "pkg/messaging/message.proto" diff --git a/.github/workflows/swagger-ui.yaml b/.github/workflows/swagger-ui.yaml index e56121e0b..5e380375e 100644 --- a/.github/workflows/swagger-ui.yaml +++ b/.github/workflows/swagger-ui.yaml @@ -6,21 +6,23 @@ name: Deploy GitHub Pages on: push: branches: - - master + - main jobs: swagger-ui: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v2 + - name: Checkout code + uses: actions/checkout@v4 + - name: Swagger UI action id: swagger-ui-action uses: blokovi/swagger-ui-action@main with: - dir: './api/openapi' - pattern: '*.yml' - debug: 'true' + dir: "./api/openapi" + pattern: "*.yml" + debug: "true" + - name: Deploy to GitHub Pages uses: peaceiris/actions-gh-pages@v3 with: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9b5a115d6..2cb60d784 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -58,26 +58,44 @@ jobs: uses: dorny/paths-filter@v2 id: changes with: + base: main filters: | + workflow: + - ".github/workflows/tests.yml" + + auth: + - "auth/**" + - "cmd/auth/**" + - "auth.proto" + - "auth.pb.go" + - "auth_grpc.pb.go" + - "pkg/ulid/**" + - "pkg/uuid/**" + bootstrap: - "bootstrap/**" - "cmd/bootstrap/**" - - "things/policies/postgres/polices.go" - - "things/policies/api/grpc/client.go" + - "auth.pb.go" + - "auth_grpc.pb.go" + - "auth/**" + - "pkg/sdk/**" + - "pkg/events/**" certs: - "certs/**" - "cmd/certs/**" - - "things/api/grpc/**" - - "auth/service.go" - - "auth/api/grpc/client.go" + - "auth.pb.go" + - "auth_grpc.pb.go" + - "auth/**" + - "pkg/sdk/**" coap: - "coap/**" - "cmd/coap/**" - - "things/api/grpc/**" - - "auth/service.go" - - "auth/api/grpc/client.go" + - "auth.pb.go" + - "auth_grpc.pb.go" + - "things/**" + - "pkg/messaging/**" consumers: - "consumers/**" @@ -88,16 +106,21 @@ jobs: - "cmd/timescale-writer/**" - "cmd/smpp-notifier/**" - "cmd/smtp-notifier/**" - - "things/api/grpc/**" - - "auth/service.go" - - "auth/api/grpc/client.go" + - "auth.pb.go" + - "auth_grpc.pb.go" + - "auth/**" + - "pkg/ulid/**" + - "pkg/uuid/**" + - "pkg/messaging/**" http: - "http/**" - "cmd/http/**" - - "things/api/grpc/**" - - "auth/service.go" - - "auth/api/grpc/client.go" + - "auth.pb.go" + - "auth_grpc.pb.go" + - "things/**" + - "pkg/messaging/**" + - "logger/**" internal: - "internal/**" @@ -105,13 +128,15 @@ jobs: invitations: - "invitations/**" - "cmd/invitations/**" - - "auth.proto" - "auth.pb.go" - "auth_grpc.pb.go" + - "auth/**" + - "pkg/sdk/**" lora: - "lora/**" - "cmd/lora/**" + - "pkg/messaging/**" logger: - "logger/**" @@ -119,16 +144,17 @@ jobs: mqtt: - "mqtt/**" - "cmd/mqtt/**" - - "things/api/grpc/**" - - "auth/service.go" - - "auth/api/grpc/client.go" + - "auth.pb.go" + - "auth_grpc.pb.go" + - "things/**" + - "pkg/messaging/**" + - "logger/**" + - "pkg/events/**" opcua: - "opcua/**" - "cmd/opcua/**" - - "things/api/grpc/**" - - "auth/service.go" - - "auth/api/grpc/client.go" + - "logger/**" pkg-clients: - "pkg/clients/**" @@ -145,6 +171,19 @@ jobs: pkg-sdk: - "pkg/sdk/**" + - "pkg/clients/**" + - "pkg/errors/**" + - "auth/**" + - "bootstrap/**" + - "certs/**" + - "consumers/**" + - "http/**" + - "invitations/**" + - "provision/**" + - "readers/**" + - "things/**" + - "twins/**" + - "users/**" pkg-transformers: - "pkg/transformers/**" @@ -158,6 +197,8 @@ jobs: provision: - "provision/**" - "cmd/provision/**" + - "logger/**" + - "pkg/sdk/**" readers: - "readers/**" @@ -166,162 +207,183 @@ jobs: - "cmd/mongodb-reader/**" - "cmd/postgres-reader/**" - "cmd/timescale-reader/**" - - "things/api/grpc/**" - - "auth/service.go" - - "auth/api/grpc/client.go" + - "auth.pb.go" + - "auth_grpc.pb.go" + - "things/**" + - "auth/**" things: - "things/**" - "cmd/things/**" - - "auth/service.go" - - "auth/api/grpc/client.go" + - "auth.pb.go" + - "auth_grpc.pb.go" + - "auth/**" + - "pkg/clients/**" + - "pkg/ulid/**" + - "pkg/uuid/**" + - "pkg/events/**" twins: - "twins/**" - "cmd/twins/**" - - "things/api/grpc/**" - - "auth/service.go" - - "auth/api/grpc/client.go" + - "auth.pb.go" + - "auth_grpc.pb.go" + - "auth/**" + - "pkg/messaging/**" + - "pkg/ulid/**" + - "pkg/uuid/**" + - "logger/**" users: - "users/**" - "cmd/users/**" - - "auth/service.go" - - "auth/api/grpc/client.go" + - "auth.pb.go" + - "auth_grpc.pb.go" + - "auth/**" + - "pkg/clients/**" + - "pkg/ulid/**" + - "pkg/uuid/**" + - "pkg/events/**" ws: - "ws/**" - "cmd/ws/**" - - "things/api/grpc/**" - - "auth/service.go" - - "auth/api/grpc/client.go" + - "auth.pb.go" + - "auth_grpc.pb.go" + - "things/**" + - "pkg/messaging/**" - name: Create coverage directory run: | mkdir coverage + - name: Run auth tests + if: steps.changes.outputs.auth == 'true' || steps.changes.outputs.workflow == 'true' + run: | + go test --race -v -count=1 -coverprofile=coverage/auth.out ./auth/... + - name: Run bootstrap tests - if: steps.changes.outputs.bootstrap == 'true' + if: steps.changes.outputs.bootstrap == 'true' || steps.changes.outputs.workflow == 'true' run: | go test --race -v -count=1 -coverprofile=coverage/bootstrap.out ./bootstrap/... - name: Run certs tests - if: steps.changes.outputs.certs == 'true' + if: steps.changes.outputs.certs == 'true' || steps.changes.outputs.workflow == 'true' run: | go test --race -v -count=1 -coverprofile=coverage/certs.out ./certs/... - name: Run CoAP tests - if: steps.changes.outputs.coap == 'true' + if: steps.changes.outputs.coap == 'true' || steps.changes.outputs.workflow == 'true' run: | go test --race -v -count=1 -coverprofile=coverage/coap.out ./coap/... - name: Run consumers tests - if: steps.changes.outputs.consumers == 'true' + if: steps.changes.outputs.consumers == 'true' || steps.changes.outputs.workflow == 'true' run: | go test --race -v -count=1 -coverprofile=coverage/consumers.out ./consumers/... - name: Run HTTP tests - if: steps.changes.outputs.http == 'true' + if: steps.changes.outputs.http == 'true' || steps.changes.outputs.workflow == 'true' run: | go test --race -v -count=1 -coverprofile=coverage/http.out ./http/... - name: Run internal tests - if: steps.changes.outputs.internal == 'true' + if: steps.changes.outputs.internal == 'true' || steps.changes.outputs.workflow == 'true' run: | go test --race -v -count=1 -coverprofile=coverage/internal.out ./internal/... - name: Run invitations tests - if: steps.changes.outputs.invitations == 'true' + if: steps.changes.outputs.invitations == 'true' || steps.changes.outputs.workflow == 'true' run: | go test --race -v -count=1 -coverprofile=coverage/invitations.out ./invitations/... - name: Run logger tests - if: steps.changes.outputs.logger == 'true' + if: steps.changes.outputs.logger == 'true' || steps.changes.outputs.workflow == 'true' run: | go test --race -v -count=1 -coverprofile=coverage/logger.out ./logger/... - name: Run LoRa tests - if: steps.changes.outputs.lora == 'true' + if: steps.changes.outputs.lora == 'true' || steps.changes.outputs.workflow == 'true' run: | go test --race -v -count=1 -coverprofile=coverage/lora.out ./lora/... - name: Run MQTT tests - if: steps.changes.outputs.mqtt == 'true' + if: steps.changes.outputs.mqtt == 'true' || steps.changes.outputs.workflow == 'true' run: | go test --race -v -count=1 -coverprofile=coverage/mqtt.out ./mqtt/... - name: Run OPC-UA tests - if: steps.changes.outputs.opcua == 'true' + if: steps.changes.outputs.opcua == 'true' || steps.changes.outputs.workflow == 'true' run: | go test --race -v -count=1 -coverprofile=coverage/opcua.out ./opcua/... - name: Run pkg clients tests - if: steps.changes.outputs.pkg-clients == 'true' + if: steps.changes.outputs.pkg-clients == 'true' || steps.changes.outputs.workflow == 'true' run: | go test --race -v -count=1 -coverprofile=coverage/pkg-clients.out ./pkg/clients/... - name: Run pkg errors tests - if: steps.changes.outputs.pkg-errors == 'true' + if: steps.changes.outputs.pkg-errors == 'true' || steps.changes.outputs.workflow == 'true' run: | go test --race -v -count=1 -coverprofile=coverage/pkg-errors.out ./pkg/errors/... - name: Run pkg events tests - if: steps.changes.outputs.pkg-events == 'true' + if: steps.changes.outputs.pkg-events == 'true' || steps.changes.outputs.workflow == 'true' run: | go test --race -v -count=1 -coverprofile=coverage/pkg-events.out ./pkg/events/... - name: Run pkg messaging tests - if: steps.changes.outputs.pkg-messaging == 'true' + if: steps.changes.outputs.pkg-messaging == 'true' || steps.changes.outputs.workflow == 'true' run: | go test --race -v -count=1 -coverprofile=coverage/pkg-messaging.out ./pkg/messaging/... - name: Run pkg sdk tests - if: steps.changes.outputs.pkg-sdk == 'true' + if: steps.changes.outputs.pkg-sdk == 'true' || steps.changes.outputs.workflow == 'true' run: | go test --race -v -count=1 -coverprofile=coverage/pkg-sdk.out ./pkg/sdk/... - name: Run pkg transformers tests - if: steps.changes.outputs.pkg-transformers == 'true' + if: steps.changes.outputs.pkg-transformers == 'true' || steps.changes.outputs.workflow == 'true' run: | go test --race -v -count=1 -coverprofile=coverage/pkg-transformers.out ./pkg/transformers/... - name: Run pkg ulid tests - if: steps.changes.outputs.pkg-ulid == 'true' + if: steps.changes.outputs.pkg-ulid == 'true' || steps.changes.outputs.workflow == 'true' run: | go test --race -v -count=1 -coverprofile=coverage/pkg-ulid.out ./pkg/ulid/... - name: Run pkg uuid tests - if: steps.changes.outputs.pkg-uuid == 'true' + if: steps.changes.outputs.pkg-uuid == 'true' || steps.changes.outputs.workflow == 'true' run: | go test --race -v -count=1 -coverprofile=coverage/pkg-uuid.out ./pkg/uuid/... - name: Run provision tests - if: steps.changes.outputs.provision == 'true' + if: steps.changes.outputs.provision == 'true' || steps.changes.outputs.workflow == 'true' run: | go test --race -v -count=1 -coverprofile=coverage/provision.out ./provision/... - name: Run readers tests - if: steps.changes.outputs.readers == 'true' + if: steps.changes.outputs.readers == 'true' || steps.changes.outputs.workflow == 'true' run: | go test --race -v -count=1 -coverprofile=coverage/readers.out ./readers/... - name: Run things tests - if: steps.changes.outputs.things == 'true' + if: steps.changes.outputs.things == 'true' || steps.changes.outputs.workflow == 'true' run: | go test --race -v -count=1 -coverprofile=coverage/things.out ./things/... - name: Run twins tests - if: steps.changes.outputs.twins == 'true' + if: steps.changes.outputs.twins == 'true' || steps.changes.outputs.workflow == 'true' run: | go test --race -v -count=1 -coverprofile=coverage/twins.out ./twins/... - name: Run users tests - if: steps.changes.outputs.users == 'true' + if: steps.changes.outputs.users == 'true' || steps.changes.outputs.workflow == 'true' run: | go test --race -v -count=1 -coverprofile=coverage/users.out ./users/... - name: Run WebSocket tests - if: steps.changes.outputs.ws == 'true' + if: steps.changes.outputs.ws == 'true' || steps.changes.outputs.workflow == 'true' run: | go test --race -v -count=1 -coverprofile=coverage/ws.out ./ws/... diff --git a/pkg/sdk/go/things_test.go b/pkg/sdk/go/things_test.go index a31e1851f..77a3a1e49 100644 --- a/pkg/sdk/go/things_test.go +++ b/pkg/sdk/go/things_test.go @@ -188,7 +188,8 @@ func TestCreateThing(t *testing.T) { for _, tc := range cases { repoCall := auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(&magistrala.IdentityRes{Id: validID, DomainId: testsutil.GenerateUUID(t)}, nil) repoCall1 := auth.On("AddPolicies", mock.Anything, mock.Anything).Return(&magistrala.AddPoliciesRes{Authorized: true}, nil) - repoCall2 := cRepo.On("Save", mock.Anything, mock.Anything).Return(convertThings(tc.response), tc.repoErr) + repoCall2 := auth.On("Authorize", mock.Anything, mock.Anything).Return(&magistrala.AuthorizeRes{Authorized: true}, nil) + repoCall3 := cRepo.On("Save", mock.Anything, mock.Anything).Return(convertThings(tc.response), tc.repoErr) rThing, err := mgsdk.CreateThing(tc.client, tc.token) tc.response.ID = rThing.ID @@ -200,12 +201,13 @@ func TestCreateThing(t *testing.T) { assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected error %s, got %s", tc.desc, tc.err, err)) assert.Equal(t, tc.response, rThing, fmt.Sprintf("%s: expected %v got %v\n", tc.desc, tc.response, rThing)) if tc.err == nil { - ok := repoCall2.Parent.AssertCalled(t, "Save", mock.Anything, mock.Anything) + ok := repoCall3.Parent.AssertCalled(t, "Save", mock.Anything, mock.Anything) assert.True(t, ok, fmt.Sprintf("Save was not called on %s", tc.desc)) } repoCall.Unset() repoCall1.Unset() repoCall2.Unset() + repoCall3.Unset() } } @@ -274,9 +276,10 @@ func TestCreateThings(t *testing.T) { for _, tc := range cases { repoCall := auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(&magistrala.IdentityRes{Id: validID, DomainId: testsutil.GenerateUUID(t)}, nil) repoCall1 := auth.On("AddPolicies", mock.Anything, mock.Anything).Return(&magistrala.AddPoliciesRes{Authorized: true}, nil) - repoCall2 := cRepo.On("Save", mock.Anything, mock.Anything).Return(convertThings(tc.response...), tc.err) + repoCall2 := auth.On("Authorize", mock.Anything, mock.Anything).Return(&magistrala.AuthorizeRes{Authorized: true}, nil) + repoCall3 := cRepo.On("Save", mock.Anything, mock.Anything).Return(convertThings(tc.response...), tc.err) if len(tc.things) > 0 { - repoCall2 = cRepo.On("Save", mock.Anything, mock.Anything, mock.Anything).Return(convertThings(tc.response...), tc.err) + repoCall3 = cRepo.On("Save", mock.Anything, mock.Anything, mock.Anything).Return(convertThings(tc.response...), tc.err) } rThing, err := mgsdk.CreateThings(tc.things, tc.token) for i, t := range rThing { @@ -292,16 +295,17 @@ func TestCreateThings(t *testing.T) { if tc.err == nil { switch len(tc.things) { case 1: - ok := repoCall2.Parent.AssertCalled(t, "Save", mock.Anything, mock.Anything) + ok := repoCall3.Parent.AssertCalled(t, "Save", mock.Anything, mock.Anything) assert.True(t, ok, fmt.Sprintf("Save was not called on %s", tc.desc)) case 2: - ok := repoCall2.Parent.AssertCalled(t, "Save", mock.Anything, mock.Anything, mock.Anything) + ok := repoCall3.Parent.AssertCalled(t, "Save", mock.Anything, mock.Anything, mock.Anything) assert.True(t, ok, fmt.Sprintf("Save was not called on %s", tc.desc)) } } repoCall.Unset() repoCall1.Unset() repoCall2.Unset() + repoCall3.Unset() } }