Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade dependencies #446

Merged
merged 5 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- run: go version

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v4
with:
version: latest
args: --timeout=5m
11 changes: 7 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
linters-settings:
gocyclo:
min-complexity: 15
govet:
check-shadowing: true
exhaustive:
default-signifies-exhaustive: true
gocyclo:
min-complexity: 15
gomodguard:
blocked:
modules:
- github.com/pkg/errors:
recommendations:
- errors
gomoddirectives:
replace-allow-list:
- github.com/pion/dtls/v2
govet:
check-shadowing: true
stylecheck:
# STxxxx checks in https://staticcheck.io/docs/configuration/options/#checks
# Default: ["*"]
Expand Down
13 changes: 12 additions & 1 deletion bridge/device/cloud/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,17 @@ func (c *Manager) isCredsExpiring() bool {
return !time.Now().Before(c.creds.ValidUntil.Add(-time.Second * 10))
}

func getResourceTypesFilter(request *mux.Message) []string {
queries, _ := request.Options().Queries()
resourceTypesFitler := []string{}
for _, q := range queries {
if len(q) > 3 && q[:3] == "rt=" {
resourceTypesFitler = append(resourceTypesFitler, q[3:])
}
}
return resourceTypesFitler
}

func (c *Manager) serveCOAP(w mux.ResponseWriter, request *mux.Message) {
request.Message.AddQuery("di=" + c.deviceID.String())
r := net.Request{
Expand All @@ -316,7 +327,7 @@ func (c *Manager) serveCOAP(w mux.ResponseWriter, request *mux.Message) {
}
resp, err = c.handler(&r)
case plgdResources.ResourceURI:
links := c.getLinks(schema.Endpoints{}, c.deviceID, nil, resources.PublishToCloud)
links := c.getLinks(schema.Endpoints{}, c.deviceID, getResourceTypesFilter(request), resources.PublishToCloud)
links = patchDeviceLink(links)
links = discovery.PatchLinks(links, c.deviceID.String())
resp, err = resources.CreateResponseContent(request.Context(), links, codes.Content)
Expand Down
147 changes: 147 additions & 0 deletions client/core/sdkError_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
// ************************************************************************
// Copyright (C) 2024 plgd.dev, s.r.o.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ************************************************************************

package core_test

import (
"errors"
"testing"

"github.com/plgd-dev/device/v2/client/core"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
)

var err = errors.New("test")

func TestMakeCanceled(t *testing.T) {
sdkErr := core.SdkError{}
require.True(t, errors.As(core.MakeCanceled(err), &sdkErr))
require.Equal(t, codes.Canceled, sdkErr.GetCode())
require.Equal(t, err, sdkErr.Unwrap())
}

func TestMakeUnknown(t *testing.T) {
sdkErr := core.SdkError{}
require.True(t, errors.As(core.MakeUnknown(err), &sdkErr))
require.Equal(t, codes.Unknown, sdkErr.GetCode())
require.Equal(t, err, sdkErr.Unwrap())
}

func TestMakeInvalidArgument(t *testing.T) {
sdkErr := core.SdkError{}
require.True(t, errors.As(core.MakeInvalidArgument(err), &sdkErr))
require.Equal(t, codes.InvalidArgument, sdkErr.GetCode())
require.Equal(t, err, sdkErr.Unwrap())
}

func TestMakeDeadlineExceeded(t *testing.T) {
sdkErr := core.SdkError{}
require.True(t, errors.As(core.MakeDeadlineExceeded(err), &sdkErr))
require.Equal(t, codes.DeadlineExceeded, sdkErr.GetCode())
require.Equal(t, err, sdkErr.Unwrap())
}

func TestMakeNotFound(t *testing.T) {
sdkErr := core.SdkError{}
require.True(t, errors.As(core.MakeNotFound(err), &sdkErr))
require.Equal(t, codes.NotFound, sdkErr.GetCode())
require.Equal(t, err, sdkErr.Unwrap())
}

func TestMakeAlreadyExists(t *testing.T) {
sdkErr := core.SdkError{}
require.True(t, errors.As(core.MakeAlreadyExists(err), &sdkErr))
require.Equal(t, codes.AlreadyExists, sdkErr.GetCode())
require.Equal(t, err, sdkErr.Unwrap())
}

func TestMakePermissionDenied(t *testing.T) {
sdkErr := core.SdkError{}
require.True(t, errors.As(core.MakePermissionDenied(err), &sdkErr))
require.Equal(t, codes.PermissionDenied, sdkErr.GetCode())
require.Equal(t, err, sdkErr.Unwrap())
}

func TestMakeResourceExhausted(t *testing.T) {
sdkErr := core.SdkError{}
require.True(t, errors.As(core.MakeResourceExhausted(err), &sdkErr))
require.Equal(t, codes.ResourceExhausted, sdkErr.GetCode())
require.Equal(t, err, sdkErr.Unwrap())
}

func TestMakeFailedPrecondition(t *testing.T) {
sdkErr := core.SdkError{}
require.True(t, errors.As(core.MakeFailedPrecondition(err), &sdkErr))
require.Equal(t, codes.FailedPrecondition, sdkErr.GetCode())
require.Equal(t, err, sdkErr.Unwrap())
}

func TestMakeAborted(t *testing.T) {
sdkErr := core.SdkError{}
require.True(t, errors.As(core.MakeAborted(err), &sdkErr))
require.Equal(t, codes.Aborted, sdkErr.GetCode())
require.Equal(t, err, sdkErr.Unwrap())
}

func TestMakeOutOfRange(t *testing.T) {
sdkErr := core.SdkError{}
require.True(t, errors.As(core.MakeOutOfRange(err), &sdkErr))
require.Equal(t, codes.OutOfRange, sdkErr.GetCode())
require.Equal(t, err, sdkErr.Unwrap())
}

func TestMakeUnimplemented(t *testing.T) {
sdkErr := core.SdkError{}
require.True(t, errors.As(core.MakeUnimplemented(err), &sdkErr))
require.Equal(t, codes.Unimplemented, sdkErr.GetCode())
require.Equal(t, err, sdkErr.Unwrap())
}

func TestMakeInternal(t *testing.T) {
sdkErr := core.SdkError{}
require.True(t, errors.As(core.MakeInternal(err), &sdkErr))
require.Equal(t, codes.Internal, sdkErr.GetCode())
require.Equal(t, err, sdkErr.Unwrap())
}

func TestMakeInternalStr(t *testing.T) {
sdkErr := core.SdkError{}
require.True(t, errors.As(core.MakeInternalStr("test:%v", err), &sdkErr))
require.Equal(t, codes.Internal, sdkErr.GetCode())
require.Contains(t, sdkErr.Error(), "test:"+err.Error())
}

func TestMakeUnavailable(t *testing.T) {
sdkErr := core.SdkError{}
require.True(t, errors.As(core.MakeUnavailable(err), &sdkErr))
require.Equal(t, codes.Unavailable, sdkErr.GetCode())
require.Equal(t, err, sdkErr.Unwrap())
}

func TestMakeDataLoss(t *testing.T) {
sdkErr := core.SdkError{}
require.True(t, errors.As(core.MakeDataLoss(err), &sdkErr))
require.Equal(t, codes.DataLoss, sdkErr.GetCode())
require.Equal(t, err, sdkErr.Unwrap())
}

func TestMakeUnauthenticated(t *testing.T) {
sdkErr := core.SdkError{}
require.True(t, errors.As(core.MakeUnauthenticated(err), &sdkErr))
require.Equal(t, codes.Unauthenticated, sdkErr.GetCode())
require.Equal(t, err, sdkErr.Unwrap())
}
Loading
Loading