Skip to content

Commit

Permalink
bridge: add unit-tests
Browse files Browse the repository at this point in the history
- tests for sign up, sing in, sign off, publish resources and
refresh token
  • Loading branch information
Danielius1922 authored and Daniel Adam committed Feb 1, 2024
1 parent 7882252 commit 315fbe2
Show file tree
Hide file tree
Showing 22 changed files with 988 additions and 448 deletions.
2 changes: 2 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
ignore:
- "client/app/app.go"
- "cmd/ocfclient/ocfclient.go"
- "cmd/ocfbridge/*.go"
- "**/main.go"
- "**/test/**/*.go"
- "**/*.pb.go"
- "**/*.pb.gw.go"
- "**/*_test.go"
Expand Down
15 changes: 10 additions & 5 deletions .github/workflows/test-with-cfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ on:
name:
type: string
required: true
bridgetest-enabled:
type: boolean
required: false
default: false
coverage:
type: boolean
required: false
Expand All @@ -22,10 +26,10 @@ on:
type: string
required: false
default: ""
unittest-args:
type: string
unittest-enabled:
type: boolean
required: false
default: ""
default: false
jobs:
test:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -53,13 +57,14 @@ jobs:

# Run after integration tests, because they always clean-up the output directory
- name: Run bridge tests
if: ${{ inputs.bridgetest-enabled }}
run: |
make test-bridge
- name: Run unit tests
if: ${{ inputs.coverage }}
if: ${{ inputs.unittest-enabled }}
run: |
make unit-test ${{ inputs.unittest-args }}
make unit-test
- name: Get output file name
if: ${{ inputs.coverage }}
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ jobs:
matrix:
include:
- name: cloud-server-debug
bridgetest-enabled: true
coverage: true
tag: ghcr.io/iotivity/iotivity-lite/cloud-server-debug:vnext
unittest-enabled: true
- name: cloud-server-debug-sha384
test-args: CERT_TOOL_SIGN_ALG=ECDSA-SHA384 CERT_TOOL_ELLIPTIC_CURVE=P384
coverage: true
Expand All @@ -37,9 +39,11 @@ jobs:
uses: ./.github/workflows/test-with-cfg.yml
with:
name: ${{ matrix.name }}
bridgetest-enabled: ${{ matrix.bridgetest-enabled || false }}
coverage: ${{ matrix.coverage }}
tag: ${{ matrix.tag }}
test-args: ${{ matrix.test-args }}
unittest-enabled: ${{ matrix.unittest-enabled || false }}

analysis:
name: SonarCloud and codecov analysis
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ vendor/
debug
cmd/ocfbridge/ocfbridge
cmd/ocfclient/ocfclient

test/ocfbridge/ocfbridge
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ test: env build-testcontainer
test-bridge:
rm -rf $(TMP_PATH)/bridge || :
mkdir -p $(TMP_PATH)/bridge
go build -C ./cmd/ocfbridge -cover -o ./ocfbridge
go build -C ./test/ocfbridge -cover -o ./ocfbridge
pkill -KILL ocfbridge || :
GOCOVERDIR=$(TMP_PATH)/bridge ./cmd/ocfbridge/ocfbridge -config ./cmd/ocfbridge/config.yaml &
GOCOVERDIR=$(TMP_PATH)/bridge ./test/ocfbridge/ocfbridge -config ./test/ocfbridge/config.yaml &

docker pull $(HUB_TEST_DEVICE_IMAGE) && \
docker run \
Expand All @@ -99,7 +99,7 @@ test-bridge:
--env TEST_DEVICE_NAME="bridged-device-0" \
--env TEST_DEVICE_TYPE="bridged" \
--env GRPC_GATEWAY_TEST_DISABLED=1 \
--env IOTIVITY_LITE_TEST_RUN="(TestOffboard|TestOffboardWithRepeat)$$" \
--env IOTIVITY_LITE_TEST_RUN="(TestOffboard|TestOffboardWithoutSignIn|TestOffboardWithRepeat|TestRepublishAfterRefresh)$$" \
-v $(TMP_PATH):/tmp \
$(HUB_TEST_DEVICE_IMAGE)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,9 @@
package cloud

import (
"time"

"github.com/plgd-dev/device/v2/schema"
"github.com/plgd-dev/device/v2/schema/cloud"
)

type CoapSignUpRequest struct {
DeviceID string `json:"di"`
AuthorizationCode string `json:"accesstoken"`
AuthorizationProvider string `json:"authprovider"`
}

type CoapSignUpResponse struct {
AccessToken string `yaml:"accessToken" json:"accesstoken"`
UserID string `yaml:"userID" json:"uid"`
RefreshToken string `yaml:"refreshToken" json:"refreshtoken"`
RedirectURI string `yaml:"-" json:"redirecturi"`
ExpiresIn int64 `yaml:"-" json:"expiresin"`
ValidUntil time.Time `yaml:"-" jsom:"-"`
}

type CoapSignInRequest struct {
DeviceID string `json:"di"`
UserID string `json:"uid"`
AccessToken string `json:"accesstoken"`
Login bool `json:"login"`
}

type CoapSignInResponse struct {
ExpiresIn int64 `json:"expiresin"`
}

type PublishResourcesRequest struct {
DeviceID string `json:"di"`
Links schema.ResourceLinks `json:"links"`
TimeToLive int `json:"ttl"`
}

type Configuration struct {
ResourceTypes []string `yaml:"-" json:"rt"`
Interfaces []string `yaml:"-" json:"if"`
Expand All @@ -68,15 +33,3 @@ type Configuration struct {
ProvisioningStatus cloud.ProvisioningStatus `yaml:"-" json:"cps"`
AuthorizationCode string `yaml:"-" json:"-"`
}

type CoapRefreshTokenRequest struct {
DeviceID string `json:"di"`
UserID string `json:"uid"`
RefreshToken string `json:"refreshtoken"`
}

type CoapRefreshTokenResponse struct {
AccessToken string `json:"accesstoken"`
RefreshToken string `json:"refreshtoken"`
ExpiresIn int64 `json:"expiresin"`
}
Loading

0 comments on commit 315fbe2

Please sign in to comment.