From 0f3c7fc001768aa541f8543bef1045d056aff033 Mon Sep 17 00:00:00 2001 From: Mengyi Wang Date: Mon, 15 Jan 2024 16:32:32 +0100 Subject: [PATCH] Add chip-tool test suite (continue) (#2) * Remove edgex related code, add matter test suite * Add license * Add Git LFS tracking for large binary file * Add comments for explaining github context inputs --- LICENSE | 201 ++++++++++++++++++ README.md | 74 +------ build/action.yml | 9 +- go.mod | 2 +- go.sum | 8 - test/action.yml | 47 ++-- test/scripts/create-tls-certificates.sh | 32 --- test/scripts/login-test-user.sh | 22 -- .../app-rfid-llrp-inventory/main_test.go | 54 ----- .../app-service-configurable/config_test.go | 40 ---- .../app-service-configurable/main_test.go | 59 ----- test/suites/chip-tool/.gitattributes | 1 + ...ip-all-clusters-minimal-app-commit-1536ca2 | 3 + test/suites/chip-tool/main_test.go | 152 +++++++++++++ test/suites/device-gpio/main_test.go | 54 ----- test/suites/device-modbus/main_test.go | 54 ----- test/suites/device-mqtt/main_test.go | 54 ----- test/suites/device-onvif-camera/main_test.go | 54 ----- test/suites/device-rest/main_test.go | 54 ----- test/suites/device-rfid-llrp/main_test.go | 54 ----- test/suites/device-snmp/main_test.go | 54 ----- test/suites/device-usb-camera/main_test.go | 60 ------ test/suites/device-virtual/main_test.go | 54 ----- .../suites/edgex-config-provider/main_test.go | 163 -------------- test/suites/edgex-no-sec/ekuiper_test.go | 110 ---------- test/suites/edgex-no-sec/main_test.go | 96 --------- test/suites/edgex-no-sec/status_test.go | 36 ---- test/suites/edgexfoundry/.gitignore | 3 - test/suites/edgexfoundry/config_test.go | 92 -------- test/suites/edgexfoundry/main_test.go | 87 -------- .../edgexfoundry/refresh/refresh_test.go | 12 -- .../edgexfoundry/secrets_config_test.go | 80 ------- test/suites/ekuiper/config_test.go | 55 ----- test/suites/ekuiper/main_test.go | 139 ------------ test/suites/ekuiper/streams_rules_test.go | 130 ----------- test/suites/ui/main_test.go | 68 ------ test/utils/config.go | 169 --------------- test/utils/content_interfaces.go | 35 --- test/utils/env.go | 22 -- test/utils/login.go | 15 -- test/utils/net.go | 58 +---- test/utils/readings.go | 58 ----- test/utils/refresh.go | 6 - test/utils/setup.go | 40 ---- test/utils/snap.go | 4 - 45 files changed, 387 insertions(+), 2287 deletions(-) create mode 100644 LICENSE delete mode 100755 test/scripts/create-tls-certificates.sh delete mode 100755 test/scripts/login-test-user.sh delete mode 100644 test/suites/app-rfid-llrp-inventory/main_test.go delete mode 100644 test/suites/app-service-configurable/config_test.go delete mode 100644 test/suites/app-service-configurable/main_test.go create mode 100644 test/suites/chip-tool/.gitattributes create mode 100755 test/suites/chip-tool/chip-all-clusters-minimal-app-commit-1536ca2 create mode 100644 test/suites/chip-tool/main_test.go delete mode 100644 test/suites/device-gpio/main_test.go delete mode 100644 test/suites/device-modbus/main_test.go delete mode 100644 test/suites/device-mqtt/main_test.go delete mode 100644 test/suites/device-onvif-camera/main_test.go delete mode 100644 test/suites/device-rest/main_test.go delete mode 100644 test/suites/device-rfid-llrp/main_test.go delete mode 100644 test/suites/device-snmp/main_test.go delete mode 100644 test/suites/device-usb-camera/main_test.go delete mode 100644 test/suites/device-virtual/main_test.go delete mode 100644 test/suites/edgex-config-provider/main_test.go delete mode 100644 test/suites/edgex-no-sec/ekuiper_test.go delete mode 100644 test/suites/edgex-no-sec/main_test.go delete mode 100644 test/suites/edgex-no-sec/status_test.go delete mode 100644 test/suites/edgexfoundry/.gitignore delete mode 100644 test/suites/edgexfoundry/config_test.go delete mode 100644 test/suites/edgexfoundry/main_test.go delete mode 100644 test/suites/edgexfoundry/refresh/refresh_test.go delete mode 100644 test/suites/edgexfoundry/secrets_config_test.go delete mode 100644 test/suites/ekuiper/config_test.go delete mode 100644 test/suites/ekuiper/main_test.go delete mode 100644 test/suites/ekuiper/streams_rules_test.go delete mode 100644 test/suites/ui/main_test.go delete mode 100644 test/utils/content_interfaces.go delete mode 100644 test/utils/login.go delete mode 100644 test/utils/readings.go diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..989e2c5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ +Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. \ No newline at end of file diff --git a/README.md b/README.md index 09014c5..2e40f5b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -# EdgeX Snap Tests -Test scripts, Github actions, and workflows for the [EdgeX Foundry](https://docs.edgexfoundry.org/) snaps. +# Matter Snap Tests (WIP) +Test scripts, Github actions, and workflows for the [Matter](https://github.com/project-chip/connectedhomeip/tree/master) snaps. The following diagram shows the Snap Testing workflow for building and testing snaps from upstream source code: ```mermaid @@ -22,10 +22,6 @@ flowchart LR The Github Workflow configurations (triggers, jobs, etc) are maintained in respective upstream source codes. The Github Actions and testing suites are maintained in this repository. -For example, [this](https://github.com/edgexfoundry/edgex-go/blob/main/.github/workflows/snap.yaml) is the workflow of the tests that run on the edgex-go project. The Github Actions used in the workflow are versioned using a major semantic versioning tag. This tag is [automatically moved](https://github.com/canonical/edgex-snap-testing/blob/main/.github/workflows/versioning.yml) to the latest minor and patch releases of the tests (this repository). - -This project has additional [workflows](https://github.com/canonical/edgex-snap-testing/tree/main/.github/workflows) such as for running the tests weekly and on local PRs. - ## Test locally This section includes example command to run tests. @@ -37,7 +33,7 @@ Useful `go test` flags are: #### Run one testing suite ```bash -go test -v -failfast -count 1 ./test/suites/device-mqtt +go test -v -failfast -count 1 ./test/suites/chip-tool ``` #### Run all suites @@ -48,55 +44,11 @@ go test -p 1 -timeout 60m -failfast -count 1 ./test/suites/... #### Run one suite with env variables The environment variables are defined in [test/utils/env.go](./test/utils/env.go) -Full config test: -```bash -FULL_CONFIG_TEST=true go test -v -failfast -count 1 ./test/suites/device-mqtt -``` - -Testing with a local platform snap: -```bash -LOCAL_PLATFORM_SNAP="edgexfoundry_3.1.0-dev.3_amd64.snap" \ -go test -v -failfast -count 1 ./test/suites/edgexfoundry -``` -Testing with a local service snap: -```bash -LOCAL_SERVICE_SNAP="edgex-device-mqtt_2.0.1-dev.15_amd64.snap" \ -go test -v -failfast -count 1 ./test/suites/device-mqtt -``` -Testing with local platform and service snaps: -```bash -LOCAL_PLATFORM_SNAP="edgexfoundry_3.1.0-dev.3_amd64.snap" \ -LOCAL_SERVICE_SNAP="edgex-device-mqtt_2.0.1-dev.15_amd64.snap" \ -go test -v -failfast -count 1 ./test/suites/device-mqtt -``` - -Test with skipping the removal of snaps during teardown: -```bash -SKIP_TEARDOWN_REMOVAL=true go test -v -failfast -count 1 ./test/suites/ -``` - -Test by revision: -``` -PLATFORM_CHANNEL=4259 go test -v -failfast -count 1 ./test/suites/edgex-no-sec -``` -This requires developer access; see `snap install -h` for details. - -#### Run only one test from a suite -``` -go test -v ./test/suites/edgexfoundry --run=TestCommon -``` -``` -go test -v ./test/suites/edgex-config-provider -run=TestConfigProvider/device-virtual -``` - #### Test the testing utils ```bash go test ./test/utils -count=10 ``` -#### Run EdgeX Ubuntu Core tests -Refer to [edgex-ubuntu-core-testing](https://github.com/canonical/edgex-ubuntu-core-testing) - ## Test using Github Actions This project includes two Github Actions that can be used in workflows to test snaps: * [build](./build): Checkout code, build the snap, and upload snap as build artifact @@ -120,7 +72,7 @@ jobs: steps: - name: Build and upload snap id: build - uses: canonical/edgex-snap-testing/build@v2 + uses: canonical/matter-snap-testing/build@v2 outputs: snap: ${{steps.build.outputs.snap}} @@ -129,25 +81,9 @@ jobs: runs-on: ubuntu-latest steps: - name: Download and test snap - uses: canonical/edgex-snap-testing/test@v2 + uses: canonical/matter-snap-testing/test@v2 with: name: device-mqtt snap: ${{needs.build.outputs.snap}} ``` -## Testing Scripts - -The testing scripts can be located in the [./test/scripts](./test/scripts/) directory. - -To create a token for example user: - -```bash -./test/scripts/login-test-user.sh -``` - -To create a self-signed TLS certificate and replace the defaults: - -```bash -./test/scripts/create-tls-certificates.sh -``` - diff --git a/build/action.yml b/build/action.yml index e5743eb..1113e7f 100644 --- a/build/action.yml +++ b/build/action.yml @@ -1,4 +1,4 @@ -name: EdgeX Snap Builder +name: Matter Snap Builder description: | This action clones the source code, builds the snap using and uploads the resulting snap as a build artifact @@ -29,16 +29,9 @@ runs: repository: ${{inputs.repo}} ref: ${{inputs.branch}} - # Get snap base version - - shell: bash - run: | - echo "base=$(sed -n 's/^base: //p' snap/snapcraft.yaml)" >> $GITHUB_ENV - # Build the snap - uses: snapcore/action-build@v1 id: build - with: - snapcraft-args: ${{ env.base == 'core22' && '--verbose' || '' }} # Upload the snap as build artifact - uses: actions/upload-artifact@v3 diff --git a/go.mod b/go.mod index c883036..57c3333 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module edgex-snap-testing +module matter-snap-testing go 1.17 diff --git a/go.sum b/go.sum index 91da683..82af653 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,3 @@ -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -12,20 +11,13 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/test/action.yml b/test/action.yml index 2227372..f26f8fc 100644 --- a/test/action.yml +++ b/test/action.yml @@ -1,4 +1,4 @@ -name: EdgeX Snap Tester +name: Matter Snap Tester description: | This Github action runs various smoke tests to validate the snap packaging. @@ -11,23 +11,13 @@ inputs: description: Name of the testing suite required: true snap: - description: Relative path to local platform or service snap + description: Relative path to local snap required: false channel: description: | Channel for downloading the snap from store. This is useful only when 'snap' input is not set. required: false - platform_channel: - description: | - Channel for downloading the edgexfoundry snap from store. - This is used when testing services against the edgexfoundry snap. - This is useful only when 'snap' input is not set. - required: false - full_config_test: - description: | - Option for enabling full config options test to include for e.g. legacy options testing. - required: false go-args: description: | Flags for running go test @@ -39,6 +29,14 @@ inputs: required: false default: 'true' + # The values of github.action_repository and github.action_ref vary + # based on their usage location. Therefore, setting the values as inputs + # ensures that they align with the action itself rather than the step's action + action_repository: + default: ${{ github.action_repository }} + action_ref: + default: ${{ github.action_ref }} + runs: using: composite @@ -56,13 +54,18 @@ runs: run: | echo "local_snap=${{github.workspace}}/${{inputs.snap}}" >> $GITHUB_OUTPUT + # Checkout Repository with LFS + - uses: actions/checkout@v4 + with: + repository: ${{inputs.action_repository}} + ref: ${{inputs.action_ref}} + path: src + lfs: true + # Run smoke tests - shell: bash - working-directory: ${{github.action_path}} + working-directory: ${{github.workspace}}/src/test env: - LOCAL_PLATFORM_SNAP: ${{ inputs.name == 'edgexfoundry' && steps.path.outputs.local_snap || '' }} - LOCAL_SERVICE_SNAP: ${{ inputs.name != 'edgexfoundry' && steps.path.outputs.local_snap || '' }} - PLATFORM_CHANNEL: ${{inputs.platform_channel}} SERVICE_CHANNEL: ${{inputs.channel}} FULL_CONFIG_TEST: ${{inputs.full_config_test}} SKIP_TEARDOWN_REMOVAL: ${{inputs.skip_teardown_removal}} @@ -72,21 +75,13 @@ runs: # Print error logs from snap(s) - if: failure() shell: bash - working-directory: ${{github.action_path}} + working-directory: ${{github.workspace}}/src/test run: ./print-errors.sh ${{inputs.name}} - - # For some reason, github.action_path resolves to a wrong path when directly passed to - # upload-artifact's path or in bash - - if: always() - shell: bash - working-directory: ${{github.action_path}} - run: | - echo "action_path=$PWD" >> $GITHUB_ENV # Upload snap logs - if: always() uses: actions/upload-artifact@v3 with: name: ${{inputs.name}}-logs - path: ${{env.action_path}}/suites/${{inputs.name}}/*.log + path: ${{github.workspace}}/src/test/suites/${{inputs.name}}/*.log retention-days: 30 diff --git a/test/scripts/create-tls-certificates.sh b/test/scripts/create-tls-certificates.sh deleted file mode 100755 index cbe7fec..0000000 --- a/test/scripts/create-tls-certificates.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash -e - -SERVER_CERT_FILE=./tmp/server.cert -SERVER_KEY_FILE=./tmp/server.key -SERVER_CSR_FILE=./tmp/server.csr -CA_CERT_FILE=./tmp/ca.cert -CA_KEY_FILE=./tmp/ca.key - -mkdir tmp - -# Generate the Certificate Authority (CA) Private Key -openssl ecparam -name prime256v1 -genkey -noout -out $CA_KEY_FILE -# Generate the Certificate Authority Certificate -openssl req -new -x509 -sha256 -key $CA_KEY_FILE -out $CA_CERT_FILE -subj "/CN=snap-testing-ca" -# Generate the Server Certificate Private Key -openssl ecparam -name prime256v1 -genkey -noout -out $SERVER_KEY_FILE -# Generate the Server Certificate Signing Request -openssl req -new -sha256 -key $SERVER_KEY_FILE -out $SERVER_CSR_FILE -subj "/CN=localhost" -# Generate the Server Certificate -openssl x509 -req -in $SERVER_CSR_FILE -CA $CA_CERT_FILE -CAkey $CA_KEY_FILE -CAcreateserial -out $SERVER_CERT_FILE -days 1000 -sha256 - -# copy the files to a directory that the snap has permission to see -sudo cp $SERVER_CERT_FILE $SERVER_KEY_FILE /var/snap/edgexfoundry/common - -sudo edgexfoundry.secrets-config proxy tls \ - --inCert /var/snap/edgexfoundry/common/server.cert \ - --inKey /var/snap/edgexfoundry/common/server.key \ - --targetFolder /var/snap/edgexfoundry/current/nginx - -sudo rm $SERVER_CERT_FILE $SERVER_KEY_FILE - -sudo snap restart --reload edgexfoundry.nginx diff --git a/test/scripts/login-test-user.sh b/test/scripts/login-test-user.sh deleted file mode 100755 index b083df3..0000000 --- a/test/scripts/login-test-user.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash -ex - -username=test -password=$(sudo edgexfoundry.secrets-config proxy adduser --user ${username} --useRootToken | jq -r '.password') -if [[ -z "${password}" ]]; then - >&2 echo "Error getting a password for user" - exit 1 -fi - -vault_token=$(curl -sS "http://localhost:8200/v1/auth/userpass/login/${username}" -d "{\"password\":\"${password}\"}" | jq -re '.auth.client_token') -if [[ -z "${vault_token}" ]]; then - >&2 echo "Error retrieving Vault token for user ${username}" - exit 1 -fi - -id_token=$(curl -sS -H "Authorization: Bearer ${vault_token}" "http://localhost:8200/v1/identity/oidc/token/${username}" | jq -re '.data.token') -if [[ -z "${id_token}" ]]; then - >&2 echo "Error retrieving ID token for user ${username}" - exit 1 -fi - -echo $id_token diff --git a/test/suites/app-rfid-llrp-inventory/main_test.go b/test/suites/app-rfid-llrp-inventory/main_test.go deleted file mode 100644 index b754fcf..0000000 --- a/test/suites/app-rfid-llrp-inventory/main_test.go +++ /dev/null @@ -1,54 +0,0 @@ -package test - -import ( - "edgex-snap-testing/test/utils" - "log" - "os" - "testing" -) - -const ( - appRfidLlrpSnap = "edgex-app-rfid-llrp-inventory" - appRfidLlrpApp = "app-rfid-llrp-inventory" -) - -func TestMain(m *testing.M) { - teardown, err := utils.SetupServiceTests(appRfidLlrpSnap) - if err != nil { - log.Fatalf("Failed to setup tests: %s", err) - } - - code := m.Run() - teardown() - - os.Exit(code) -} - -func TestCommon(t *testing.T) { - utils.TestContentInterfaces(t, utils.ContentInterfaces{ - TestSecretstoreToken: true, - Snap: appRfidLlrpSnap, - App: appRfidLlrpApp, - }) - - utils.TestConfig(t, appRfidLlrpSnap, utils.Config{ - TestChangePort: utils.ConfigChangePort{ - App: appRfidLlrpApp, - DefaultPort: utils.ServicePort(appRfidLlrpApp), - TestAppConfig: true, - TestGlobalConfig: true, - TestMixedGlobalAppConfig: utils.FullConfigTest, - }, - TestAutoStart: true, - }) - - utils.TestNet(t, appRfidLlrpSnap, utils.Net{ - StartSnap: true, - TestOpenPorts: []string{utils.ServicePort(appRfidLlrpApp)}, - TestBindLoopback: []string{utils.ServicePort(appRfidLlrpApp)}, - }) - - utils.TestPackaging(t, appRfidLlrpSnap, utils.Packaging{ - TestSemanticSnapVersion: true, - }) -} diff --git a/test/suites/app-service-configurable/config_test.go b/test/suites/app-service-configurable/config_test.go deleted file mode 100644 index 36783d7..0000000 --- a/test/suites/app-service-configurable/config_test.go +++ /dev/null @@ -1,40 +0,0 @@ -package test - -import ( - "edgex-snap-testing/test/utils" - "strings" - "testing" - "time" - - "github.com/stretchr/testify/require" -) - -func TestProfileConfig(t *testing.T) { - // start clean - utils.SnapStop(t, ascService) - - t.Run("set profile", func(t *testing.T) { - t.Cleanup(func() { - utils.SnapStop(t, ascService) - utils.SnapUnset(t, ascSnap, "profile") - // set profile back to default for upcoming tests - utils.SnapSet(t, ascSnap, "profile", defaultTestProfile) - }) - - start := time.Now() - const profile = "http-export" - - // set profile - utils.SnapSet(t, ascSnap, "profile", profile) - utils.SnapStart(t, ascSnap) - - // check logs for the record of expected profile - - //check logs for the record of expected profile - time.Sleep(1 * time.Second) - logs := utils.SnapLogs(t, start, ascSnap) - expectLog := "app=app-" + profile - - require.True(t, strings.Contains(logs, expectLog)) - }) -} diff --git a/test/suites/app-service-configurable/main_test.go b/test/suites/app-service-configurable/main_test.go deleted file mode 100644 index 1e4cf45..0000000 --- a/test/suites/app-service-configurable/main_test.go +++ /dev/null @@ -1,59 +0,0 @@ -package test - -import ( - "edgex-snap-testing/test/utils" - "log" - "os" - "testing" -) - -const ( - ascSnap = "edgex-app-service-configurable" - ascApp = "app-service-configurable" - ascService = ascSnap + "." + ascApp - defaultTestProfile = "rules-engine" -) - -func TestMain(m *testing.M) { - teardown, err := utils.SetupServiceTests(ascSnap) - if err != nil { - log.Fatalf("Failed to setup tests: %s", err) - } - - // set profile to rules engine - utils.SnapSet(nil, ascSnap, "profile", defaultTestProfile) - - code := m.Run() - teardown() - - os.Exit(code) -} - -func TestCommon(t *testing.T) { - utils.TestContentInterfaces(t, utils.ContentInterfaces{ - TestSecretstoreToken: true, - Snap: ascSnap, - App: "app-" + defaultTestProfile, - }) - - utils.TestConfig(t, ascSnap, utils.Config{ - TestChangePort: utils.ConfigChangePort{ - App: ascApp, - DefaultPort: utils.ServicePort(ascApp), - TestAppConfig: true, - TestGlobalConfig: true, - TestMixedGlobalAppConfig: utils.FullConfigTest, - }, - TestAutoStart: true, - }) - - utils.TestNet(t, ascSnap, utils.Net{ - StartSnap: true, - TestOpenPorts: []string{utils.ServicePort(ascApp)}, - TestBindLoopback: []string{utils.ServicePort(ascApp)}, - }) - - utils.TestPackaging(t, ascSnap, utils.Packaging{ - TestSemanticSnapVersion: true, - }) -} diff --git a/test/suites/chip-tool/.gitattributes b/test/suites/chip-tool/.gitattributes new file mode 100644 index 0000000..03de60f --- /dev/null +++ b/test/suites/chip-tool/.gitattributes @@ -0,0 +1 @@ +chip-all-clusters-minimal-app-commit-* filter=lfs diff=lfs merge=lfs -text diff --git a/test/suites/chip-tool/chip-all-clusters-minimal-app-commit-1536ca2 b/test/suites/chip-tool/chip-all-clusters-minimal-app-commit-1536ca2 new file mode 100755 index 0000000..2e456dc --- /dev/null +++ b/test/suites/chip-tool/chip-all-clusters-minimal-app-commit-1536ca2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:29a03592355d375f14e8d5102d8b17c82c6c80ff0a8698adc79833d0360618e1 +size 98795128 diff --git a/test/suites/chip-tool/main_test.go b/test/suites/chip-tool/main_test.go new file mode 100644 index 0000000..46c8d25 --- /dev/null +++ b/test/suites/chip-tool/main_test.go @@ -0,0 +1,152 @@ +package test + +import ( + "log" + "matter-snap-testing/test/utils" + "os" + "os/exec" + "path/filepath" + "strings" + "testing" + "time" +) + +var start = time.Now() + +func TestMain(m *testing.M) { + teardown, err := setup() + if err != nil { + log.Fatalf("Failed to setup tests: %s", err) + } + + code := m.Run() + teardown() + + os.Exit(code) +} + +func TestMatterDeviceOperations(t *testing.T) { + const ( + chipAllClusterMinimalAppFile = "chip-all-clusters-minimal-app-commit-1536ca2" + chipAllClusterMinimalAppLog = "chip-all-clusters-minimal-app.log" + ) + + // Setup: remove exisiting log files + if err := os.Remove("./" + chipAllClusterMinimalAppLog); err != nil && !os.IsNotExist(err) { + t.Fatalf("Error deleting log file: %s\n", err) + } + if err := os.Remove("./chip-tool.log"); err != nil && !os.IsNotExist(err) { + t.Fatalf("Error deleting log file: %s\n", err) + } + + // Setup: run and log chip-all-clusters-minimal-app in the background + logFile, err := os.Create(chipAllClusterMinimalAppLog) + if err != nil { + t.Fatalf("Error creating log file: %s\n", err) + } + + cmd := exec.Command("./" + chipAllClusterMinimalAppFile) + cmd.Stdout = logFile + cmd.Stderr = logFile + + err = cmd.Start() + if err != nil { + t.Fatalf("Error starting application: %s\n", err) + } + + t.Cleanup(func() { + matches, err := filepath.Glob("/tmp/chip_*") + if err != nil { + t.Fatalf("Error finding tmp chip files: %s\n", err) + } + + for _, match := range matches { + if err := os.Remove(match); err != nil { + t.Fatalf("Error removing tmp chip file %s: %s\n", match, err) + } + } + + if err := cmd.Process.Kill(); err != nil { + t.Fatalf("Error killing process: %s\n", err) + } + + if logFile != nil { + logFile.Close() + } + }) + + t.Run("Commission", func(t *testing.T) { + utils.Exec(t, "sudo chip-tool pairing onnetwork 110 20202021") + }) + + t.Run("Control", func(t *testing.T) { + utils.Exec(t, "sudo chip-tool onoff toggle 110 1") + waitForAppMessage(t, "./"+chipAllClusterMinimalAppLog, "CHIP:ZCL: Toggle ep1 on/off", start) + }) +} + +func setup() (teardown func(), err error) { + const chipToolSnap = "chip-tool" + + log.Println("[CLEAN]") + utils.SnapRemove(nil, chipToolSnap) + + log.Println("[SETUP]") + + teardown = func() { + log.Println("[TEARDOWN]") + utils.SnapDumpLogs(nil, start, chipToolSnap) + + log.Println("Removing installed snap:", !utils.SkipTeardownRemoval) + if !utils.SkipTeardownRemoval { + utils.SnapRemove(nil, chipToolSnap) + } + } + + if utils.LocalServiceSnap() { + err = utils.SnapInstallFromFile(nil, utils.LocalServiceSnapPath) + } else { + err = utils.SnapInstallFromStore(nil, chipToolSnap, utils.ServiceChannel) + } + if err != nil { + teardown() + return + } + + // connect interfaces + utils.SnapConnect(nil, chipToolSnap+":avahi-observe", "") + utils.SnapConnect(nil, chipToolSnap+":bluez", "") + utils.SnapConnect(nil, chipToolSnap+":process-control", "") + + return +} + +func waitForAppMessage(t *testing.T, appLogPath, expectedLog string, since time.Time) { + const maxRetry = 10 + + for i := 1; i <= maxRetry; i++ { + time.Sleep(1 * time.Second) + t.Logf("Retry %d/%d: Waiting for expected content in logs: %s", i, maxRetry, expectedLog) + + logs, err := readLogFile(appLogPath) + if err != nil { + t.Fatalf("Error reading log file: %s\n", err) + continue + } + + if strings.Contains(logs, expectedLog) { + t.Logf("Found expected content in logs: %s", expectedLog) + return + } + } + + t.Fatalf("Time out: reached max %d retries.", maxRetry) +} + +func readLogFile(filePath string) (string, error) { + text, err := os.ReadFile(filePath) + if err != nil { + return "", err + } + return string(text), nil +} diff --git a/test/suites/device-gpio/main_test.go b/test/suites/device-gpio/main_test.go deleted file mode 100644 index 5d77ff3..0000000 --- a/test/suites/device-gpio/main_test.go +++ /dev/null @@ -1,54 +0,0 @@ -package test - -import ( - "edgex-snap-testing/test/utils" - "log" - "os" - "testing" -) - -const ( - deviceGpioSnap = "edgex-device-gpio" - deviceGpioApp = "device-gpio" -) - -func TestMain(m *testing.M) { - teardown, err := utils.SetupServiceTests(deviceGpioSnap) - if err != nil { - log.Fatalf("Failed to setup tests: %s", err) - } - - code := m.Run() - teardown() - - os.Exit(code) -} - -func TestCommon(t *testing.T) { - utils.TestContentInterfaces(t, utils.ContentInterfaces{ - TestSecretstoreToken: true, - Snap: deviceGpioSnap, - App: deviceGpioApp, - }) - - utils.TestConfig(t, deviceGpioSnap, utils.Config{ - TestChangePort: utils.ConfigChangePort{ - App: deviceGpioApp, - DefaultPort: utils.ServicePort(deviceGpioApp), - TestAppConfig: true, - TestGlobalConfig: true, - TestMixedGlobalAppConfig: utils.FullConfigTest, - }, - TestAutoStart: true, - }) - - utils.TestNet(t, deviceGpioSnap, utils.Net{ - StartSnap: true, - TestOpenPorts: []string{utils.ServicePort(deviceGpioApp)}, - TestBindLoopback: []string{utils.ServicePort(deviceGpioApp)}, - }) - - utils.TestPackaging(t, deviceGpioSnap, utils.Packaging{ - TestSemanticSnapVersion: true, - }) -} diff --git a/test/suites/device-modbus/main_test.go b/test/suites/device-modbus/main_test.go deleted file mode 100644 index 0c42821..0000000 --- a/test/suites/device-modbus/main_test.go +++ /dev/null @@ -1,54 +0,0 @@ -package test - -import ( - "edgex-snap-testing/test/utils" - "log" - "os" - "testing" -) - -const ( - deviceModbusSnap = "edgex-device-modbus" - deviceModbusApp = "device-modbus" -) - -func TestMain(m *testing.M) { - teardown, err := utils.SetupServiceTests(deviceModbusSnap) - if err != nil { - log.Fatalf("Failed to setup tests: %s", err) - } - - code := m.Run() - teardown() - - os.Exit(code) -} - -func TestCommon(t *testing.T) { - utils.TestContentInterfaces(t, utils.ContentInterfaces{ - TestSecretstoreToken: true, - Snap: deviceModbusSnap, - App: deviceModbusApp, - }) - - utils.TestConfig(t, deviceModbusSnap, utils.Config{ - TestChangePort: utils.ConfigChangePort{ - App: deviceModbusApp, - DefaultPort: utils.ServicePort(deviceModbusApp), - TestAppConfig: true, - TestGlobalConfig: true, - TestMixedGlobalAppConfig: utils.FullConfigTest, - }, - TestAutoStart: true, - }) - - utils.TestNet(t, deviceModbusSnap, utils.Net{ - StartSnap: true, - TestOpenPorts: []string{utils.ServicePort(deviceModbusApp)}, - TestBindLoopback: []string{utils.ServicePort(deviceModbusApp)}, - }) - - utils.TestPackaging(t, deviceModbusSnap, utils.Packaging{ - TestSemanticSnapVersion: true, - }) -} diff --git a/test/suites/device-mqtt/main_test.go b/test/suites/device-mqtt/main_test.go deleted file mode 100644 index e503e13..0000000 --- a/test/suites/device-mqtt/main_test.go +++ /dev/null @@ -1,54 +0,0 @@ -package test - -import ( - "edgex-snap-testing/test/utils" - "log" - "os" - "testing" -) - -const ( - deviceMqttSnap = "edgex-device-mqtt" - deviceMqttApp = "device-mqtt" -) - -func TestMain(m *testing.M) { - teardown, err := utils.SetupServiceTests(deviceMqttSnap) - if err != nil { - log.Fatalf("Failed to setup tests: %s", err) - } - - code := m.Run() - teardown() - - os.Exit(code) -} - -func TestCommon(t *testing.T) { - utils.TestContentInterfaces(t, utils.ContentInterfaces{ - TestSecretstoreToken: true, - Snap: deviceMqttSnap, - App: deviceMqttApp, - }) - - utils.TestConfig(t, deviceMqttSnap, utils.Config{ - TestChangePort: utils.ConfigChangePort{ - App: deviceMqttApp, - DefaultPort: utils.ServicePort(deviceMqttApp), - TestAppConfig: true, - TestGlobalConfig: true, - TestMixedGlobalAppConfig: utils.FullConfigTest, - }, - TestAutoStart: true, - }) - - utils.TestNet(t, deviceMqttSnap, utils.Net{ - StartSnap: true, - TestOpenPorts: []string{utils.ServicePort(deviceMqttApp)}, - TestBindLoopback: []string{utils.ServicePort(deviceMqttApp)}, - }) - - utils.TestPackaging(t, deviceMqttSnap, utils.Packaging{ - TestSemanticSnapVersion: true, - }) -} diff --git a/test/suites/device-onvif-camera/main_test.go b/test/suites/device-onvif-camera/main_test.go deleted file mode 100644 index 19ad203..0000000 --- a/test/suites/device-onvif-camera/main_test.go +++ /dev/null @@ -1,54 +0,0 @@ -package test - -import ( - "edgex-snap-testing/test/utils" - "log" - "os" - "testing" -) - -const ( - deviceOnvifCameraSnap = "edgex-device-onvif-camera" - deviceOnvifCameraApp = "device-onvif-camera" -) - -func TestMain(m *testing.M) { - teardown, err := utils.SetupServiceTests(deviceOnvifCameraSnap) - if err != nil { - log.Fatalf("Failed to setup tests: %s", err) - } - - code := m.Run() - teardown() - - os.Exit(code) -} - -func TestCommon(t *testing.T) { - utils.TestContentInterfaces(t, utils.ContentInterfaces{ - TestSecretstoreToken: true, - Snap: deviceOnvifCameraSnap, - App: deviceOnvifCameraApp, - }) - - utils.TestConfig(t, deviceOnvifCameraSnap, utils.Config{ - TestChangePort: utils.ConfigChangePort{ - App: deviceOnvifCameraApp, - DefaultPort: utils.ServicePort(deviceOnvifCameraApp), - TestAppConfig: true, - TestGlobalConfig: true, - TestMixedGlobalAppConfig: utils.FullConfigTest, - }, - TestAutoStart: true, - }) - - utils.TestNet(t, deviceOnvifCameraSnap, utils.Net{ - StartSnap: true, - TestOpenPorts: []string{utils.ServicePort(deviceOnvifCameraApp)}, - TestBindLoopback: []string{utils.ServicePort(deviceOnvifCameraApp)}, - }) - - utils.TestPackaging(t, deviceOnvifCameraSnap, utils.Packaging{ - TestSemanticSnapVersion: true, - }) -} diff --git a/test/suites/device-rest/main_test.go b/test/suites/device-rest/main_test.go deleted file mode 100644 index 8a88c65..0000000 --- a/test/suites/device-rest/main_test.go +++ /dev/null @@ -1,54 +0,0 @@ -package test - -import ( - "edgex-snap-testing/test/utils" - "log" - "os" - "testing" -) - -const ( - deviceRestSnap = "edgex-device-rest" - deviceRestApp = "device-rest" -) - -func TestMain(m *testing.M) { - teardown, err := utils.SetupServiceTests(deviceRestSnap) - if err != nil { - log.Fatalf("Failed to setup tests: %s", err) - } - - code := m.Run() - teardown() - - os.Exit(code) -} - -func TestCommon(t *testing.T) { - utils.TestContentInterfaces(t, utils.ContentInterfaces{ - TestSecretstoreToken: true, - Snap: deviceRestSnap, - App: deviceRestApp, - }) - - utils.TestConfig(t, deviceRestSnap, utils.Config{ - TestChangePort: utils.ConfigChangePort{ - App: deviceRestApp, - DefaultPort: utils.ServicePort(deviceRestApp), - TestAppConfig: true, - TestGlobalConfig: true, - TestMixedGlobalAppConfig: utils.FullConfigTest, - }, - TestAutoStart: true, - }) - - utils.TestNet(t, deviceRestSnap, utils.Net{ - StartSnap: true, - TestOpenPorts: []string{utils.ServicePort(deviceRestApp)}, - TestBindLoopback: []string{utils.ServicePort(deviceRestApp)}, - }) - - utils.TestPackaging(t, deviceRestSnap, utils.Packaging{ - TestSemanticSnapVersion: true, - }) -} diff --git a/test/suites/device-rfid-llrp/main_test.go b/test/suites/device-rfid-llrp/main_test.go deleted file mode 100644 index 3ce44c5..0000000 --- a/test/suites/device-rfid-llrp/main_test.go +++ /dev/null @@ -1,54 +0,0 @@ -package test - -import ( - "edgex-snap-testing/test/utils" - "log" - "os" - "testing" -) - -const ( - deviceRfidLlrpSnap = "edgex-device-rfid-llrp" - deviceRfidLlrpApp = "device-rfid-llrp" -) - -func TestMain(m *testing.M) { - teardown, err := utils.SetupServiceTests(deviceRfidLlrpSnap) - if err != nil { - log.Fatalf("Failed to setup tests: %s", err) - } - - code := m.Run() - teardown() - - os.Exit(code) -} - -func TestCommon(t *testing.T) { - utils.TestContentInterfaces(t, utils.ContentInterfaces{ - TestSecretstoreToken: true, - Snap: deviceRfidLlrpSnap, - App: deviceRfidLlrpApp, - }) - - utils.TestConfig(t, deviceRfidLlrpSnap, utils.Config{ - TestChangePort: utils.ConfigChangePort{ - App: deviceRfidLlrpApp, - DefaultPort: utils.ServicePort(deviceRfidLlrpApp), - TestAppConfig: true, - TestGlobalConfig: true, - TestMixedGlobalAppConfig: utils.FullConfigTest, - }, - TestAutoStart: true, - }) - - utils.TestNet(t, deviceRfidLlrpSnap, utils.Net{ - StartSnap: true, - TestOpenPorts: []string{utils.ServicePort(deviceRfidLlrpApp)}, - TestBindLoopback: []string{utils.ServicePort(deviceRfidLlrpApp)}, - }) - - utils.TestPackaging(t, deviceRfidLlrpSnap, utils.Packaging{ - TestSemanticSnapVersion: true, - }) -} diff --git a/test/suites/device-snmp/main_test.go b/test/suites/device-snmp/main_test.go deleted file mode 100644 index 645d939..0000000 --- a/test/suites/device-snmp/main_test.go +++ /dev/null @@ -1,54 +0,0 @@ -package test - -import ( - "edgex-snap-testing/test/utils" - "log" - "os" - "testing" -) - -const ( - deviceSnmpSnap = "edgex-device-snmp" - deviceSnmpApp = "device-snmp" -) - -func TestMain(m *testing.M) { - teardown, err := utils.SetupServiceTests(deviceSnmpSnap) - if err != nil { - log.Fatalf("Failed to setup tests: %s", err) - } - - code := m.Run() - teardown() - - os.Exit(code) -} - -func TestCommon(t *testing.T) { - utils.TestContentInterfaces(t, utils.ContentInterfaces{ - TestSecretstoreToken: true, - Snap: deviceSnmpSnap, - App: deviceSnmpApp, - }) - - utils.TestConfig(t, deviceSnmpSnap, utils.Config{ - TestChangePort: utils.ConfigChangePort{ - App: deviceSnmpApp, - DefaultPort: utils.ServicePort(deviceSnmpApp), - TestAppConfig: true, - TestGlobalConfig: true, - TestMixedGlobalAppConfig: utils.FullConfigTest, - }, - TestAutoStart: true, - }) - - utils.TestNet(t, deviceSnmpSnap, utils.Net{ - StartSnap: true, - TestOpenPorts: []string{utils.ServicePort(deviceSnmpApp)}, - TestBindLoopback: []string{utils.ServicePort(deviceSnmpApp)}, - }) - - utils.TestPackaging(t, deviceSnmpSnap, utils.Packaging{ - TestSemanticSnapVersion: true, - }) -} diff --git a/test/suites/device-usb-camera/main_test.go b/test/suites/device-usb-camera/main_test.go deleted file mode 100644 index 88fde44..0000000 --- a/test/suites/device-usb-camera/main_test.go +++ /dev/null @@ -1,60 +0,0 @@ -package test - -import ( - "edgex-snap-testing/test/utils" - "log" - "os" - "testing" -) - -const ( - deviceUSBCamSnap = "edgex-device-usb-camera" - deviceUSBCamApp = "device-usb-camera" - deviceUSBCamRtspApp = "device-usb-camera/rtsp" -) - -var ( - deviceUSBCamServicePort = utils.ServicePort(deviceUSBCamApp) - deviceUSBCamRtspServicePort = utils.ServicePort(deviceUSBCamRtspApp) -) - -func TestMain(m *testing.M) { - teardown, err := utils.SetupServiceTests(deviceUSBCamSnap) - if err != nil { - log.Fatalf("Failed to setup tests: %s", err) - } - - code := m.Run() - teardown() - - os.Exit(code) -} - -func TestCommon(t *testing.T) { - utils.TestContentInterfaces(t, utils.ContentInterfaces{ - TestSecretstoreToken: true, - Snap: deviceUSBCamSnap, - App: deviceUSBCamApp, - }) - - utils.TestConfig(t, deviceUSBCamSnap, utils.Config{ - TestChangePort: utils.ConfigChangePort{ - App: deviceUSBCamApp, - DefaultPort: deviceUSBCamServicePort, - TestAppConfig: true, - TestGlobalConfig: true, - TestMixedGlobalAppConfig: utils.FullConfigTest, - }, - TestAutoStart: true, - }) - - utils.TestNet(t, deviceUSBCamSnap, utils.Net{ - StartSnap: true, - TestOpenPorts: []string{deviceUSBCamServicePort, deviceUSBCamRtspServicePort}, - TestBindLoopback: []string{deviceUSBCamServicePort, deviceUSBCamRtspServicePort}, - }) - - utils.TestPackaging(t, deviceUSBCamSnap, utils.Packaging{ - TestSemanticSnapVersion: true, - }) -} diff --git a/test/suites/device-virtual/main_test.go b/test/suites/device-virtual/main_test.go deleted file mode 100644 index e5bb107..0000000 --- a/test/suites/device-virtual/main_test.go +++ /dev/null @@ -1,54 +0,0 @@ -package test - -import ( - "edgex-snap-testing/test/utils" - "log" - "os" - "testing" -) - -const ( - deviceVirtualSnap = "edgex-device-virtual" - deviceVirtualApp = "device-virtual" -) - -func TestMain(m *testing.M) { - teardown, err := utils.SetupServiceTests(deviceVirtualSnap) - if err != nil { - log.Fatalf("Failed to setup tests: %s", err) - } - - code := m.Run() - teardown() - - os.Exit(code) -} - -func TestCommon(t *testing.T) { - utils.TestContentInterfaces(t, utils.ContentInterfaces{ - TestSecretstoreToken: true, - Snap: deviceVirtualSnap, - App: deviceVirtualApp, - }) - - utils.TestConfig(t, deviceVirtualSnap, utils.Config{ - TestChangePort: utils.ConfigChangePort{ - App: deviceVirtualApp, - DefaultPort: utils.ServicePort(deviceVirtualApp), - TestAppConfig: true, - TestGlobalConfig: true, - TestMixedGlobalAppConfig: utils.FullConfigTest, - }, - TestAutoStart: true, - }) - - utils.TestNet(t, deviceVirtualSnap, utils.Net{ - StartSnap: true, - TestOpenPorts: []string{utils.ServicePort(deviceVirtualApp)}, - TestBindLoopback: []string{utils.ServicePort(deviceVirtualApp)}, - }) - - utils.TestPackaging(t, deviceVirtualSnap, utils.Packaging{ - TestSemanticSnapVersion: true, - }) -} diff --git a/test/suites/edgex-config-provider/main_test.go b/test/suites/edgex-config-provider/main_test.go deleted file mode 100644 index b741955..0000000 --- a/test/suites/edgex-config-provider/main_test.go +++ /dev/null @@ -1,163 +0,0 @@ -package test - -import ( - "edgex-snap-testing/test/utils" - "log" - "os" - "testing" - "time" -) - -const ( - platformSnap = "edgexfoundry" - provider = "edgex-config-provider-example" -) - -var services = []string{ - "app-service-configurable", - "app-rfid-llrp-inventory", - "device-gpio", - "device-modbus", - "device-mqtt", - "device-rest", - "device-rfid-llrp", - "device-snmp", - "device-usb-camera", - "device-virtual", - "device-onvif-camera", -} - -const startupMsg = "CONFIG BY EXAMPLE PROVIDER" - -func TestMain(m *testing.M) { - teardown, err := setup() - if err != nil { - log.Fatalf("Failed to setup tests: %s", err) - } - - code := m.Run() - teardown() - - os.Exit(code) -} - -func setup() (teardown func(), err error) { - log.Println("[CLEAN]") - utils.SnapRemove(nil, platformSnap) - utils.SnapRemove(nil, provider) - - log.Println("[SETUP]") - start := time.Now() - - teardown = func() { - log.Println("[TEARDOWN]") - utils.SnapDumpLogs(nil, start, platformSnap) - utils.SnapRemove(nil, platformSnap) - utils.SnapRemove(nil, provider) - // remove cloned directory - os.RemoveAll(provider) - } - - // install the provider - if utils.LocalServiceSnap() { - if err = utils.SnapInstallFromFile(nil, utils.LocalServiceSnapPath); err != nil { - teardown() - return - } - } else { - const workDir = provider + "/" - // clone the example provider - if _, _, err = utils.Exec(nil, "git clone https://github.com/canonical/edgex-config-provider.git --branch=snap-testing --depth=1 "+workDir); err != nil { - teardown() - return - } - - // build the example provider snap - if err = utils.SnapBuild(nil, workDir); err != nil { - teardown() - return - } - - const configProviderSnapFile = workDir + provider + "_*_*.snap" - if err = utils.SnapInstallFromFile(nil, configProviderSnapFile); err != nil { - teardown() - return - } - } - - if utils.LocalPlatformSnap() { - err = utils.SnapInstallFromFile(nil, utils.LocalPlatformSnapPath) - } else { - err = utils.SnapInstallFromStore(nil, platformSnap, utils.PlatformChannel) - } - if err != nil { - teardown() - return - } - - utils.SnapStart(nil, platformSnap) - - // make sure all services are online before starting the tests - if err = utils.WaitPlatformOnline(nil); err != nil { - teardown() - return - } - - return -} - -func TestConfigProvider(t *testing.T) { - - for _, name := range services { - t.Run(name, func(t *testing.T) { - snapName := "edgex-" + name - - // clean start - utils.SnapRemove(t, snapName) - - start := time.Now() - - t.Cleanup(func() { - utils.SnapDumpLogs(t, start, snapName) - utils.SnapRemove(t, snapName) - }) - - // install the consumer - utils.SnapInstallFromStore(t, snapName, utils.ServiceChannel) - - // add basic config to make the services run - switch name { - case "device-mqtt": - const mqttBroker = "mosquitto" - if !utils.SnapInstalled(t, mqttBroker) { - utils.SnapInstallFromStore(t, mqttBroker, "latest/stable") - t.Cleanup(func() { - utils.SnapRemove(t, mqttBroker) - }) - } - if !utils.SnapServicesActive(t, mqttBroker) { - utils.SnapStart(t, mqttBroker) - t.Cleanup(func() { - utils.SnapStop(t, mqttBroker) - }) - } - case "app-service-configurable": - utils.SnapSet(nil, snapName, "profile", "http-export") - } - - // NOTE: Connect after setting options to work around the error resulted - // from creation/removal of an env file in read-only file system. - // See https://warthogs.atlassian.net/browse/EDGEX-586 - // - // connect to provider's slot - interfaceName := name + "-config" - utils.SnapConnect(t, - snapName+":"+interfaceName, - provider+":"+interfaceName) - - utils.SnapStart(t, snapName) - - utils.WaitForLogMessage(t, snapName, `msg="`+startupMsg+`"`, start) - }) - } -} diff --git a/test/suites/edgex-no-sec/ekuiper_test.go b/test/suites/edgex-no-sec/ekuiper_test.go deleted file mode 100644 index 6ef4520..0000000 --- a/test/suites/edgex-no-sec/ekuiper_test.go +++ /dev/null @@ -1,110 +0,0 @@ -package test - -import ( - "edgex-snap-testing/test/utils" - "encoding/json" - "log" - "net/http" - "testing" - "time" - - "github.com/stretchr/testify/require" -) - -type Reading struct { - TotalCount int `json:"totalCount"` -} - -const ( - deviceVirtualSnap = "edgex-device-virtual" - deviceVirtualApp = "device-virtual" - - ekuiperSnap = "edgex-ekuiper" - ekuiperApp = "ekuiper" - ekuiperRestfulApi = "ekuiper/rest-api" -) - -func TestRulesEngine(t *testing.T) { - start := time.Now() - - t.Cleanup(func() { - log.Println("[TEARDOWN SUBTEST]") - utils.SnapDumpLogs(t, start, deviceVirtualSnap) - utils.SnapDumpLogs(t, start, ekuiperSnap) - - log.Println("Removing installed snap:", !utils.SkipTeardownRemoval) - if !utils.SkipTeardownRemoval { - utils.SnapRemove(t, deviceVirtualSnap) - utils.SnapRemove(t, ekuiperSnap) - } - }) - - log.Println("[CLEAN SUBTEST]") - utils.SnapRemove(t, deviceVirtualSnap) - utils.SnapRemove(t, ekuiperSnap) - - utils.SnapInstallFromStore(t, deviceVirtualSnap, utils.ServiceChannel) - utils.SnapInstallFromStore(t, ekuiperSnap, utils.ServiceChannel) - - // turn security off - utils.SnapSet(t, deviceVirtualSnap, "config.edgex-security-secret-store", "false") - utils.SnapSet(t, ekuiperSnap, "config.edgex-security-secret-store", "false") - - utils.SnapSet(t, ekuiperSnap, "config.kuiper.basic.debug", "true") - - // set tests to run without a config provider when testing config options as a temporary solution. - utils.DoNotUseConfigProviderServiceSnap(t, deviceVirtualSnap, deviceVirtualApp) - - // make sure all services are online before starting the tests - utils.SnapStart(t, - ekuiperSnap, - deviceVirtualSnap) - - utils.WaitServiceOnline(t, 60, - utils.ServicePort(deviceVirtualApp), - utils.ServicePort(ekuiperApp), - utils.ServicePort(ekuiperRestfulApi), - ) - - // wait device-virtual to produce readings - utils.WaitForReadings(t, "Random-Integer-Device", false) - - t.Run("create stream and rule", func(t *testing.T) { - utils.Exec(t, `edgex-ekuiper.kuiper create stream stream1 '()WITH(FORMAT="JSON",TYPE="edgex")'`) - - utils.Exec(t, - `edgex-ekuiper.kuiper create rule rule_edgex_message_bus ' - { - "sql":"SELECT * FROM stream1 WHERE meta(deviceName) != \"device-test\"", - "actions": [ - { - "edgex": { - "connectionSelector": "edgex.redisMsgBus", - "topicPrefix": "edgex/events/device", - "messageType": "request", - "deviceName": "device-test" - } - } - ] - }'`) - - // wait readings come from ekuiper to edgex message bus - utils.WaitForReadings(t, "device-test", false) - - req, err := http.NewRequest(http.MethodGet, "http://localhost:59880/api/v3/reading/device/name/device-test", nil) - require.NoError(t, err) - - client := &http.Client{} - resp, err := client.Do(req) - require.NoError(t, err) - defer resp.Body.Close() - - var reading Reading - if err = json.NewDecoder(resp.Body).Decode(&reading); err != nil { - t.Fatal(err) - } - - require.Greaterf(t, reading.TotalCount, 0, "No readings have been re-published to EdgeX message bus by ekuiper") - }) - -} diff --git a/test/suites/edgex-no-sec/main_test.go b/test/suites/edgex-no-sec/main_test.go deleted file mode 100644 index 3ccd341..0000000 --- a/test/suites/edgex-no-sec/main_test.go +++ /dev/null @@ -1,96 +0,0 @@ -package test - -import ( - "edgex-snap-testing/test/utils" - "log" - "os" - "testing" - "time" -) - -const platformSnap = "edgexfoundry" - -func platformPortsNoSec() []string { - return []string{ - utils.ServicePort("core-data"), - utils.ServicePort("core-metadata"), - utils.ServicePort("core-command"), - utils.ServicePort("consul"), - utils.ServicePort("redis"), - } -} - -func TestMain(m *testing.M) { - teardown, err := setup() - if err != nil { - log.Fatalf("Failed to setup tests: %s", err) - } - - code := m.Run() - teardown() - - os.Exit(code) -} - -func TestCommon(t *testing.T) { - utils.TestNet(t, platformSnap, utils.Net{ - StartSnap: false, // the service are started by default - TestOpenPorts: platformPortsNoSec(), - TestBindLoopback: platformPortsNoSec(), - }) -} - -func setup() (teardown func(), err error) { - log.Println("[CLEAN]") - utils.SnapRemove(nil, platformSnap) - - log.Println("[SETUP]") - start := time.Now() - - teardown = func() { - log.Println("[TEARDOWN]") - utils.SnapDumpLogs(nil, start, platformSnap) - - log.Println("Removing installed snap:", !utils.SkipTeardownRemoval) - if !utils.SkipTeardownRemoval { - utils.SnapRemove(nil, platformSnap) - } - } - - if utils.LocalPlatformSnap() { - err = utils.SnapInstallFromFile(nil, utils.LocalPlatformSnapPath) - } else { - err = utils.SnapInstallFromStore(nil, platformSnap, utils.PlatformChannel) - } - if err != nil { - teardown() - return - } - - // disable security - this sets autostart of security services to false - utils.SnapSet(nil, platformSnap, "security", "false") - - // enable autostart globally to start all services apart from security services that are explicitly disabled: - utils.SnapSet(nil, platformSnap, "autostart", "true") - // The above is equivalent to starting non-security services manually: - // utils.SnapStart(nil, func() (names []string) { - // nonSecServices := []string{ - // "consul", "redis", - // "core-common-config-bootstrapper", - // "core-data", "core-metadata", "core-command", - // "support-scheduler", "support-notifications", - // } - // for _, s := range nonSecServices { - // names = append(names, "edgexfoundry."+s) - // } - // return - // }()...) - - // make sure all services are online before starting the tests - if err = utils.WaitServiceOnline(nil, 180, platformPortsNoSec()...); err != nil { - teardown() - return - } - - return -} diff --git a/test/suites/edgex-no-sec/status_test.go b/test/suites/edgex-no-sec/status_test.go deleted file mode 100644 index 103276b..0000000 --- a/test/suites/edgex-no-sec/status_test.go +++ /dev/null @@ -1,36 +0,0 @@ -package test - -import ( - "edgex-snap-testing/test/utils" - "github.com/stretchr/testify/require" - "net/http" - "testing" -) - -func TestServiceStatus(t *testing.T) { - t.Run("security services", func(t *testing.T) { - var securityServices = []string{ - "nginx", "vault", - "security-bootstrapper-nginx", - "security-bootstrapper-redis", - "security-consul-bootstrapper", - "security-proxy-auth", - "security-secretstore-setup", - } - - for _, service := range securityServices { - require.False(t, utils.SnapServicesEnabled(t, "edgexfoundry."+service)) - require.False(t, utils.SnapServicesActive(t, "edgexfoundry."+service)) - } - }) -} - -func TestAccess(t *testing.T) { - t.Run("consul", func(t *testing.T) { - t.Log("Access Consul locally") - resp, err := http.Get("http://localhost:8500/v1/kv/edgex/v3/core-data/Service/Port") - require.NoError(t, err) - defer resp.Body.Close() - require.Equal(t, 200, resp.StatusCode) - }) -} diff --git a/test/suites/edgexfoundry/.gitignore b/test/suites/edgexfoundry/.gitignore deleted file mode 100644 index f1edfb1..0000000 --- a/test/suites/edgexfoundry/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -ca.cert -ca.key -server.csr diff --git a/test/suites/edgexfoundry/config_test.go b/test/suites/edgexfoundry/config_test.go deleted file mode 100644 index 7497911..0000000 --- a/test/suites/edgexfoundry/config_test.go +++ /dev/null @@ -1,92 +0,0 @@ -package test - -import ( - "edgex-snap-testing/test/utils" - "testing" - "time" -) - -const supportSchedulerStartupMsg = "This is the Support Scheduler Microservice" - -func TestChangeStartupMsg(t *testing.T) { - revertCP := utils.DoNotUseConfigProviderPlatformSnap(t, platformSnap, supportSchedulerApp) - - t.Cleanup(func() { - revertCP() - utils.SnapRestart(t, supportSchedulerService) - }) - - testChangeStartupMsg_app(t) - testChangeStartupMsg_global(t) - testChangeStartupMsg_mixedGlobalApp(t) -} - -func testChangeStartupMsg_app(t *testing.T) { - t.Run("app", func(t *testing.T) { - const ( - newStartupMsg = "snap-testing (app)" - startupMsgKey = "apps.support-scheduler.config.service-startupmsg" - ) - - t.Log("Set and verify new startup message:", newStartupMsg) - utils.SnapSet(t, platformSnap, startupMsgKey, newStartupMsg) - ts := time.Now() - utils.SnapRestart(t, supportSchedulerService) - - utils.WaitForLogMessage(t, supportSchedulerService, `msg="`+newStartupMsg+`"`, ts) - - t.Log("Unset and check default message") - utils.SnapUnset(t, platformSnap, startupMsgKey) - ts = time.Now() - utils.SnapRestart(t, supportSchedulerService) - utils.WaitForLogMessage(t, supportSchedulerService, `msg="`+supportSchedulerStartupMsg+`"`, ts) - }) -} - -func testChangeStartupMsg_global(t *testing.T) { - t.Run("global", func(t *testing.T) { - const ( - newStartupMsg = "snap-testing (global)" - startupMsgKey = "config.service-startupmsg" - ) - - t.Log("Set and verify new startup message:", newStartupMsg) - utils.SnapSet(t, platformSnap, startupMsgKey, newStartupMsg) - ts := time.Now() - utils.SnapRestart(t, supportSchedulerService) - - utils.WaitForLogMessage(t, supportSchedulerService, `msg="`+newStartupMsg+`"`, ts) - - t.Log("Unset and check default message") - utils.SnapUnset(t, platformSnap, startupMsgKey) - ts = time.Now() - utils.SnapRestart(t, supportSchedulerService) - utils.WaitForLogMessage(t, supportSchedulerService, `msg="`+supportSchedulerStartupMsg+`"`, ts) - }) -} - -func testChangeStartupMsg_mixedGlobalApp(t *testing.T) { - t.Run("mixedGlobalApp", func(t *testing.T) { - const ( - appNewStartupMsg = "snap-testing (app specific)" - appStartupMsgKey = "apps." + supportSchedulerApp + ".config.service-startupmsg" - - globalNewStartupMsg = "snap-testing (global override)" - globalStartupMsgKey = "config.service-startupmsg" - ) - - t.Log("Set local and global startup messages and verify that local has taken precedence") - utils.SnapSet(t, platformSnap, appStartupMsgKey, appNewStartupMsg) - utils.SnapSet(t, platformSnap, globalStartupMsgKey, globalNewStartupMsg) - ts := time.Now() - utils.SnapRestart(t, supportSchedulerService) - utils.WaitForLogMessage(t, supportSchedulerService, `msg="`+appNewStartupMsg+`"`, ts) - - t.Log("Unset and check default message") - utils.SnapUnset(t, platformSnap, appStartupMsgKey) - utils.SnapUnset(t, platformSnap, globalStartupMsgKey) - ts = time.Now() - utils.SnapRestart(t, supportSchedulerService) - utils.WaitForLogMessage(t, supportSchedulerService, `msg="`+supportSchedulerStartupMsg+`"`, ts) - }) -} diff --git a/test/suites/edgexfoundry/main_test.go b/test/suites/edgexfoundry/main_test.go deleted file mode 100644 index 23910a4..0000000 --- a/test/suites/edgexfoundry/main_test.go +++ /dev/null @@ -1,87 +0,0 @@ -package test - -import ( - "edgex-snap-testing/test/utils" - "log" - "os" - "testing" - "time" -) - -const ( - platformSnap = "edgexfoundry" - supportSchedulerApp = "support-scheduler" - supportSchedulerService = platformSnap + "." + supportSchedulerApp -) - -func TestMain(m *testing.M) { - teardown, err := setup() - if err != nil { - log.Fatalf("Failed to setup tests: %s", err) - } - - code := m.Run() - teardown() - - os.Exit(code) -} - -func TestCommon(t *testing.T) { - - // The common config tests aren't used - // - TestAppConfig is covered in local startup message testing - // - TestGlobalConfig and TestMixedGlobalAppConfig can't be used because this - // snap multiple servers, test setting startup message instead - // - TestAutostart testing fails (unknown reason) - // utils.TestConfig(t, platformSnap, utils.Config{ - // TestAutoStart: true, - // }) - - utils.TestNet(t, platformSnap, utils.Net{ - StartSnap: false, // the service are started by default - TestOpenPorts: utils.PlatformPorts(true), - TestBindLoopback: utils.PlatformPorts(false), // exclude public ports - }) - - utils.TestPackaging(t, platformSnap, utils.Packaging{ - TestSemanticSnapVersion: true, - }) -} - -func setup() (teardown func(), err error) { - log.Println("[CLEAN]") - utils.SnapRemove(nil, platformSnap) - - log.Println("[SETUP]") - start := time.Now() - - teardown = func() { - log.Println("[TEARDOWN]") - utils.SnapDumpLogs(nil, start, platformSnap) - - log.Println("Removing installed snap:", !utils.SkipTeardownRemoval) - if !utils.SkipTeardownRemoval { - utils.SnapRemove(nil, platformSnap) - } - } - - if utils.LocalPlatformSnap() { - err = utils.SnapInstallFromFile(nil, utils.LocalPlatformSnapPath) - } else { - err = utils.SnapInstallFromStore(nil, platformSnap, utils.PlatformChannel) - } - if err != nil { - teardown() - return - } - - utils.SnapStart(nil, platformSnap) - - // make sure all services are online before starting the tests - if err = utils.WaitPlatformOnline(nil); err != nil { - teardown() - return - } - - return -} diff --git a/test/suites/edgexfoundry/refresh/refresh_test.go b/test/suites/edgexfoundry/refresh/refresh_test.go deleted file mode 100644 index 8f28dd0..0000000 --- a/test/suites/edgexfoundry/refresh/refresh_test.go +++ /dev/null @@ -1,12 +0,0 @@ -package test - -import ( - "edgex-snap-testing/test/utils" - "testing" -) - -const platformSnap = "edgexfoundry" - -func TestCommon(t *testing.T) { - utils.TestRefresh(t, platformSnap) -} diff --git a/test/suites/edgexfoundry/secrets_config_test.go b/test/suites/edgexfoundry/secrets_config_test.go deleted file mode 100644 index 2b7dde1..0000000 --- a/test/suites/edgexfoundry/secrets_config_test.go +++ /dev/null @@ -1,80 +0,0 @@ -package test - -import ( - "crypto/tls" - "fmt" - "io/ioutil" - "net/http" - "os" - "strings" - "testing" - "time" - - "edgex-snap-testing/test/utils" - "github.com/stretchr/testify/require" -) - -const coreDataPingEndpoint = "https://localhost:8443/core-data/api/v3/ping" - -// TestAddAPIGatewayUser creates an example user, generates a JWT token for this user, -// and then accesses the core-data service via the API gateway using the JWT token. -// https://docs.edgexfoundry.org/3.0/getting-started/Ch-GettingStartedSnapUsers/#adding-api-gateway-users -func TestAddAPIGatewayUser(t *testing.T) { - t.Log("Create an example user and generate a JWT token") - idToken := utils.LoginTestUser(t) - - t.Log("Calling on behalf of example user:", coreDataPingEndpoint) - - req, err := http.NewRequest("GET", coreDataPingEndpoint, nil) - require.NoError(t, err) - - req.Header.Set("Authorization", "Bearer "+idToken) - - // InsecureSkipVerify because the API Gateway uses the built-in self-signed certificate - client := &http.Client{ - Transport: &http.Transport{ - TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, - }, - } - - resp, err := client.Do(req) - require.NoError(t, err) - defer resp.Body.Close() - require.Equal(t, 200, resp.StatusCode, "Unexpected HTTP response") - - body, err := ioutil.ReadAll(resp.Body) - require.NoError(t, err) - t.Logf("Output: %s", body) -} - -// TestChangeTLSCert creats new TLS certificate and calls API gateway to verify the use of new certificate -// https://docs.edgexfoundry.org/3.0/getting-started/Ch-GettingStartedSnapUsers/#changing-tls-certificates -func TestChangeTLSCert(t *testing.T) { - const tmpDir = "./tmp" - t.Cleanup(func() { - require.NoError(t, os.RemoveAll(tmpDir)) - }) - - t.Log("Create TLS certificate") - createTLSCert(t) - - t.Log("Calling API gateway using new TLS certificates:", coreDataPingEndpoint) - time.Sleep(5 * time.Second) - - const caCertFile = tmpDir + "/ca.cert" - // Note: %% is a literal percent sign - // Note: The ca.cert file is created by create-tls-certificates.sh - code, _, _ := utils.Exec(t, fmt.Sprintf( - "curl --verbose --show-error --silent --include --output /dev/null --write-out '%%{http_code}' --cacert %s '%s'", - caCertFile, - coreDataPingEndpoint)) - - // A success response should return status 401 because the endpoint is protected. - require.Equal(t, "401", strings.TrimSpace(code)) -} - -func createTLSCert(t *testing.T) { - // The script path relative to the testing suites - const createLtsCert = "../../scripts/create-tls-certificates.sh" - utils.Exec(t, createLtsCert) -} diff --git a/test/suites/ekuiper/config_test.go b/test/suites/ekuiper/config_test.go deleted file mode 100644 index c562b99..0000000 --- a/test/suites/ekuiper/config_test.go +++ /dev/null @@ -1,55 +0,0 @@ -package test - -import ( - "edgex-snap-testing/test/utils" - "testing" - "time" -) - -func TestConfigOption(t *testing.T) { - const ( - // eKuiper will be configured to use this port to connect to Redis - newPort = "11111" - portKey = "config.edgex.default.port" - ) - - var defaultRedisPort = utils.ServicePort("redis") - - t.Cleanup(func() { - utils.SnapUnset(t, ekuiperSnap, portKey) - utils.SnapStop(t, ekuiperSnap) - }) - - t.Run("Test config option", func(t *testing.T) { - t.Logf("Set EdgeX Redis Message bus port to %s and verify", newPort) - utils.SnapSet(t, ekuiperSnap, portKey, newPort) - startTime := time.Now() - utils.SnapStart(t, ekuiperSnap) - - utils.WaitServiceOnline(t, 60, - utils.ServicePort(ekuiperApp), - utils.ServicePort(ekuiperRestfulApi), - ) - - t.Log("Creating stream and rule to trigger the process of applying config option in edgex-ekuiper") - utils.Exec(t, `edgex-ekuiper.kuiper create stream stream1 '()WITH(FORMAT="JSON",TYPE="edgex")'`) - utils.Exec(t, - `edgex-ekuiper.kuiper create rule rule_log ' - { - "sql":"SELECT * FROM stream1 WHERE meta(deviceName) != \"device-test\"", - "actions":[ - { - "log":{} - } - ] - }'`) - - utils.WaitForLogMessage(t, ekuiperSnap, "port:"+newPort, startTime) - - t.Log("Unset and check default port") - utils.SnapUnset(t, ekuiperSnap, portKey) - startTime = time.Now() - utils.SnapRestart(t, ekuiperSnap) - utils.WaitForLogMessage(t, ekuiperSnap, "port:"+defaultRedisPort, startTime) - }) -} diff --git a/test/suites/ekuiper/main_test.go b/test/suites/ekuiper/main_test.go deleted file mode 100644 index 8c1896b..0000000 --- a/test/suites/ekuiper/main_test.go +++ /dev/null @@ -1,139 +0,0 @@ -package test - -import ( - "edgex-snap-testing/test/utils" - "log" - "os" - "testing" - "time" -) - -const ( - platformSnap = "edgexfoundry" - - ekuiperSnap = "edgex-ekuiper" - ekuiperApp = "ekuiper" - ekuiperRestfulApi = "ekuiper/rest-api" - - deviceVirtualSnap = "edgex-device-virtual" - deviceVirtualApp = "device-virtual" -) - -var ( - ekuiperPort = utils.ServicePort(ekuiperApp) - ekuiperRestfulPort = utils.ServicePort(ekuiperRestfulApi) -) - -var testSecretsInterface bool - -func TestMain(m *testing.M) { - teardown, err := setup() - if err != nil { - log.Fatalf("Failed to setup tests: %s", err) - } - - // set profile to rules engine - testSecretsInterface = true - - code := m.Run() - teardown() - - os.Exit(code) -} - -func TestCommon(t *testing.T) { - utils.TestContentInterfaces(t, utils.ContentInterfaces{ - TestSecretstoreToken: testSecretsInterface, - Snap: ekuiperSnap, - App: ekuiperSnap, - }) - - utils.TestConfig(t, ekuiperSnap, utils.Config{ - TestAutoStart: true, - }) - - utils.TestNet(t, ekuiperSnap, utils.Net{ - StartSnap: true, - TestOpenPorts: []string{ekuiperPort, ekuiperRestfulPort}, - TestBindLoopback: []string{ekuiperPort, ekuiperRestfulPort}, - }) - - utils.TestPackaging(t, ekuiperSnap, utils.Packaging{ - TestSemanticSnapVersion: true, - }) -} - -func setup() (teardown func(), err error) { - log.Println("[CLEAN]") - utils.SnapRemove(nil, - ekuiperSnap, - platformSnap, - deviceVirtualSnap, - ) - - log.Println("[SETUP]") - start := time.Now() - - teardown = func() { - log.Println("[TEARDOWN]") - - utils.SnapDumpLogs(nil, start, ekuiperSnap) - utils.SnapDumpLogs(nil, start, platformSnap) - utils.SnapDumpLogs(nil, start, deviceVirtualSnap) - - log.Println("Removing installed snap:", !utils.SkipTeardownRemoval) - if !utils.SkipTeardownRemoval { - utils.SnapRemove(nil, - ekuiperSnap, - platformSnap, - deviceVirtualSnap, - ) - } - } - - // install the ekuiper snap before edgexfoundry - // to catch build error sooner and stop - if utils.LocalServiceSnap() { - err = utils.SnapInstallFromFile(nil, utils.LocalServiceSnapPath) - } else { - err = utils.SnapInstallFromStore(nil, ekuiperSnap, utils.ServiceChannel) - } - if err != nil { - teardown() - return - } - - if utils.LocalPlatformSnap() { - err = utils.SnapInstallFromFile(nil, utils.LocalPlatformSnapPath) - } else { - err = utils.SnapInstallFromStore(nil, platformSnap, utils.PlatformChannel) - } - if err != nil { - teardown() - return - } - - if err = utils.SnapInstallFromStore(nil, deviceVirtualSnap, utils.ServiceChannel); err != nil { - teardown() - return - } - - // for local build, the interface isn't auto-connected. - // connect manually - if utils.LocalServiceSnap() { - if err = utils.SnapConnectSecretstoreToken(nil, ekuiperSnap); err != nil { - teardown() - return - } - } - - utils.SnapStart(nil, platformSnap) - - // make sure all services are online before starting the tests - if err = utils.WaitPlatformOnline(nil); err != nil { - teardown() - return - } - - return -} diff --git a/test/suites/ekuiper/streams_rules_test.go b/test/suites/ekuiper/streams_rules_test.go deleted file mode 100644 index 7786090..0000000 --- a/test/suites/ekuiper/streams_rules_test.go +++ /dev/null @@ -1,130 +0,0 @@ -package test - -import ( - "edgex-snap-testing/test/utils" - "encoding/json" - "net/http" - "testing" - "time" - - "github.com/stretchr/testify/require" -) - -type Reading struct { - TotalCount int `json:"totalCount"` -} - -type RuleStatus struct { - LogCount int `json:"sink_log_0_0_records_out_total"` -} - -func TestStreamsAndRules(t *testing.T) { - t.Cleanup(func() { - utils.SnapStop(t, - ekuiperSnap, - deviceVirtualSnap) - }) - - utils.SnapStart(t, - ekuiperSnap, - deviceVirtualSnap) - - t.Run("create stream", func(t *testing.T) { - utils.Exec(t, `edgex-ekuiper.kuiper create stream stream1 '()WITH(FORMAT="JSON",TYPE="edgex")'`) - }) - - t.Run("create rule_log", func(t *testing.T) { - utils.Exec(t, - `edgex-ekuiper.kuiper create rule rule_log ' - { - "sql":"SELECT * FROM stream1 WHERE meta(deviceName) != \"device-test\"", - "actions":[ - { - "log":{} - } - ] - }'`) - }) - - t.Run("create rule_edgex_message_bus", func(t *testing.T) { - utils.Exec(t, - `edgex-ekuiper.kuiper create rule rule_edgex_message_bus ' - { - "sql":"SELECT * FROM stream1 WHERE meta(deviceName) != \"device-test\"", - "actions": [ - { - "edgex": { - "connectionSelector": "edgex.redisMsgBus", - "topicPrefix": "edgex/events/device", - "messageType": "request", - "deviceName": "device-test" - } - } - ] - }'`) - }) - - // wait device-virtual to come online and produce readings - if err := utils.WaitServiceOnline(t, 60, utils.ServicePort(deviceVirtualApp)); err != nil { - t.Fatal(err) - } - utils.WaitForReadings(t, "Random-Integer-Device", true) - - t.Run("check rule_log", func(t *testing.T) { - var ruleStatus RuleStatus - - // waiting for readings to come from edgex to ekuiper - for i := 1; ; i++ { - time.Sleep(1 * time.Second) - resp, err := http.Get("http://localhost:59720/rules/rule_log/status") - if err != nil { - t.Fatal(err) - } - defer resp.Body.Close() - - if err := json.NewDecoder(resp.Body).Decode(&ruleStatus); err != nil { - t.Fatal(err) - } - - t.Logf("Waiting for readings to come from edgex to ekuiper, current retry count: %d/60", i) - - if i <= 60 && ruleStatus.LogCount > 0 { - t.Logf("Readings are coming to ekuiper now") - break - } - - if i > 60 && ruleStatus.LogCount <= 0 { - t.Logf("Waiting for readings to come from edgex to ekuiper, reached maximum retry count of 60") - break - } - } - - require.Greaterf(t, ruleStatus.LogCount, 0, "No readings have been published to log by ekuiper") - }) - - t.Run("check rule_edgex_message_bus", func(t *testing.T) { - // wait device-virtual to come online and produce readings - if err := utils.WaitServiceOnline(t, 60, utils.ServicePort(deviceVirtualApp)); err != nil { - t.Fatal(err) - } - - req, err := http.NewRequest(http.MethodGet, "http://localhost:59880/api/v3/reading/device/name/device-test", nil) - require.NoError(t, err) - - idToken := utils.LoginTestUser(t) - req.Header.Set("Authorization", "Bearer "+idToken) - - var reading Reading - client := &http.Client{} - resp, err := client.Do(req) - - require.NoError(t, err) - defer resp.Body.Close() - - if err = json.NewDecoder(resp.Body).Decode(&reading); err != nil { - t.Fatal(err) - } - - require.Greaterf(t, reading.TotalCount, 0, "No readings have been re-published to EdgeX message bus by ekuiper") - }) -} diff --git a/test/suites/ui/main_test.go b/test/suites/ui/main_test.go deleted file mode 100644 index 7fc8cd3..0000000 --- a/test/suites/ui/main_test.go +++ /dev/null @@ -1,68 +0,0 @@ -package test - -import ( - "edgex-snap-testing/test/utils" - "log" - "os" - "testing" - "time" -) - -const ( - uiSnap = "edgex-ui" - uiApp = "ui" -) - -func TestMain(m *testing.M) { - teardown, err := setup() - if err != nil { - log.Fatalf("Failed to setup tests: %s", err) - } - - code := m.Run() - teardown() - - os.Exit(code) -} - -func TestCommon(t *testing.T) { - utils.TestNet(t, uiSnap, utils.Net{ - StartSnap: true, - TestOpenPorts: []string{utils.ServicePort(uiApp)}, - TestBindLoopback: []string{utils.ServicePort(uiApp)}, - }) - - utils.TestPackaging(t, uiSnap, utils.Packaging{ - TestSemanticSnapVersion: true, - }) -} - -func setup() (teardown func(), err error) { - log.Println("[CLEAN]") - utils.SnapRemove(nil, uiSnap) - - log.Println("[SETUP]") - start := time.Now() - - teardown = func() { - log.Println("[TEARDOWN]") - utils.SnapDumpLogs(nil, start, uiSnap) - - log.Println("Removing installed snap:", !utils.SkipTeardownRemoval) - if !utils.SkipTeardownRemoval { - utils.SnapRemove(nil, uiSnap) - } - } - - if utils.LocalServiceSnap() { - err = utils.SnapInstallFromFile(nil, utils.LocalServiceSnapPath) - } else { - err = utils.SnapInstallFromStore(nil, uiSnap, utils.ServiceChannel) - } - if err != nil { - teardown() - return - } - - return -} diff --git a/test/utils/config.go b/test/utils/config.go index aa6543c..af0284f 100644 --- a/test/utils/config.go +++ b/test/utils/config.go @@ -9,152 +9,15 @@ import ( ) type Config struct { - TestChangePort ConfigChangePort TestAutoStart bool } -type ConfigChangePort struct { - App string - DefaultPort string - TestAppConfig bool - TestGlobalConfig bool - TestMixedGlobalAppConfig bool -} - -const serviceWaitTimeout = 60 // seconds - func TestConfig(t *testing.T, snapName string, conf Config) { t.Run("config", func(t *testing.T) { - TestChangePort(t, snapName, conf.TestChangePort) TestAutoStart(t, snapName, conf.TestAutoStart) }) } -func TestChangePort(t *testing.T, snapName string, conf ConfigChangePort) { - if conf.TestAppConfig || conf.TestGlobalConfig || conf.TestMixedGlobalAppConfig { - t.Run("change service port", func(t *testing.T) { - - // start once so that default configs get uploaded to the registry - service := snapName + "." + conf.App - SnapStart(t, service) - WaitServiceOnline(t, serviceWaitTimeout, conf.DefaultPort) - SnapStop(t, service) - - if conf.TestAppConfig { - testChangePort_app(t, snapName, conf.App, conf.DefaultPort) - } - if conf.TestGlobalConfig { - testChangePort_global(t, snapName, conf.App, conf.DefaultPort) - } - if conf.TestMixedGlobalAppConfig { - testChangePort_mixedGlobalApp(t, snapName, conf.App, conf.DefaultPort) - } - }) - } -} - -func testChangePort_app(t *testing.T, snap, app, servicePort string) { - t.Run("app config", func(t *testing.T) { - service := snap + "." + app - - // start clean - SnapStop(t, service) - - t.Cleanup(func() { - SnapUnset(t, snap, "apps") - SnapStop(t, service) - }) - - const newPort = "22222" - - // make sure the port is available before using it - RequirePortAvailable(t, newPort) - - DoNotUseConfigProviderServiceSnap(t, snap, app) - - // set apps. and validate the new port comes online - SnapSet(t, snap, "apps."+app+".config.service-port", newPort) - SnapStart(t, service) - - WaitServiceOnline(t, serviceWaitTimeout, newPort) - - // unset apps. and validate the default port comes online - SnapUnset(t, snap, "apps."+app+".config.service-port") - SnapRestart(t, service) - - WaitServiceOnline(t, serviceWaitTimeout, servicePort) - }) -} - -func testChangePort_global(t *testing.T, snap, app, servicePort string) { - t.Run("global config", func(t *testing.T) { - service := snap + "." + app - - // start clean - SnapStop(t, service) - - t.Cleanup(func() { - SnapUnset(t, snap, "config") - SnapStop(t, service) - }) - - const newPort = "33333" - - // make sure the port is available before using it - RequirePortAvailable(t, newPort) - - DoNotUseConfigProviderServiceSnap(t, snap, app) - - // set config. and validate the new port comes online - SnapSet(t, snap, "config.service-port", newPort) - SnapStart(t, service) - - WaitServiceOnline(t, serviceWaitTimeout, newPort) - - // unset config. and validate the default port comes online - SnapUnset(t, snap, "config.service-port") - SnapRestart(t, service) - - WaitServiceOnline(t, serviceWaitTimeout, servicePort) - }) -} - -func testChangePort_mixedGlobalApp(t *testing.T, snap, app, servicePort string) { - t.Run("app+global config for different values", func(t *testing.T) { - service := snap + "." + app - - if !FullConfigTest { - t.Skip("Full config test is disabled.") - } - // start clean - SnapStop(t, service) - - t.Cleanup(func() { - SnapUnset(t, snap, "apps") - SnapUnset(t, snap, "config") - SnapStop(t, service) - }) - - const newAppPort = "44444" - const newConfigPort = "55555" - - // make sure the ports are available before using it - RequirePortAvailable(t, newAppPort) - RequirePortAvailable(t, newConfigPort) - - DoNotUseConfigProviderServiceSnap(t, snap, app) - - // set apps. and config. with different values, - // and validate that app-specific option has been picked up because it has higher precedence - SnapSet(t, snap, "apps."+app+".config.service-port", newAppPort) - SnapSet(t, snap, "config.service-port", newConfigPort) - SnapStart(t, service) - - WaitServiceOnline(t, serviceWaitTimeout, newAppPort) - }) - -} - func TestAutoStart(t *testing.T, snapName string, testAutoStart bool) { if testAutoStart { t.Run("autostart", func(t *testing.T) { @@ -188,41 +51,9 @@ func TestAutostartGlobal(t *testing.T, snapName string) { }) } -// DoNotUseConfigProviderPlatformSnap disables the config provider for the specified app -// and sets the common configuration path -func DoNotUseConfigProviderPlatformSnap(t *testing.T, snap, app string) (revert func()) { - t.Logf("Configure %s to not use Config Provider", app) - - SnapSet(t, snap, "apps."+app+".config.edgex-config-provider", "none") - SnapSet(t, snap, "apps."+app+".config.edgex-common-config", "./config/core-common-config-bootstrapper/res/configuration.yaml") - - return func() { - t.Log("Revert to use Config Provider as usual") - SnapUnset(t, snap, "apps."+app+".config.edgex-config-provider") - SnapUnset(t, snap, "apps."+app+".config.edgex-common-config") - } -} - -// DoNotUseConfigProviderServiceSnap disables the config provider for the specified app, -// copies the common configuration file from the platform snap to the service snap, -// and sets the common configuration path. -func DoNotUseConfigProviderServiceSnap(t *testing.T, snap, app string) { - SnapSet(t, snap, "apps."+app+".config.edgex-config-provider", "none") - - t.Logf("Copying common config file from platform snap to service snap: %s", snap) - - sourceFile := "/snap/edgexfoundry/current/config/core-common-config-bootstrapper/res/configuration.yaml" - destFile := "/var/snap/" + snap + "/current/config/common-config.yaml" - Exec(t, "sudo cp "+sourceFile+" "+destFile) - - SnapSet(t, snap, "apps."+app+".config.edgex-common-config", destFile) -} - func WaitForLogMessage(t *testing.T, snap, expectedLog string, since time.Time) { const maxRetry = 10 - WaitPlatformOnline(t) - for i := 1; i <= maxRetry; i++ { time.Sleep(1 * time.Second) t.Logf("Retry %d/%d: Waiting for expected content in logs: %s", i, maxRetry, expectedLog) diff --git a/test/utils/content_interfaces.go b/test/utils/content_interfaces.go deleted file mode 100644 index 2d457fe..0000000 --- a/test/utils/content_interfaces.go +++ /dev/null @@ -1,35 +0,0 @@ -package utils - -import ( - "testing" - - "github.com/stretchr/testify/require" -) - -type ContentInterfaces struct { - TestSecretstoreToken bool - TestConfigProvider bool - Snap string - App string -} - -func TestContentInterfaces(t *testing.T, conf ContentInterfaces) { - t.Run("content interfaces", func(t *testing.T) { - if conf.TestSecretstoreToken { - TestSeedSecretstoreToken(t, conf.Snap, conf.App) - } - if conf.TestConfigProvider { - t.Skip("TODO") - } - }) -} - -func TestSeedSecretstoreToken(t *testing.T, consumerName, consumerAppName string) { - t.Run("seed secretstore token", func(t *testing.T) { - providerSecret, _, _ := Exec(t, "sudo cat /var/snap/edgexfoundry/current/secrets/"+consumerAppName+"/secrets-token.json") - consumerSecret, _, _ := Exec(t, "sudo cat /var/snap/"+consumerName+"/current/"+consumerAppName+"/secrets-token.json") - require.NotEmpty(t, providerSecret) - - require.Equal(t, providerSecret, consumerSecret) - }) -} diff --git a/test/utils/env.go b/test/utils/env.go index de4866c..9ad2c45 100644 --- a/test/utils/env.go +++ b/test/utils/env.go @@ -8,50 +8,28 @@ import ( const ( // environment variables // used to override defaults - platformChannelEnv = "PLATFORM_CHANNEL" // channel/revision of the edgexfoundry snap (has default) serviceChannelEnv = "SERVICE_CHANNEL" // channel/revision of the service snap (has default) - localPlatformSnapEnv = "LOCAL_PLATFORM_SNAP" // path to local platform snap to be tested instead of downloading from a channel localServiceSnapEnv = "LOCAL_SERVICE_SNAP" // path to local service snap to be tested instead of downloading from a channel - fullConfigTestEnv = "FULL_CONFIG_TEST" // toggle full config tests (has default) skipTeardownRemovalEnv = "SKIP_TEARDOWN_REMOVAL" // skip the removal of snaps during teardown ) var ( // global defaults - PlatformChannel = "latest/edge" ServiceChannel = "latest/edge" - LocalPlatformSnapPath = "" LocalServiceSnapPath = "" - FullConfigTest = false SkipTeardownRemoval = false ) func init() { - if v := os.Getenv(platformChannelEnv); v != "" { - PlatformChannel = v - } - if v := os.Getenv(serviceChannelEnv); v != "" { ServiceChannel = v } - if v := os.Getenv(localPlatformSnapEnv); v != "" { - LocalPlatformSnapPath = v - } - if v := os.Getenv(localServiceSnapEnv); v != "" { LocalServiceSnapPath = v } - if v := os.Getenv(fullConfigTestEnv); v != "" { - var err error - FullConfigTest, err = strconv.ParseBool(v) - if err != nil { - panic(err) - } - } - if v := os.Getenv(skipTeardownRemovalEnv); v != "" { var err error SkipTeardownRemoval, err = strconv.ParseBool(v) diff --git a/test/utils/login.go b/test/utils/login.go deleted file mode 100644 index c672370..0000000 --- a/test/utils/login.go +++ /dev/null @@ -1,15 +0,0 @@ -package utils - -import ( - "strings" - "testing" -) - -func LoginTestUser(t *testing.T) (idToken string) { - // The script path relative to the testing suites - const loginScriptPath = "../../scripts/login-test-user.sh" - - idToken, _, _ = Exec(t, loginScriptPath) - t.Log("ID Token for 'example' user:", idToken) - return strings.TrimSpace(idToken) -} diff --git a/test/utils/net.go b/test/utils/net.go index 4034947..7f607b9 100644 --- a/test/utils/net.go +++ b/test/utils/net.go @@ -18,36 +18,8 @@ type Net struct { const dialTimeout = 2 * time.Second var portService = map[string]string{ - // platform services - "59880": "core-data", - "59881": "core-metadata", - "59882": "core-command", - "8000": "nginx(http)", - "8443": "nginx(https)", - "8200": "vault", - "8500": "consul", - "6379": "redis", - "59861": "support-scheduler", - // app services - "59711": "app-rfid-llrp-inventory", - "59701": "app-service-configurable", - // security services - "59842": "security-proxy-auth", - // device services - "59910": "device-gpio", - "59901": "device-modbus", - "59982": "device-mqtt", - "59984": "device-onvif-camera", - "59986": "device-rest", - "59989": "device-rfid-llrp", - "59993": "device-snmp", - "59983": "device-usb-camera", - "8554": "device-usb-camera/rtsp", - "59900": "device-virtual", - // others - "20498": "ekuiper", - "59720": "ekuiper/rest-api", - "4000": "ui", + // matter controller + "5550": "chip-tool", } // servicePort looks up the service port by app name @@ -60,26 +32,6 @@ func ServicePort(serviceName string) string { panic("Found no port number for service: " + serviceName) } -func PlatformPorts(includePublicPorts bool) (ports []string) { - ports = append(ports, - ServicePort("core-data"), - ServicePort("core-metadata"), - ServicePort("core-command"), - ServicePort("vault"), - ServicePort("consul"), - ServicePort("redis"), - ServicePort("nginx(http)"), - ServicePort("security-proxy-auth"), - - ) - if includePublicPorts { - ports = append(ports, - ServicePort("nginx(https)"), - ) - } - return -} - func TestNet(t *testing.T, snapName string, conf Net) { t.Run("net", func(t *testing.T) { if conf.StartSnap { @@ -178,12 +130,6 @@ func WaitServiceOnline(t *testing.T, maxRetry int, ports ...string) error { return nil } -// WaitPlatformOnline waits for all platform ports to come online -// by dialing its port(s) up to a maximum number -func WaitPlatformOnline(t *testing.T) error { - return WaitServiceOnline(t, 180, PlatformPorts(true)...) -} - // requirePortOpen checks if the local port(s) accepts connections func requirePortOpen(t *testing.T, ports ...string) { if len(ports) == 0 { diff --git a/test/utils/readings.go b/test/utils/readings.go deleted file mode 100644 index e28ce0f..0000000 --- a/test/utils/readings.go +++ /dev/null @@ -1,58 +0,0 @@ -package utils - -import ( - "encoding/json" - "net/http" - "testing" - "time" - - "github.com/stretchr/testify/require" -) - -// WaitForReadings waits for readings to appear in core-data -// The readings are produced by device-virtual or another service -func WaitForReadings(t *testing.T, deviceName string, secured bool) { - var coreDataReadingCountEndpoint = "http://localhost:59880/api/v3/reading/count/device/name/" + deviceName - - t.Run("query readings count", func(t *testing.T) { - var eventCount struct { - Count int - } - - var idToken string - if secured { - idToken = LoginTestUser(t) - } - - for i := 1; ; i++ { - time.Sleep(1 * time.Second) - req, err := http.NewRequest(http.MethodGet, coreDataReadingCountEndpoint, nil) - require.NoError(t, err) - - if secured { - req.Header.Set("Authorization", "Bearer "+idToken) - } - - client := &http.Client{} - resp, err := client.Do(req) - require.NoError(t, err) - defer resp.Body.Close() - require.Equal(t, 200, resp.StatusCode, "Unexpected HTTP response") - - require.NoError(t, json.NewDecoder(resp.Body).Decode(&eventCount)) - - t.Logf("Waiting for readings in Core Data, current retry: %d/60", i) - - if i <= 60 && eventCount.Count > 0 { - t.Logf("Found readings in Core Data") - break - } - - if i > 60 && eventCount.Count <= 0 { - t.Logf("Waiting for readings in Core Data: reached maximum 60 retries") - break - } - } - require.Greaterf(t, eventCount.Count, 0, "No readings in Core Data") - }) -} diff --git a/test/utils/refresh.go b/test/utils/refresh.go index a23b383..39d7a4e 100644 --- a/test/utils/refresh.go +++ b/test/utils/refresh.go @@ -10,9 +10,6 @@ import ( // TestRefresh tests an EdgeX upgrade using snap refresh func TestRefresh(t *testing.T, snapName string) { t.Run("refresh", func(t *testing.T) { - if LocalPlatformSnap() { - t.Skip("Skip refresh for local snap build") - } const stableChannel = "latest/stable" @@ -29,8 +26,6 @@ func TestRefresh(t *testing.T, snapName string) { t.Cleanup(func() { SnapRemove(t, snapName) SnapInstallFromStore(t, snapName, ServiceChannel) - - WaitPlatformOnline(t) }) originalVersion := SnapVersion(t, snapName) @@ -40,7 +35,6 @@ func TestRefresh(t *testing.T, snapName string) { SnapRefresh(t, snapName, ServiceChannel) refreshVersion := SnapVersion(t, snapName) refreshRevision = SnapRevision(t, snapName) - WaitPlatformOnline(t) t.Logf("Successfully upgraded from %s (%s) to %s (%s)", originalVersion, originalRevision, refreshVersion, refreshRevision) diff --git a/test/utils/setup.go b/test/utils/setup.go index d694a7a..097856c 100644 --- a/test/utils/setup.go +++ b/test/utils/setup.go @@ -5,15 +5,12 @@ import ( "time" ) -const platformSnap = "edgexfoundry" - // SetupServiceTests setup up the environment for testing // It returns a teardown function to be called at the end of the tests func SetupServiceTests(snapName string) (teardown func(), err error) { log.Println("[CLEAN]") SnapRemove(nil, snapName, - platformSnap, ) log.Println("[SETUP]") @@ -22,19 +19,15 @@ func SetupServiceTests(snapName string) (teardown func(), err error) { teardown = func() { log.Println("[TEARDOWN]") SnapDumpLogs(nil, start, snapName) - SnapDumpLogs(nil, start, platformSnap) log.Println("Removing installed snap:", !SkipTeardownRemoval) if !SkipTeardownRemoval { SnapRemove(nil, snapName, - platformSnap, ) } } - // install the device/app service snap before edgexfoundry - // to catch build error sooner and stop if LocalServiceSnap() { err = SnapInstallFromFile(nil, LocalServiceSnapPath) } else { @@ -45,38 +38,5 @@ func SetupServiceTests(snapName string) (teardown func(), err error) { return } - if err = SnapInstallFromStore(nil, platformSnap, PlatformChannel); err != nil { - teardown() - return - } - - // install the edgexfoundry platform snap - if LocalPlatformSnap() { - err = SnapInstallFromFile(nil, LocalPlatformSnapPath) - } else { - err = SnapInstallFromStore(nil, snapName, PlatformChannel) - } - if err != nil { - teardown() - return - } - - // for local build, the interface isn't auto-connected. - // connect manually - if LocalServiceSnap() || LocalPlatformSnap() { - if err = SnapConnectSecretstoreToken(nil, snapName); err != nil { - teardown() - return - } - } - - SnapStart(nil, platformSnap) - - // make sure all services are online before starting the tests - if err = WaitPlatformOnline(nil); err != nil { - teardown() - return - } - return } diff --git a/test/utils/snap.go b/test/utils/snap.go index 9ca19fe..dd323f9 100644 --- a/test/utils/snap.go +++ b/test/utils/snap.go @@ -210,10 +210,6 @@ func SnapServicesActive(t *testing.T, name string) bool { return strings.TrimSpace(out) == "active" } -func LocalPlatformSnap() bool { - return LocalPlatformSnapPath != "" -} - func LocalServiceSnap() bool { return LocalServiceSnapPath != "" }