From 0fb5f074edba95bf60c66e3724e49ce4bc91184b Mon Sep 17 00:00:00 2001 From: michaelfmnk Date: Thu, 8 Aug 2024 12:44:27 +0200 Subject: [PATCH 1/9] moved e2e tests --- e2e/client_test.go | 104 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 e2e/client_test.go diff --git a/e2e/client_test.go b/e2e/client_test.go new file mode 100644 index 0000000..84d252c --- /dev/null +++ b/e2e/client_test.go @@ -0,0 +1,104 @@ +package client + +import ( + "fmt" + "os" + "testing" + + "github.com/openvpn/cloudconnexa-go-client/v2/cloudconnexa" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func validateEnvVars(t *testing.T) { + validateEnvVar(t, HostEnvVar) + validateEnvVar(t, ClientIDEnvVar) + validateEnvVar(t, ClientSecretEnvVar) +} + +func validateEnvVar(t *testing.T, envVar string) { + fmt.Println(os.Getenv(envVar)) + require.NotEmptyf(t, os.Getenv(envVar), "%s must be set", envVar) +} + +const ( + HostEnvVar = "OVPN_HOST" + ClientIDEnvVar = "CLOUDCONNEXA_CLIENT_ID" + ClientSecretEnvVar = "CLOUDCONNEXA_CLIENT_SECRET" +) + +func TestNewClient(t *testing.T) { + c := setUpClient(t) + assert.NotEmpty(t, c.Token) +} + +func setUpClient(t *testing.T) *cloudconnexa.Client { + validateEnvVars(t) + var err error + client, err := cloudconnexa.NewClient(os.Getenv(HostEnvVar), os.Getenv(ClientIDEnvVar), os.Getenv(ClientSecretEnvVar)) + require.NoError(t, err) + return client +} + +func TestListNetworks(t *testing.T) { + c := setUpClient(t) + response, err := c.Networks.GetByPage(0, 10) + require.NoError(t, err) + fmt.Printf("found %d networks\n", len(response.Content)) +} + +func TestListConnectors(t *testing.T) { + c := setUpClient(t) + response, err := c.Connectors.GetByPage(0, 10) + require.NoError(t, err) + fmt.Printf("found %d connectors\n", len(response.Content)) +} + +func TestCreateNetwork(t *testing.T) { + c := setUpClient(t) + connector := cloudconnexa.NetworkConnector{ + Description: "test", + Name: "test", + VpnRegionId: "it-mxp", + } + route := cloudconnexa.Route{ + Description: "test", + Type: "IP_V4", + Subnet: "10.189.253.64/30", + } + network := cloudconnexa.Network{ + Description: "test", + Egress: false, + Name: "test", + InternetAccess: "LOCAL", + Connectors: []cloudconnexa.NetworkConnector{connector}, + } + response, err := c.Networks.Create(network) + require.NoError(t, err) + fmt.Printf("created %s network\n", response.Id) + test, err := c.Routes.Create(response.Id, route) + require.NoError(t, err) + fmt.Printf("created %s route\n", test.Id) + serviceConfig := cloudconnexa.IPServiceConfig{ + ServiceTypes: []string{"ANY"}, + } + ipServiceRoute := cloudconnexa.IPServiceRoute{ + Description: "test", + Value: "10.189.253.64/30", + } + service := cloudconnexa.IPService{ + Name: "test", + Description: "test", + NetworkItemId: response.Id, + Type: "IP_SOURCE", + NetworkItemType: "NETWORK", + Config: &serviceConfig, + Routes: []*cloudconnexa.IPServiceRoute{&ipServiceRoute}, + } + s, err := c.IPServices.Create(&service) + require.NoError(t, err) + fmt.Printf("created %s service\n", s.Id) + err = c.Networks.Delete(response.Id) + require.NoError(t, err) + fmt.Printf("deleted %s network\n", response.Id) +} From 16825bd403c4bb33e57d48fe99b57eeb5d9c6cd0 Mon Sep 17 00:00:00 2001 From: michaelfmnk Date: Thu, 8 Aug 2024 12:46:30 +0200 Subject: [PATCH 2/9] updated build & test workflow --- .github/workflows/go.yml | 19 ++++++++++++++++++- Makefile | 5 ++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 3739145..326630e 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -1,6 +1,20 @@ name: Go build -on: push +on: + pull_request: + branches: + - main + paths-ignore: + - "README.md" + push: + branches: + - main + paths-ignore: + - "README.md" + # We test at a regular interval to ensure we are alerted to something breaking due + # to an API change, even if the code did not change. + schedule: + - cron: "0 0 * * *" jobs: build: @@ -25,3 +39,6 @@ jobs: - name: Test run: make test + + - name: E2E Test + run: make e2e diff --git a/Makefile b/Makefile index 4694493..2aa648c 100644 --- a/Makefile +++ b/Makefile @@ -7,4 +7,7 @@ deps: .PHONY: test test: - @go test -cover -race -v ./... \ No newline at end of file + @go test -cover -race -v ./... + +e2e: + @go test -v ./e2e/... \ No newline at end of file From e2091a1c2da141dcca67b215f7a41d3cbb9d0080 Mon Sep 17 00:00:00 2001 From: michaelfmnk Date: Thu, 8 Aug 2024 12:56:15 +0200 Subject: [PATCH 3/9] updated github workflow --- .github/workflows/go.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 326630e..2dc4b0b 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -18,6 +18,7 @@ on: jobs: build: + environment: TestingEnv runs-on: ubuntu-latest strategy: matrix: From f3a4a7aa37c140e6bc58a74efa94f26ddd4571e2 Mon Sep 17 00:00:00 2001 From: michaelfmnk Date: Thu, 8 Aug 2024 13:00:21 +0200 Subject: [PATCH 4/9] updated makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2aa648c..67ec7ae 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ deps: .PHONY: test test: - @go test -cover -race -v ./... + @go test -cover -race -v ./cloudconnexa/... e2e: @go test -v ./e2e/... \ No newline at end of file From 65f930c331abf819b9cb7f1fc5f1610f8eff462a Mon Sep 17 00:00:00 2001 From: michaelfmnk Date: Thu, 8 Aug 2024 13:06:08 +0200 Subject: [PATCH 5/9] updated workflow --- .github/workflows/go.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 2dc4b0b..0e746c8 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -1,5 +1,8 @@ name: Go build +env: + OVPN_HOST: ${{ vars.OVPN_HOST }} + on: pull_request: branches: From 0154378ae1930d5b0543daa15b64b1a78c3aa6a8 Mon Sep 17 00:00:00 2001 From: michaelfmnk Date: Thu, 8 Aug 2024 13:08:59 +0200 Subject: [PATCH 6/9] updated makefile --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 67ec7ae..0685c1b 100644 --- a/Makefile +++ b/Makefile @@ -9,5 +9,6 @@ deps: test: @go test -cover -race -v ./cloudconnexa/... +.PHONY: e2e e2e: @go test -v ./e2e/... \ No newline at end of file From f5587aef2c14fd5d5e6a945563663e18636dff21 Mon Sep 17 00:00:00 2001 From: michaelfmnk Date: Thu, 8 Aug 2024 13:10:28 +0200 Subject: [PATCH 7/9] updated workflow --- .github/workflows/go.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 0e746c8..0e25b45 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -2,6 +2,8 @@ name: Go build env: OVPN_HOST: ${{ vars.OVPN_HOST }} + CLOUDCONNEXA_CLIENT_ID: ${{ vars.CLOUDCONNEXA_CLIENT_ID }} + CLOUDCONNEXA_CLIENT_SECRET: ${{ vars.CLOUDCONNEXA_CLIENT_SECRET }} on: pull_request: @@ -21,7 +23,6 @@ on: jobs: build: - environment: TestingEnv runs-on: ubuntu-latest strategy: matrix: From d101de094ba4eb7496126d5de7c67d8e5fb796b8 Mon Sep 17 00:00:00 2001 From: michaelfmnk Date: Thu, 8 Aug 2024 13:10:43 +0200 Subject: [PATCH 8/9] updated workflow --- .github/workflows/go.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 0e25b45..69a3ca5 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -2,8 +2,8 @@ name: Go build env: OVPN_HOST: ${{ vars.OVPN_HOST }} - CLOUDCONNEXA_CLIENT_ID: ${{ vars.CLOUDCONNEXA_CLIENT_ID }} - CLOUDCONNEXA_CLIENT_SECRET: ${{ vars.CLOUDCONNEXA_CLIENT_SECRET }} + CLOUDCONNEXA_CLIENT_ID: ${{ secrets.CLOUDCONNEXA_CLIENT_ID }} + CLOUDCONNEXA_CLIENT_SECRET: ${{ secrets.CLOUDCONNEXA_CLIENT_SECRET }} on: pull_request: From 5d1ec68df7baf76cc6327175b6ce975d3eeb4f68 Mon Sep 17 00:00:00 2001 From: michaelfmnk Date: Thu, 8 Aug 2024 13:13:31 +0200 Subject: [PATCH 9/9] updated workflow --- .github/workflows/go.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 69a3ca5..f9681e9 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -23,6 +23,7 @@ on: jobs: build: + environment: TestingEnv runs-on: ubuntu-latest strategy: matrix: