Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Release/v2.3.0 #50

Merged
merged 194 commits into from
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
194 commits
Select commit Hold shift + click to select a range
ba2d85c
payloads json
gabrielCamilleriCcbill May 9, 2022
b5b72b9
Added workflows
fybJenkins May 9, 2022
c93149d
Fix action
fybJenkins May 9, 2022
e18e323
Fixed upload artifact
fybJenkins May 9, 2022
ad899d4
Add changes
github-actions[bot] May 9, 2022
e1fb992
Removed existing generated files
fybJenkins May 9, 2022
acb5255
Updated ignore
fybJenkins May 9, 2022
f5deb3b
Add changes
github-actions[bot] May 9, 2022
ef3b6fd
Removed go.mod from ignore file
fybJenkins May 9, 2022
5d1513f
Merge branch 'feature/BMC-9505/setup-generation-workflows' of github.…
fybJenkins May 9, 2022
3761245
Add changes
github-actions[bot] May 9, 2022
08d0363
Added tidy command
fybJenkins May 9, 2022
0b38c48
Merge branch 'feature/BMC-9505/setup-generation-workflows' of github.…
fybJenkins May 9, 2022
86ffeed
Fixed an input
fybJenkins May 9, 2022
5762f52
Set generator to specific version
fybJenkins May 9, 2022
fca690c
Add changes
github-actions[bot] May 9, 2022
174e0da
test_utils implementation
gabrielCamilleriCcbill May 10, 2022
0521700
Removed extra details in README
fybJenkins May 10, 2022
c0e38fc
Merge branch 'feature/BMC-9505/setup-generation-workflows' of github.…
fybJenkins May 10, 2022
1edde89
Add changes
github-actions[bot] May 10, 2022
1df911e
Added GIT info for README
fybJenkins May 10, 2022
8ef2888
Merge branch 'feature/BMC-9505/setup-generation-workflows' of github.…
fybJenkins May 10, 2022
441d662
Add changes
github-actions[bot] May 10, 2022
5b224f7
Moved handlebar
fybJenkins May 10, 2022
209b2a3
Merge branch 'feature/BMC-9505/setup-generation-workflows' of github.…
fybJenkins May 10, 2022
5c59f5d
Add changes
github-actions[bot] May 10, 2022
81e898f
Updated template for other parameters
fybJenkins May 10, 2022
cffee63
Merge branch 'feature/BMC-9505/setup-generation-workflows' of github.…
fybJenkins May 10, 2022
d2c9f04
Add changes
github-actions[bot] May 10, 2022
4448f50
remove unwanted files
gabrielCamilleriCcbill May 10, 2022
5938ecc
Updated template
fybJenkins May 10, 2022
577c434
Merge branch 'feature/BMC-9505/setup-generation-workflows' of github.…
fybJenkins May 10, 2022
9da3f33
Add changes
github-actions[bot] May 10, 2022
f64f8ce
moved class name to proper file
gabrielCamilleriCcbill May 10, 2022
4416a4a
moved functions to belong to class
gabrielCamilleriCcbill May 10, 2022
7faa923
writing first audit test
gabrielCamilleriCcbill May 11, 2022
39fb716
writing test_get_events_all_query_params
gabrielCamilleriCcbill May 11, 2022
5623d64
merging jenkins' workflow branch into audit testing branch
gabrielCamilleriCcbill May 11, 2022
cac54a6
modifying test_utils and test_get_events
gabrielCamilleriCcbill May 13, 2022
5a51870
changed return type for test utils method
gabrielCamilleriCcbill May 13, 2022
01b4ad2
using interfaces instead of structs
gabrielCamilleriCcbill May 13, 2022
5672b0a
test_get_events_all_query_params impl
gabrielCamilleriCcbill May 13, 2022
41754d0
fixing test and its utils
gabrielCamilleriCcbill May 16, 2022
73d9e24
fixing test
gabrielCamilleriCcbill May 17, 2022
fc2e128
updated test utils
gabrielCamilleriCcbill May 18, 2022
eccf31b
Add changes
github-actions[bot] May 18, 2022
801082e
fixing test
gabrielCamilleriCcbill May 18, 2022
a19a96c
fixing query parameter
gabrielCamilleriCcbill May 18, 2022
a9880a5
tests finished
gabrielCamilleriCcbill May 18, 2022
7d9bb26
test utils impl finished (requires cleanup)
gabrielCamilleriCcbill May 18, 2022
77ec5de
Merge branch 'Feature/-setup-testing' of github.com:phoenixnap/go-sdk…
gabrielCamilleriCcbill May 18, 2022
2af3f23
reformat and cleanup code
gabrielCamilleriCcbill May 18, 2022
8d8481c
reformat code
gabrielCamilleriCcbill May 18, 2022
a83e969
Merge remote-tracking branch 'origin/develop' into Feature/-setup-tes…
gabrielCamilleriCcbill May 18, 2022
63d94e7
resolve conflicts
gabrielCamilleriCcbill May 18, 2022
7d1d7db
Merge remote-tracking branch 'origin/Feature/-setup-testing' into fea…
gabrielCamilleriCcbill May 18, 2022
0eed813
modified query params to make time parsable
gabrielCamilleriCcbill May 18, 2022
a017132
audit test cleanup
gabrielCamilleriCcbill May 18, 2022
1b0ca95
rename
gabrielCamilleriCcbill May 18, 2022
533ba13
tagsapi test init
gabrielCamilleriCcbill May 18, 2022
60f6a89
init test tags get
gabrielCamilleriCcbill May 18, 2022
370d365
reformatted and removed uneccessary file
gabrielCamilleriCcbill May 19, 2022
7ae77fb
Add changes
github-actions[bot] May 19, 2022
37600df
go mod changes and formats
gabrielCamilleriCcbill May 19, 2022
18a7498
addressed comment
gabrielCamilleriCcbill May 19, 2022
78242cb
Add changes
github-actions[bot] May 19, 2022
348e037
Revert "Add changes"
gabrielCamilleriCcbill May 19, 2022
1b93952
structs reformat
gabrielCamilleriCcbill May 19, 2022
6090ea6
Revert "go mod changes and formats"
gabrielCamilleriCcbill May 19, 2022
c57819f
setup and teardown
gabrielCamilleriCcbill May 19, 2022
e901379
removed method not being used
gabrielCamilleriCcbill May 19, 2022
9d2dc4b
fixed structs and test utils
gabrielCamilleriCcbill May 19, 2022
9deafa8
utils and structs updates
gabrielCamilleriCcbill May 19, 2022
7533546
Merge branch 'Feature/-setup-testing' of github.com:phoenixnap/go-sdk…
gabrielCamilleriCcbill May 19, 2022
12d2e3b
test utils and struct method spacing
gabrielCamilleriCcbill May 19, 2022
94b57d2
Merge branch 'Feature/-setup-testing' into feature/AuditApi-Testing
gabrielCamilleriCcbill May 19, 2022
26b7f1f
added method spacing
gabrielCamilleriCcbill May 19, 2022
d554185
added method spacing
gabrielCamilleriCcbill May 19, 2022
353cf62
Revert "Add changes"
gabrielCamilleriCcbill May 19, 2022
00dfc22
Add changes
github-actions[bot] May 19, 2022
ca1c14d
Merge branch 'Feature/-setup-testing' into Feature/Tags-Api-Testing
gabrielCamilleriCcbill May 19, 2022
5f40ce8
struct update
gabrielCamilleriCcbill May 19, 2022
b811ab4
updated test utils and structs
gabrielCamilleriCcbill May 19, 2022
075feec
test utils and struct updates
gabrielCamilleriCcbill May 19, 2022
f9a0ee0
Merge branch 'Feature/-setup-testing' of github.com:phoenixnap/go-sdk…
gabrielCamilleriCcbill May 19, 2022
24d3602
Merge branch 'Feature/-setup-testing' into Feature/Tags-Api-Testing
gabrielCamilleriCcbill May 19, 2022
b9f8ca3
Merge branch 'develop' into Feature/-setup-testing
gabrielCamilleriCcbill May 19, 2022
50a464f
unnecessary changes
gabrielCamilleriCcbill May 19, 2022
d53ade8
removed file completely (revert)
gabrielCamilleriCcbill May 19, 2022
8eeba65
Merge branch 'Feature/-setup-testing' into feature/AuditApi-Testing
gabrielCamilleriCcbill May 19, 2022
fdd6ce9
Merge branch 'Feature/-setup-testing' into Feature/Tags-Api-Testing
gabrielCamilleriCcbill May 19, 2022
5583851
removed commented code
gabrielCamilleriCcbill May 19, 2022
bf1358f
added create tag test
gabrielCamilleriCcbill May 19, 2022
f75d33b
Suite -> Test
gabrielCamilleriCcbill May 19, 2022
12f884c
method renamed to camel case
gabrielCamilleriCcbill May 19, 2022
6a6da84
revert
gabrielCamilleriCcbill May 19, 2022
76bb87a
Merge branch 'Feature/-setup-testing' into feature/AuditApi-Testing
gabrielCamilleriCcbill May 19, 2022
aa5857e
fixing method calls to camel case
gabrielCamilleriCcbill May 19, 2022
16f1012
Merge branch 'Feature/-setup-testing' into Feature/Tags-Api-Testing
gabrielCamilleriCcbill May 19, 2022
512a63f
method camel case rename
gabrielCamilleriCcbill May 19, 2022
65253ca
method rename
gabrielCamilleriCcbill May 19, 2022
9b41704
finishing tags tests and formatting
gabrielCamilleriCcbill May 20, 2022
5516e76
Merge remote-tracking branch 'origin/release/v2.3.0' into feature/Aud…
gabrielCamilleriCcbill May 20, 2022
d077d4e
Merge remote-tracking branch 'origin/release/v2.3.0' into Feature/-se…
gabrielCamilleriCcbill May 20, 2022
b60eeed
Merge pull request #40 from phoenixnap/Feature/-setup-testing
gabrielCamilleriCcbill May 20, 2022
2e0c656
Merge remote-tracking branch 'origin/release/v2.3.0' into Feature/Tag…
gabrielCamilleriCcbill May 20, 2022
782f03f
Merge branch 'release/v2.3.0' into feature/AuditApi-Testing
gabrielCamilleriCcbill May 20, 2022
fe7347d
Merge branch 'release/v2.3.0' into Feature/Tags-Api-Testing
gabrielCamilleriCcbill May 20, 2022
667a50f
added release for generate sdk
gabrielCamilleriCcbill May 20, 2022
8b5ce58
added release generation
gabrielCamilleriCcbill May 20, 2022
a071396
go junit xml report
gabrielCamilleriCcbill May 20, 2022
6ae6b37
generate sdk update
gabrielCamilleriCcbill May 20, 2022
b9773af
go intsall to go get
gabrielCamilleriCcbill May 20, 2022
b484431
fixing directory issue
gabrielCamilleriCcbill May 20, 2022
1573f1f
fixing command not found issue
gabrielCamilleriCcbill May 20, 2022
2263ea8
missing command issue fix 2
gabrielCamilleriCcbill May 20, 2022
22e9046
command not ofnud fix 3
gabrielCamilleriCcbill May 20, 2022
613f502
go install problem
gabrielCamilleriCcbill May 20, 2022
983d050
access issue to publish test
gabrielCamilleriCcbill May 20, 2022
272c7a5
Error: EACCES: permission denied fix test
gabrielCamilleriCcbill May 20, 2022
f769d22
status code fix
gabrielCamilleriCcbill May 20, 2022
f1ad8f3
failing tests github only
gabrielCamilleriCcbill May 20, 2022
b2cec60
failing tests
gabrielCamilleriCcbill May 20, 2022
8c2889c
fixed mockserver missing
gabrielCamilleriCcbill May 20, 2022
a87ab52
mockserverfix
gabrielCamilleriCcbill May 20, 2022
bbc9f27
outputting the test result
gabrielCamilleriCcbill May 20, 2022
f36fa8d
publishing tests
gabrielCamilleriCcbill May 20, 2022
8c79d28
run tests for audit api only
gabrielCamilleriCcbill May 23, 2022
7bb61f1
run audit api test only
gabrielCamilleriCcbill May 23, 2022
ad1de8e
cleanup
gabrielCamilleriCcbill May 23, 2022
8d38ec6
revert
gabrielCamilleriCcbill May 23, 2022
010a6f1
tag api test results
gabrielCamilleriCcbill May 23, 2022
fa25b42
pass suite name to actions.yml
gabrielCamilleriCcbill May 23, 2022
92694e5
sdk missing configs
gabrielCamilleriCcbill May 23, 2022
d36153a
missing config changes
gabrielCamilleriCcbill May 23, 2022
7927db8
camel case renamed
gabrielCamilleriCcbill May 23, 2022
a3ae5dc
fixing comments
gabrielCamilleriCcbill May 24, 2022
c1dfb51
setting up suite for testing
gabrielCamilleriCcbill May 24, 2022
08c5e92
removing unnecessary comment
gabrielCamilleriCcbill May 24, 2022
0dedfe4
adding tests
gabrielCamilleriCcbill May 24, 2022
2564d7b
addressed jenkins comments
gabrielCamilleriCcbill May 24, 2022
7b5c298
renaming argument
gabrielCamilleriCcbill May 24, 2022
ff855f3
cleanup
gabrielCamilleriCcbill May 24, 2022
da624a7
Merge branch 'Feature/Tags-Api-Testing' of github.com:phoenixnap/go-s…
gabrielCamilleriCcbill May 24, 2022
6695f61
Merge pull request #42 from phoenixnap/feature/AuditApi-Testing
gabrielCamilleriCcbill May 24, 2022
2d5c2d6
addinf tests
gabrielCamilleriCcbill May 24, 2022
5aac29b
Merge branch 'release/v2.3.0' into Feature/Tags-Api-Testing
gabrielCamilleriCcbill May 24, 2022
479eba3
verify method fix
gabrielCamilleriCcbill May 24, 2022
3ff59c6
testing something
gabrielCamilleriCcbill May 24, 2022
8ab3259
renaming test to suite to keep the standard impl
gabrielCamilleriCcbill May 24, 2022
4b70afa
finishing rancher tests impl
gabrielCamilleriCcbill May 24, 2022
6db0c7c
code cleanup
gabrielCamilleriCcbill May 24, 2022
6510890
Adding IP API Tests (#44)
fybJenkins May 24, 2022
b0ccf7e
Merge branch 'release/v2.3.0' into Feature/Tags-Api-Testing
gabrielCamilleriCcbill May 25, 2022
3f3d437
test results
gabrielCamilleriCcbill May 25, 2022
c8cf31e
cleanup
gabrielCamilleriCcbill May 25, 2022
66e0dd4
setting up test suite for network
gabrielCamilleriCcbill May 25, 2022
563cddf
implementing get and create private net tests
gabrielCamilleriCcbill May 25, 2022
492a80a
finished private nets iml public nets
gabrielCamilleriCcbill May 25, 2022
3db68a5
impl public network tests
gabrielCamilleriCcbill May 25, 2022
b17cf14
addressed jenkins comment
gabrielCamilleriCcbill May 25, 2022
469c023
impl public networks tests
gabrielCamilleriCcbill May 25, 2022
27fbab1
Merge pull request #43 from phoenixnap/Feature/Tags-Api-Testing
gabrielCamilleriCcbill May 25, 2022
4286382
impl public networks tests
gabrielCamilleriCcbill May 25, 2022
e14a40d
finished tests for networks
gabrielCamilleriCcbill May 25, 2022
b1ab3e6
removed unncessary ethod from test utils
gabrielCamilleriCcbill May 25, 2022
f4a5b47
Merge branch 'release/v2.3.0' into feature/RancherSolutionApi-Testing
gabrielCamilleriCcbill May 25, 2022
3d7c86a
merge conflicts
gabrielCamilleriCcbill May 26, 2022
9fc90a6
test utils cleanup
gabrielCamilleriCcbill May 26, 2022
97421f6
Merge branch 'feature/RancherSolutionApi-Testing' into feature/Networ…
gabrielCamilleriCcbill May 26, 2022
b667db6
generate sdk fix
gabrielCamilleriCcbill May 26, 2022
ec14d00
cleanup
gabrielCamilleriCcbill May 26, 2022
1035ac9
fixing versions and changed path param variable
gabrielCamilleriCcbill May 26, 2022
0caf1b1
Merge branch 'feature/RancherSolutionApi-Testing' into feature/Networ…
gabrielCamilleriCcbill May 26, 2022
7ba9d57
Merge pull request #45 from phoenixnap/feature/RancherSolutionApi-Tes…
gabrielCamilleriCcbill May 26, 2022
6aa92d0
Merge branch 'release/v2.3.0' into feature/NetworkApi-Testing
gabrielCamilleriCcbill May 26, 2022
8692b43
removed unnecessary need
gabrielCamilleriCcbill May 26, 2022
90b46e3
fix order
gabrielCamilleriCcbill May 26, 2022
febc7ed
fixed statusCode
gabrielCamilleriCcbill May 26, 2022
9b945f6
reformat revert
gabrielCamilleriCcbill May 26, 2022
79dbda6
doing the format how jenkins had initially written them
gabrielCamilleriCcbill May 26, 2022
f17f758
jenkins format
gabrielCamilleriCcbill May 26, 2022
40f1828
more custom formatting
gabrielCamilleriCcbill May 27, 2022
a34eea5
reformat
gabrielCamilleriCcbill May 27, 2022
d5f8715
reformat
gabrielCamilleriCcbill May 27, 2022
0d4401f
reformat private networks get
gabrielCamilleriCcbill May 27, 2022
73ceada
missed reformat
gabrielCamilleriCcbill May 27, 2022
03a5aff
dummy change to retrigger workflow
gabrielCamilleriCcbill May 27, 2022
7b99acd
dummy change
gabrielCamilleriCcbill May 27, 2022
9c8784a
azure issue fix
gabrielCamilleriCcbill May 27, 2022
db25a3e
dummy change to trigger workflow
gabrielCamilleriCcbill May 27, 2022
e5664f2
Merge pull request #46 from phoenixnap/feature/NetworkApi-Testing
gabrielCamilleriCcbill May 27, 2022
abcf734
Adding tests for BMC API SDK (#47)
fybJenkins May 27, 2022
2233144
Added formatting for test payloads using JQ (#48)
fybJenkins May 30, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/composite/generate-sdk/action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: 'Generate SDK'
description: 'Generate SDK for a given API'
inputs:
spec-link:
description: 'Link to the spec file.'
required: true
package-name:
description: 'Name of the go module.'
required: true
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/composite/lint-sdk/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ runs:
steps:
- name: Install golang
shell: bash
run: sudo apt-get install golang-go
run: |
sudo apt-get update
sudo apt-get install golang-go
- name: Lint module
shell: bash
run: cd ${{ inputs.module-name }} && go vet ./...
28 changes: 28 additions & 0 deletions .github/workflows/composite/test-sdk/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: 'Test SDK'
description: 'Test SDK using a given test file.'
inputs:
test-suite:
description: 'Name of the test suite to run.'
required: true
runs:
using: "composite"
steps:
- name: Install golang
shell: bash
run: |
sudo apt-get update
sudo apt-get install golang-go
- name: Run tests
shell: bash
run: |
cd tests
export GOPATH="$HOME/go/"
export PATH=$PATH:$GOPATH/bin
go install github.com/jstemmer/go-junit-report
go test -v -run ${{ inputs.test-suite }} | go-junit-report -set-exit-code > ${{inputs.test-suite}}.xml
- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v2
with:
name: Test Results
path: 'tests/*'
117 changes: 111 additions & 6 deletions .github/workflows/generate-sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
branches:
- develop
- 'release/**'
schedule:
- cron: '15 */4 * * *'

Expand Down Expand Up @@ -69,7 +70,7 @@ jobs:
push-changes:
name: Push Changes
runs-on: ubuntu-latest
if: startsWith(github.head_ref, 'release') == false && github.head_ref != 'master' && github.event.pull_request.head.repo.full_name == 'phoenixnap/go-sdk-bmc'
if: startsWith(github.head_ref, 'release') == false && startsWith(github.base_ref, 'release') == false && github.head_ref != 'master' && github.base_ref != 'master' && github.event.pull_request.head.repo.full_name == 'phoenixnap/go-sdk-bmc'
needs:
- generate-bmcapi
- generate-rancherapi
Expand Down Expand Up @@ -247,15 +248,117 @@ jobs:
with:
module-name: tagapi

publish-test-results:
name: Publish Test Results
test-auditapi:
name: Test Audit API
runs-on: ubuntu-latest
needs:
- lint-auditapi
services:
mockserver:
image: mockserver/mockserver:5.13.0
ports:
- 1080:1080
steps:
- uses: actions/checkout@v2
- name: Download Artifacts
uses: actions/download-artifact@v2
- uses: ./.github/workflows/composite/test-sdk
with:
test-suite: TestAuditApiTestSuite
test-ipapi:
name: Test IP API
runs-on: ubuntu-latest
needs:
- lint-ipapi
services:
mockserver:
image: mockserver/mockserver:5.13.0
ports:
- 1080:1080
steps:
- uses: actions/checkout@v2
- name: Download Artifacts
uses: actions/download-artifact@v2
- uses: ./.github/workflows/composite/test-sdk
with:
test-suite: TestIpApiTestSuite
test-bmcapi:
name: Test BMC API
runs-on: ubuntu-latest
needs:
- lint-bmcapi
services:
mockserver:
image: mockserver/mockserver:5.13.0
ports:
- 1080:1080
steps:
- uses: actions/checkout@v2
- name: Download Artifacts
uses: actions/download-artifact@v2
- uses: ./.github/workflows/composite/test-sdk
with:
test-suite: TestBmcApiTestSuite
test-tagapi:
name: Test Tag API
runs-on: ubuntu-latest
needs:
- lint-tagapi
services:
mockserver:
image: mockserver/mockserver:5.13.0
ports:
- 1080:1080
steps:
- uses: actions/checkout@v2
- name: Download Artifacts
uses: actions/download-artifact@v2
- uses: ./.github/workflows/composite/test-sdk
with:
test-suite: TestTagApiTestSuite
test-rancherapi:
name: Test Rancher API
runs-on: ubuntu-latest
needs:
- lint-rancherapi
services:
mockserver:
image: mockserver/mockserver:5.13.0
ports:
- 1080:1080
steps:
- uses: actions/checkout@v2
- name: Download Artifacts
uses: actions/download-artifact@v2
- uses: ./.github/workflows/composite/test-sdk
with:
test-suite: TestRancherSolutionApiTestSuite
test-networkapi:
name: Test Network API
runs-on: ubuntu-latest
needs:
- lint-networkapi
- lint-ipapi
- lint-auditapi
- lint-tagapi
services:
mockserver:
image: mockserver/mockserver:5.13.0
ports:
- 1080:1080
steps:
- uses: actions/checkout@v2
- name: Download Artifacts
uses: actions/download-artifact@v2
- uses: ./.github/workflows/composite/test-sdk
with:
test-suite: TestNetworkApiTestSuite
publish-test-results:
name: Publish Test Results
needs:
- test-bmcapi
- test-rancherapi
- test-networkapi
- test-ipapi
- test-auditapi
- test-tagapi
runs-on: ubuntu-latest
if: always()
steps:
Expand All @@ -268,3 +371,5 @@ jobs:
with:
files: test-reports/**/*.xml
check_name: "Test Results"


27 changes: 27 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Tests

## Setup

To run tests you'll need to run an instance of `mockserver` running at port 1080. This can be done using Docker:
- Install docker
- Prepare and start `mockserver` by running the following: `docker run --name mockserver -d --rm -p 1080:1080 mockserver/mockserver:5.13.0`

You can then get logs from the mock server by running `docker logs -f mockserver`. The container id can be found using `docker ps`.

Once you're done, you can stop the mock server by running `docker container stop -f mockserver`.

Alternatively, you can also run an instance of `portainer` by running the following command: `docker run -d -p 9000:9000 --restart always -v /var/run/docker.sock:/var/run/docker.sock -v /opt/portainer:/data portainer/portainer`. Going to `localhost:9000` will then give you a GUI where you can stop, start, and look at the logs for `mockserver`.

## Running

Tests can be run per-module by running its respective `tc_` script, or all at once by running `ts_sdk.rb`:

```sh
bundler exec ruby ./ts_sdk.rb
```

## Payloads

Payloads are created according to the mockserver documentation. In addition, they are formatted using `jq`.

To format any additional payloads, install `jq` by doing `sudo apt-get install jq`, then run `format.sh` while inside the `payloads` folder.
96 changes: 96 additions & 0 deletions tests/audit_api_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package tests

import (
"context"
"encoding/json"
"fmt"
"os"
"strconv"
"testing"
"time"

"github.com/phoenixnap/go-sdk-bmc/auditapi"
"github.com/stretchr/testify/suite"
)

type AuditApiTestSuite struct {
suite.Suite
ctx context.Context
configuration *auditapi.Configuration
apiClient *auditapi.APIClient
}

func (suite *AuditApiTestSuite) SetupSuite() {
// Set configuration
suite.configuration = auditapi.NewConfiguration()
suite.configuration.Host = "127.0.0.1:1080"
suite.configuration.Scheme = "http"
// Set the context background
suite.ctx = context.WithValue(context.Background(), "accessToken", "ACCESSTOKENSTRING")
suite.ctx = context.WithValue(suite.ctx, "serverIndex", nil)
fmt.Println(">>> From SetupSuite")
suite.apiClient = auditapi.NewAPIClient(suite.configuration)
}

// this function executes after all tests executed
func (suite *AuditApiTestSuite) TearDownTest() {
fmt.Println(">>> From TearDownSuite")
TestUtilsImpl{}.resetExpectations()
}

func (suite *AuditApiTestSuite) verifyCalledOnce(expectationId string) {
// Result retrieved from server's verification
// Verifying expectation matched exactly once.
verifyResult := TestUtilsImpl{}.verifyExpectationMatchedTimes(expectationId, 1)

// Asserts a successful result
suite.Equal(202, verifyResult.StatusCode)
}

func (suite *AuditApiTestSuite) Test_get_events_all_query_params() {

// Generate payload
request, response := TestUtilsImpl{}.generatePayloadsFrom("auditapi/events_get", "./payloads")

// Extract the response expectation id
expectationId := TestUtilsImpl{}.setupExpectation(request, response, 1)

// Fetch a map of query parameters
qpMap := TestUtilsImpl{}.generateQueryParams(request)

// Converting to int32
limitstring, ok := qpMap["limit"].(string)
if !ok {
panic(ok)
}

from, _ := time.Parse(time.RFC3339, request.QueryStringParameters[0].Values[0])
to, _ := time.Parse(time.RFC3339, request.QueryStringParameters[1].Values[0])
limit64, _ := strconv.ParseInt(limitstring, 10, 32)
limit := int32(limit64)
order := fmt.Sprintf("%v", qpMap["order"])
username := fmt.Sprintf("%v", qpMap["username"])
verb := fmt.Sprintf("%v", qpMap["verb"])
uri := fmt.Sprintf("%v", qpMap["uri"])

// Operation Execution
result, r, err := suite.apiClient.EventsApi.EventsGet(suite.ctx).From(from).To(to).Limit(limit).Order(order).Username(username).Verb(verb).Uri(uri).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `EventsApi.EventsGet``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}

// Convert the result and response body to json strings
jsonResult, _ := json.Marshal(result)
jsonResponseBody, _ := json.Marshal(response.Body)

// Asserts
suite.Equal(jsonResult, jsonResponseBody)

// Verify
suite.verifyCalledOnce(expectationId)
}

func TestAuditApiTestSuite(t *testing.T) {
suite.Run(t, new(AuditApiTestSuite))
}
Loading