2021-04-15 04:26:49 +08:00
|
|
|
// Copyright (c) Mainflux
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
package lora_test
|
|
|
|
|
|
|
|
import (
|
2023-04-12 23:30:01 +08:00
|
|
|
"context"
|
2021-04-15 04:26:49 +08:00
|
|
|
"encoding/base64"
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/mainflux/mainflux/lora"
|
|
|
|
"github.com/mainflux/mainflux/lora/mocks"
|
|
|
|
"github.com/mainflux/mainflux/pkg/errors"
|
|
|
|
"github.com/stretchr/testify/assert"
|
MF-1718 - Use static code analysis in CI (#1729)
* things, twins, and logger lint fixed
Signed-off-by: aryan <aryangodara03@gmail.com>
* all services updated, auth jwt not working, ineffectual assignment issue
Signed-off-by: aryan <aryangodara03@gmail.com>
* handle error from grpc server in endpointtest
Signed-off-by: aryan <aryangodara03@gmail.com>
* temp commit, auth/jwt needs to be resolved
Signed-off-by: aryan <aryangodara03@gmail.com>
* revert back to jwt v4 temporarily
Signed-off-by: aryan <aryangodara03@gmail.com>
* updated jwt tokenizer
Signed-off-by: aryan <aryangodara03@gmail.com>
* resolve EOF error for httptest requests
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix auth jwt, update to registeredclaims
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix ineffective assignment, auth/api/grpc endpoint failing
Signed-off-by: aryan <aryangodara03@gmail.com>
* temp commit, remove later
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix grpc server setup
Signed-off-by: aryan <aryangodara03@gmail.com>
* resolve golangci tests, remove debug statements
Signed-off-by: aryan <aryangodara03@gmail.com>
* update golangci version and modify linters used
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix failing tests
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix grpc server for setup tests
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix logging and errors inlined
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix remarks, update grpc setup_test
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix setup_test
Signed-off-by: aryan <aryangodara03@gmail.com>
* update setup_test grpc
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix data race
Signed-off-by: aryan <aryangodara03@gmail.com>
* update setup_test grpc
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix grpc setup down to single simple function
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix linting issues
Signed-off-by: aryan <aryangodara03@gmail.com>
* resolve pr comments
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix tests, handle returned errors, go mod tidy vendor
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix errors from new linters
Signed-off-by: aryan <aryangodara03@gmail.com>
---------
Signed-off-by: aryan <aryangodara03@gmail.com>
2023-04-22 23:14:35 +08:00
|
|
|
"github.com/stretchr/testify/require"
|
2021-04-15 04:26:49 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
thingID = "thingID-1"
|
|
|
|
chanID = "chanID-1"
|
|
|
|
devEUI = "devEUI-1"
|
|
|
|
appID = "appID-1"
|
|
|
|
thingID2 = "thingID-2"
|
|
|
|
chanID2 = "chanID-2"
|
|
|
|
devEUI2 = "devEUI-2"
|
|
|
|
appID2 = "appID-2"
|
|
|
|
msg = `[{"bn":"msg-base-name","n":"temperature","v": 17},{"n":"humidity","v": 56}]`
|
|
|
|
)
|
|
|
|
|
|
|
|
func newService() lora.Service {
|
|
|
|
pub := mocks.NewPublisher()
|
|
|
|
thingsRM := mocks.NewRouteMap()
|
|
|
|
channelsRM := mocks.NewRouteMap()
|
|
|
|
connsRM := mocks.NewRouteMap()
|
|
|
|
|
|
|
|
return lora.New(pub, thingsRM, channelsRM, connsRM)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPublish(t *testing.T) {
|
|
|
|
svc := newService()
|
|
|
|
|
2023-04-12 23:30:01 +08:00
|
|
|
err := svc.CreateChannel(context.Background(), chanID, appID)
|
MF-1718 - Use static code analysis in CI (#1729)
* things, twins, and logger lint fixed
Signed-off-by: aryan <aryangodara03@gmail.com>
* all services updated, auth jwt not working, ineffectual assignment issue
Signed-off-by: aryan <aryangodara03@gmail.com>
* handle error from grpc server in endpointtest
Signed-off-by: aryan <aryangodara03@gmail.com>
* temp commit, auth/jwt needs to be resolved
Signed-off-by: aryan <aryangodara03@gmail.com>
* revert back to jwt v4 temporarily
Signed-off-by: aryan <aryangodara03@gmail.com>
* updated jwt tokenizer
Signed-off-by: aryan <aryangodara03@gmail.com>
* resolve EOF error for httptest requests
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix auth jwt, update to registeredclaims
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix ineffective assignment, auth/api/grpc endpoint failing
Signed-off-by: aryan <aryangodara03@gmail.com>
* temp commit, remove later
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix grpc server setup
Signed-off-by: aryan <aryangodara03@gmail.com>
* resolve golangci tests, remove debug statements
Signed-off-by: aryan <aryangodara03@gmail.com>
* update golangci version and modify linters used
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix failing tests
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix grpc server for setup tests
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix logging and errors inlined
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix remarks, update grpc setup_test
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix setup_test
Signed-off-by: aryan <aryangodara03@gmail.com>
* update setup_test grpc
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix data race
Signed-off-by: aryan <aryangodara03@gmail.com>
* update setup_test grpc
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix grpc setup down to single simple function
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix linting issues
Signed-off-by: aryan <aryangodara03@gmail.com>
* resolve pr comments
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix tests, handle returned errors, go mod tidy vendor
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix errors from new linters
Signed-off-by: aryan <aryangodara03@gmail.com>
---------
Signed-off-by: aryan <aryangodara03@gmail.com>
2023-04-22 23:14:35 +08:00
|
|
|
require.Nil(t, err, fmt.Sprintf("unexpected error: %s\n", err))
|
2021-04-15 04:26:49 +08:00
|
|
|
|
2023-04-12 23:30:01 +08:00
|
|
|
err = svc.CreateThing(context.Background(), thingID, devEUI)
|
MF-1718 - Use static code analysis in CI (#1729)
* things, twins, and logger lint fixed
Signed-off-by: aryan <aryangodara03@gmail.com>
* all services updated, auth jwt not working, ineffectual assignment issue
Signed-off-by: aryan <aryangodara03@gmail.com>
* handle error from grpc server in endpointtest
Signed-off-by: aryan <aryangodara03@gmail.com>
* temp commit, auth/jwt needs to be resolved
Signed-off-by: aryan <aryangodara03@gmail.com>
* revert back to jwt v4 temporarily
Signed-off-by: aryan <aryangodara03@gmail.com>
* updated jwt tokenizer
Signed-off-by: aryan <aryangodara03@gmail.com>
* resolve EOF error for httptest requests
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix auth jwt, update to registeredclaims
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix ineffective assignment, auth/api/grpc endpoint failing
Signed-off-by: aryan <aryangodara03@gmail.com>
* temp commit, remove later
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix grpc server setup
Signed-off-by: aryan <aryangodara03@gmail.com>
* resolve golangci tests, remove debug statements
Signed-off-by: aryan <aryangodara03@gmail.com>
* update golangci version and modify linters used
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix failing tests
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix grpc server for setup tests
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix logging and errors inlined
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix remarks, update grpc setup_test
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix setup_test
Signed-off-by: aryan <aryangodara03@gmail.com>
* update setup_test grpc
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix data race
Signed-off-by: aryan <aryangodara03@gmail.com>
* update setup_test grpc
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix grpc setup down to single simple function
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix linting issues
Signed-off-by: aryan <aryangodara03@gmail.com>
* resolve pr comments
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix tests, handle returned errors, go mod tidy vendor
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix errors from new linters
Signed-off-by: aryan <aryangodara03@gmail.com>
---------
Signed-off-by: aryan <aryangodara03@gmail.com>
2023-04-22 23:14:35 +08:00
|
|
|
require.Nil(t, err, fmt.Sprintf("unexpected error: %s\n", err))
|
2021-04-15 04:26:49 +08:00
|
|
|
|
2023-04-12 23:30:01 +08:00
|
|
|
err = svc.ConnectThing(context.Background(), chanID, thingID)
|
MF-1718 - Use static code analysis in CI (#1729)
* things, twins, and logger lint fixed
Signed-off-by: aryan <aryangodara03@gmail.com>
* all services updated, auth jwt not working, ineffectual assignment issue
Signed-off-by: aryan <aryangodara03@gmail.com>
* handle error from grpc server in endpointtest
Signed-off-by: aryan <aryangodara03@gmail.com>
* temp commit, auth/jwt needs to be resolved
Signed-off-by: aryan <aryangodara03@gmail.com>
* revert back to jwt v4 temporarily
Signed-off-by: aryan <aryangodara03@gmail.com>
* updated jwt tokenizer
Signed-off-by: aryan <aryangodara03@gmail.com>
* resolve EOF error for httptest requests
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix auth jwt, update to registeredclaims
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix ineffective assignment, auth/api/grpc endpoint failing
Signed-off-by: aryan <aryangodara03@gmail.com>
* temp commit, remove later
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix grpc server setup
Signed-off-by: aryan <aryangodara03@gmail.com>
* resolve golangci tests, remove debug statements
Signed-off-by: aryan <aryangodara03@gmail.com>
* update golangci version and modify linters used
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix failing tests
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix grpc server for setup tests
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix logging and errors inlined
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix remarks, update grpc setup_test
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix setup_test
Signed-off-by: aryan <aryangodara03@gmail.com>
* update setup_test grpc
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix data race
Signed-off-by: aryan <aryangodara03@gmail.com>
* update setup_test grpc
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix grpc setup down to single simple function
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix linting issues
Signed-off-by: aryan <aryangodara03@gmail.com>
* resolve pr comments
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix tests, handle returned errors, go mod tidy vendor
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix errors from new linters
Signed-off-by: aryan <aryangodara03@gmail.com>
---------
Signed-off-by: aryan <aryangodara03@gmail.com>
2023-04-22 23:14:35 +08:00
|
|
|
require.Nil(t, err, fmt.Sprintf("unexpected error: %s\n", err))
|
2021-04-15 04:26:49 +08:00
|
|
|
|
2023-04-12 23:30:01 +08:00
|
|
|
err = svc.CreateChannel(context.Background(), chanID2, appID2)
|
MF-1718 - Use static code analysis in CI (#1729)
* things, twins, and logger lint fixed
Signed-off-by: aryan <aryangodara03@gmail.com>
* all services updated, auth jwt not working, ineffectual assignment issue
Signed-off-by: aryan <aryangodara03@gmail.com>
* handle error from grpc server in endpointtest
Signed-off-by: aryan <aryangodara03@gmail.com>
* temp commit, auth/jwt needs to be resolved
Signed-off-by: aryan <aryangodara03@gmail.com>
* revert back to jwt v4 temporarily
Signed-off-by: aryan <aryangodara03@gmail.com>
* updated jwt tokenizer
Signed-off-by: aryan <aryangodara03@gmail.com>
* resolve EOF error for httptest requests
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix auth jwt, update to registeredclaims
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix ineffective assignment, auth/api/grpc endpoint failing
Signed-off-by: aryan <aryangodara03@gmail.com>
* temp commit, remove later
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix grpc server setup
Signed-off-by: aryan <aryangodara03@gmail.com>
* resolve golangci tests, remove debug statements
Signed-off-by: aryan <aryangodara03@gmail.com>
* update golangci version and modify linters used
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix failing tests
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix grpc server for setup tests
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix logging and errors inlined
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix remarks, update grpc setup_test
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix setup_test
Signed-off-by: aryan <aryangodara03@gmail.com>
* update setup_test grpc
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix data race
Signed-off-by: aryan <aryangodara03@gmail.com>
* update setup_test grpc
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix grpc setup down to single simple function
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix linting issues
Signed-off-by: aryan <aryangodara03@gmail.com>
* resolve pr comments
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix tests, handle returned errors, go mod tidy vendor
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix errors from new linters
Signed-off-by: aryan <aryangodara03@gmail.com>
---------
Signed-off-by: aryan <aryangodara03@gmail.com>
2023-04-22 23:14:35 +08:00
|
|
|
require.Nil(t, err, fmt.Sprintf("unexpected error: %s\n", err))
|
2021-04-15 04:26:49 +08:00
|
|
|
|
2023-04-12 23:30:01 +08:00
|
|
|
err = svc.CreateThing(context.Background(), thingID2, devEUI2)
|
MF-1718 - Use static code analysis in CI (#1729)
* things, twins, and logger lint fixed
Signed-off-by: aryan <aryangodara03@gmail.com>
* all services updated, auth jwt not working, ineffectual assignment issue
Signed-off-by: aryan <aryangodara03@gmail.com>
* handle error from grpc server in endpointtest
Signed-off-by: aryan <aryangodara03@gmail.com>
* temp commit, auth/jwt needs to be resolved
Signed-off-by: aryan <aryangodara03@gmail.com>
* revert back to jwt v4 temporarily
Signed-off-by: aryan <aryangodara03@gmail.com>
* updated jwt tokenizer
Signed-off-by: aryan <aryangodara03@gmail.com>
* resolve EOF error for httptest requests
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix auth jwt, update to registeredclaims
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix ineffective assignment, auth/api/grpc endpoint failing
Signed-off-by: aryan <aryangodara03@gmail.com>
* temp commit, remove later
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix grpc server setup
Signed-off-by: aryan <aryangodara03@gmail.com>
* resolve golangci tests, remove debug statements
Signed-off-by: aryan <aryangodara03@gmail.com>
* update golangci version and modify linters used
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix failing tests
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix grpc server for setup tests
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix logging and errors inlined
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix remarks, update grpc setup_test
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix setup_test
Signed-off-by: aryan <aryangodara03@gmail.com>
* update setup_test grpc
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix data race
Signed-off-by: aryan <aryangodara03@gmail.com>
* update setup_test grpc
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix grpc setup down to single simple function
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix linting issues
Signed-off-by: aryan <aryangodara03@gmail.com>
* resolve pr comments
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix tests, handle returned errors, go mod tidy vendor
Signed-off-by: aryan <aryangodara03@gmail.com>
* fix errors from new linters
Signed-off-by: aryan <aryangodara03@gmail.com>
---------
Signed-off-by: aryan <aryangodara03@gmail.com>
2023-04-22 23:14:35 +08:00
|
|
|
require.Nil(t, err, fmt.Sprintf("unexpected error: %s\n", err))
|
2021-04-15 04:26:49 +08:00
|
|
|
|
|
|
|
msgBase64 := base64.StdEncoding.EncodeToString([]byte(msg))
|
|
|
|
|
|
|
|
cases := []struct {
|
|
|
|
desc string
|
|
|
|
err error
|
|
|
|
msg lora.Message
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "publish message with existing route-map and valid Data",
|
|
|
|
err: nil,
|
|
|
|
msg: lora.Message{
|
|
|
|
ApplicationID: appID,
|
|
|
|
DevEUI: devEUI,
|
|
|
|
Data: msgBase64,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "publish message with existing route-map and invalid Data",
|
|
|
|
err: lora.ErrMalformedMessage,
|
|
|
|
msg: lora.Message{
|
|
|
|
ApplicationID: appID,
|
|
|
|
DevEUI: devEUI,
|
|
|
|
Data: "wrong",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "publish message with non existing appID route-map",
|
|
|
|
err: lora.ErrNotFoundApp,
|
|
|
|
msg: lora.Message{
|
|
|
|
ApplicationID: "wrong",
|
|
|
|
DevEUI: devEUI,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "publish message with non existing devEUI route-map",
|
|
|
|
err: lora.ErrNotFoundDev,
|
|
|
|
msg: lora.Message{
|
|
|
|
ApplicationID: appID,
|
|
|
|
DevEUI: "wrong",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "publish message with non existing connection route-map",
|
|
|
|
err: lora.ErrNotConnected,
|
|
|
|
msg: lora.Message{
|
|
|
|
ApplicationID: appID2,
|
|
|
|
DevEUI: devEUI2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
2023-04-12 23:30:01 +08:00
|
|
|
err := svc.Publish(context.Background(), &tc.msg)
|
2021-04-15 04:26:49 +08:00
|
|
|
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
|
|
|
}
|
|
|
|
}
|