Skip to content

Commit

Permalink
GitHub Workflow updates & testing (#33)
Browse files Browse the repository at this point in the history
* moved e2e tests

* updated build & test workflow

* updated github workflow

* updated makefile

* updated workflow

* updated makefile

* updated workflow

* updated workflow

* updated workflow
  • Loading branch information
michaelfmnk authored Aug 9, 2024
1 parent 4f6f8ac commit d35ab58
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 2 deletions.
25 changes: 24 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
name: Go build

on: push
env:
OVPN_HOST: ${{ vars.OVPN_HOST }}
CLOUDCONNEXA_CLIENT_ID: ${{ secrets.CLOUDCONNEXA_CLIENT_ID }}
CLOUDCONNEXA_CLIENT_SECRET: ${{ secrets.CLOUDCONNEXA_CLIENT_SECRET }}

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:
environment: TestingEnv
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -25,3 +45,6 @@ jobs:

- name: Test
run: make test

- name: E2E Test
run: make e2e
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ deps:

.PHONY: test
test:
@go test -cover -race -v ./...
@go test -cover -race -v ./cloudconnexa/...

.PHONY: e2e
e2e:
@go test -v ./e2e/...
104 changes: 104 additions & 0 deletions e2e/client_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit d35ab58

Please sign in to comment.