-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! Refactor and add unit tests (#422)
- Loading branch information
1 parent
2a55444
commit a83e282
Showing
17 changed files
with
143 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/**************************************************************************** | ||
* | ||
* 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 bridge_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/google/uuid" | ||
bridgeTest "github.com/plgd-dev/device/v2/bridge/test" | ||
"github.com/plgd-dev/device/v2/test" | ||
testClient "github.com/plgd-dev/device/v2/test/client" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestOnboardDevice(t *testing.T) { | ||
s := bridgeTest.NewBridgeService(t) | ||
deviceID := uuid.New().String() | ||
d := bridgeTest.NewBridgedDevice(t, s, true, deviceID) | ||
defer func() { | ||
s.DeleteAndCloseDevice(d.GetID()) | ||
}() | ||
cleanup := bridgeTest.RunBridgeService(s) | ||
defer cleanup() | ||
|
||
type args struct { | ||
deviceID string | ||
authorizationProvider string | ||
authorizationCode string | ||
cloudURL string | ||
cloudID string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "notFound", | ||
args: args{ | ||
deviceID: "notFound", | ||
authorizationProvider: "authorizationProvider", | ||
authorizationCode: "authorizationCode", | ||
cloudURL: "coaps+tcp://test:5684", | ||
cloudID: "cloudID", | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "valid", | ||
args: args{ | ||
deviceID: deviceID, | ||
authorizationProvider: "authorizationProvider", | ||
authorizationCode: "authorizationCode", | ||
cloudURL: "coaps+tcp://test:5684", | ||
cloudID: "cloudID", | ||
}, | ||
}, | ||
} | ||
|
||
c, err := testClient.NewTestSecureClient() | ||
require.NoError(t, err) | ||
defer func() { | ||
errC := c.Close(context.Background()) | ||
require.NoError(t, errC) | ||
}() | ||
ctx, cancel := context.WithTimeout(context.Background(), test.TestTimeout) | ||
defer cancel() | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
ttCtx, ttCancel := context.WithTimeout(ctx, time.Second) | ||
defer ttCancel() | ||
err = c.OnboardDevice(ttCtx, tt.args.deviceID, tt.args.authorizationProvider, tt.args.cloudURL, tt.args.authorizationCode, tt.args.cloudID, withDeviceID(d.GetID().String())) | ||
if tt.wantErr { | ||
require.Error(t, err) | ||
return | ||
} | ||
require.NoError(t, err) | ||
err = c.OffboardDevice(ttCtx, tt.args.deviceID, withDeviceID(d.GetID().String())) | ||
require.NoError(t, err) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
apis: | ||
coap: | ||
id: 8f596b43-29c0-4147-8b40-e99268ab30f7 | ||
name: "my-bridge-example" | ||
name: "bridge-example" | ||
externalAddress: "127.0.0.1:15683" | ||
maxMessageSize: 262144 | ||
numGeneratedBridgedDevices: 3 | ||
numGeneratedBridgedDevices: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters