This repository was archived by the owner on May 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Fix provider vs current APIs #136
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6feb6f6
fix provider v1
chicco785 a1fadd2
fixes to provider v1
chicco785 2bb1d4b
update to new changes to the client
chicco785 db2f66a
Update client_test.go
chicco785 327ba35
Update Makefile
chicco785 50934e4
Update .gitignore
chicco785 7c0ef51
Delete go.work.sum
chicco785 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
OPENVPN_HOST= | ||
OVPN_HOST= | ||
CLOUDCONNEXA_CLIENT_ID= | ||
CLOUDCONNEXA_CLIENT_SECRET= | ||
TF_ACC=0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,4 +33,5 @@ main | |
terraform.tfstate** | ||
*.tfvars | ||
|
||
*.env | ||
*.env | ||
/.vscode |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package client | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. may it is better to have something like this in https://github.com/OpenVPN/cloudconnexa-go-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) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.