Skip to content

Commit

Permalink
fix: updated apiURL for e2e tests (#432)
Browse files Browse the repository at this point in the history
Updated apiURL for all tests

Co-authored-by: codinja1188 <[email protected]>
  • Loading branch information
codinja1188 and codinja1188 authored Jan 11, 2024
1 parent 6ab4251 commit 01f781b
Show file tree
Hide file tree
Showing 30 changed files with 62 additions and 136 deletions.
7 changes: 6 additions & 1 deletion internal/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ func (c *Client) metalApiConnect(httpClient *http.Client) error {
configuration.Debug = checkEnvForDebug()
configuration.AddDefaultHeader("X-Auth-Token", c.Token())
configuration.UserAgent = fmt.Sprintf("metal-cli/%s %s", c.Version, configuration.UserAgent)
configuration.Servers = metal.ServerConfigurations{
metal.ServerConfiguration{
URL: c.apiURL,
},
}
metalgoClient := metal.NewAPIClient(configuration)
c.metalApiClient = metalgoClient
return nil
Expand All @@ -134,7 +139,7 @@ func (c *Client) Config(cmd *cobra.Command) *viper.Viper {
}
if err := v.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
panic(fmt.Errorf("Could not read config: %s", err))
panic(fmt.Errorf("could not read config: %s", err))
}
}
c.cfgFile = v.ConfigFileUsed()
Expand Down
6 changes: 2 additions & 4 deletions test/e2e/capacitytest/capacity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ import (

func TestCli_Capacity(t *testing.T) {
subCommand := "capacity"
consumerToken := ""
apiURL := ""
Version := "metal"
rootClient := root.NewClient(consumerToken, apiURL, Version)

rootClient := root.NewClient(helper.ConsumerToken, helper.URL, helper.Version)
type fields struct {
MainCmd *cobra.Command
Outputer outputPkg.Outputer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ func TestCli_Devices_Create_Flags(t *testing.T) {
var deviceId string
var err error
subCommand := "device"
consumerToken := ""
apiURL := ""
Version := "metal"
rootClient := root.NewClient(consumerToken, apiURL, Version)
rootClient := root.NewClient(helper.ConsumerToken, helper.URL, helper.Version)
type fields struct {
MainCmd *cobra.Command
Outputer outputPkg.Outputer
Expand All @@ -39,7 +36,7 @@ func TestCli_Devices_Create_Flags(t *testing.T) {
want: &cobra.Command{},
cmdFunc: func(t *testing.T, c *cobra.Command) {
root := c.Root()
projectName := "metal-cli-device-create-flags" + helper.GenerateRandomString(5)
projectName := "metal-cli-" + helper.GenerateRandomString(5) + "-device-create-flags"
project := helper.CreateTestProject(t, projectName)

root.SetArgs([]string{subCommand, "create", "-p", project.GetId(), "-P", "m3.small.x86", "-m", "da", "-H", "metal-cli-create-flags-dev", "--operating-system", "custom_ipxe", "--always-pxe=true", "--ipxe-script-url", "https://boot.netboot.xyz/"})
Expand Down
7 changes: 2 additions & 5 deletions test/e2e/devices/devicecreatetest/device_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ func TestCli_Devices_Create(t *testing.T) {
var deviceId string
var err error
subCommand := "device"
consumerToken := ""
apiURL := ""
Version := "metal"
rootClient := root.NewClient(consumerToken, apiURL, Version)
rootClient := root.NewClient(helper.ConsumerToken, helper.URL, helper.Version)
randomId := helper.GenerateRandomString(5)

type fields struct {
Expand All @@ -44,7 +41,7 @@ func TestCli_Devices_Create(t *testing.T) {
projectName := "metal-cli-device-create" + randomId
project := helper.CreateTestProject(t, projectName)

deviceName := "metal-cli-create-dev" + randomId
deviceName := "metal-cli-" + randomId + "-create-dev"
root.SetArgs([]string{subCommand, "create", "-p", project.GetId(), "-P", "m3.small.x86", "-m", "da", "-O", "ubuntu_20_04", "-H", deviceName})

out := helper.ExecuteAndCaptureOutput(t, root)
Expand Down
7 changes: 2 additions & 5 deletions test/e2e/devices/devicegettest/device_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import (

func TestCli_Devices_Get(t *testing.T) {
subCommand := "device"
consumerToken := ""
apiURL := ""
Version := "metal"
rootClient := root.NewClient(consumerToken, apiURL, Version)
rootClient := root.NewClient(helper.ConsumerToken, helper.URL, helper.Version)
type fields struct {
MainCmd *cobra.Command
Outputer outputPkg.Outputer
Expand All @@ -36,7 +33,7 @@ func TestCli_Devices_Get(t *testing.T) {
want: &cobra.Command{},
cmdFunc: func(t *testing.T, c *cobra.Command) {
root := c.Root()
projectName := "metal-cli-device-get" + helper.GenerateRandomString(5)
projectName := "metal-cli-" + helper.GenerateRandomString(5) + "-device-get"
project := helper.CreateTestProject(t, projectName)
device := helper.CreateTestDevice(t, project.GetId(), "metal-cli-get-dev")

Expand Down
7 changes: 2 additions & 5 deletions test/e2e/devices/devicereinstalltest/device_reinstall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ func TestCli_Devices_Update(t *testing.T) {
var err error
var status bool
subCommand := "device"
consumerToken := ""
apiURL := ""
Version := "metal"
rootClient := root.NewClient(consumerToken, apiURL, Version)
rootClient := root.NewClient(helper.ConsumerToken, helper.URL, helper.Version)
type fields struct {
MainCmd *cobra.Command
Outputer outputPkg.Outputer
Expand All @@ -37,7 +34,7 @@ func TestCli_Devices_Update(t *testing.T) {
want: &cobra.Command{},
cmdFunc: func(t *testing.T, c *cobra.Command) {
root := c.Root()
projectName := "metal-cli-device-reinstall" + helper.GenerateRandomString(5)
projectName := "metal-cli-" + helper.GenerateRandomString(5) + "-device-reinstall"
project := helper.CreateTestProject(t, projectName)
device := helper.CreateTestDevice(t, project.GetId(), "metal-cli-reinstall-dev")
status, err = helper.IsDeviceStateActive(t, device.GetId())
Expand Down
7 changes: 2 additions & 5 deletions test/e2e/devices/devicestarttest/device_start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import (

func TestCli_Devices_Update(t *testing.T) {
subCommand := "device"
consumerToken := ""
apiURL := ""
Version := "metal"
rootClient := root.NewClient(consumerToken, apiURL, Version)
rootClient := root.NewClient(helper.ConsumerToken, helper.URL, helper.Version)
type fields struct {
MainCmd *cobra.Command
Outputer outputPkg.Outputer
Expand All @@ -36,7 +33,7 @@ func TestCli_Devices_Update(t *testing.T) {
want: &cobra.Command{},
cmdFunc: func(t *testing.T, c *cobra.Command) {
root := c.Root()
projectName := "metal-cli-device-start" + helper.GenerateRandomString(5)
projectName := "metal-cli-" + helper.GenerateRandomString(5) + "-device-start"
project := helper.CreateTestProject(t, projectName)
device := helper.CreateTestDevice(t, project.GetId(), "metal-cli-start-dev")
status, err := helper.IsDeviceStateActive(t, device.GetId())
Expand Down
7 changes: 2 additions & 5 deletions test/e2e/devices/devicestoptest/device_stop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import (

func TestCli_Devices_Update(t *testing.T) {
subCommand := "device"
consumerToken := ""
apiURL := ""
Version := "metal"
rootClient := root.NewClient(consumerToken, apiURL, Version)
rootClient := root.NewClient(helper.ConsumerToken, helper.URL, helper.Version)
type fields struct {
MainCmd *cobra.Command
Outputer outputPkg.Outputer
Expand All @@ -36,7 +33,7 @@ func TestCli_Devices_Update(t *testing.T) {
want: &cobra.Command{},
cmdFunc: func(t *testing.T, c *cobra.Command) {
root := c.Root()
projectName := "metal-cli-device-stop" + helper.GenerateRandomString(5)
projectName := "metal-cli-" + helper.GenerateRandomString(5) + "-device-stop"
project := helper.CreateTestProject(t, projectName)
device := helper.CreateTestDevice(t, project.GetId(), "metal-cli-stop-dev")

Expand Down
7 changes: 2 additions & 5 deletions test/e2e/devices/deviceupdatetest/device_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import (

func TestCli_Devices_Update(t *testing.T) {
subCommand := "device"
consumerToken := ""
apiURL := ""
Version := "metal"
rootClient := root.NewClient(consumerToken, apiURL, Version)
rootClient := root.NewClient(helper.ConsumerToken, helper.URL, helper.Version)
type fields struct {
MainCmd *cobra.Command
Outputer outputPkg.Outputer
Expand All @@ -36,7 +33,7 @@ func TestCli_Devices_Update(t *testing.T) {
want: &cobra.Command{},
cmdFunc: func(t *testing.T, c *cobra.Command) {
root := c.Root()
projectName := "metal-cli-device-update" + helper.GenerateRandomString(5)
projectName := "metal-cli-" + helper.GenerateRandomString(5) + "-device-update"
project := helper.CreateTestProject(t, projectName)
device := helper.CreateTestDevice(t, project.GetId(), "metal-cli-update-dev")

Expand Down
7 changes: 2 additions & 5 deletions test/e2e/events/deviceeventstest/device_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import (

func TestCli_Events_Get(t *testing.T) {
subCommand := "event"
consumerToken := ""
apiURL := ""
Version := "metal"
rootClient := root.NewClient(consumerToken, apiURL, Version)
rootClient := root.NewClient(helper.ConsumerToken, helper.URL, helper.Version)
type fields struct {
MainCmd *cobra.Command
Outputer outputPkg.Outputer
Expand All @@ -36,7 +33,7 @@ func TestCli_Events_Get(t *testing.T) {
want: &cobra.Command{},
cmdFunc: func(t *testing.T, c *cobra.Command) {
root := c.Root()
projectName := "metal-cli-device-events" + helper.GenerateRandomString(5)
projectName := "metal-cli-" + helper.GenerateRandomString(5) + "-device-events"
project := helper.CreateTestProject(t, projectName)
device := helper.CreateTestDevice(t, project.GetId(), "metal-cli-events-dev")
status, err := helper.IsDeviceStateActive(t, device.GetId())
Expand Down
7 changes: 2 additions & 5 deletions test/e2e/events/projecteventstest/project_events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import (

func TestCli_Events_Get(t *testing.T) {
subCommand := "event"
consumerToken := ""
apiURL := ""
Version := "metal"
rootClient := root.NewClient(consumerToken, apiURL, Version)
rootClient := root.NewClient(helper.ConsumerToken, helper.URL, helper.Version)
type fields struct {
MainCmd *cobra.Command
Outputer outputPkg.Outputer
Expand All @@ -37,7 +34,7 @@ func TestCli_Events_Get(t *testing.T) {
cmdFunc: func(t *testing.T, c *cobra.Command) {
root := c.Root()

projectName := "metal-cli-projects-events" + helper.GenerateRandomString(5)
projectName := "metal-cli-" + helper.GenerateRandomString(5) + "-projects-events"
project := helper.CreateTestProject(t, projectName)

root.SetArgs([]string{subCommand, "get", "-p", project.GetId()})
Expand Down
9 changes: 3 additions & 6 deletions test/e2e/gateways/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ import (

func TestGateways_Create(t *testing.T) {
subCommand := "gateways"
consumerToken := ""
apiURL := ""
Version := "devel"
rootClient := root.NewClient(consumerToken, apiURL, Version)

project := helper.CreateTestProject(t, "metal-cli-gateways-create")
rootClient := root.NewClient(helper.ConsumerToken, helper.URL, helper.Version)
projectName := "metal-cli-" + helper.GenerateRandomString(5) + "-gateways-create"
project := helper.CreateTestProject(t, projectName)
vlan := helper.CreateTestVLAN(t, project.GetId())

tests := []struct {
Expand Down
9 changes: 3 additions & 6 deletions test/e2e/gateways/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ import (

func TestGateways_Delete(t *testing.T) {
subCommand := "gateways"
consumerToken := ""
apiURL := ""
Version := "devel"
rootClient := root.NewClient(consumerToken, apiURL, Version)

project := helper.CreateTestProject(t, "metal-cli-gateway-delete")
rootClient := root.NewClient(helper.ConsumerToken, helper.URL, helper.Version)
projectName := "metal-cli-" + helper.GenerateRandomString(5) + "-gateway-delete"
project := helper.CreateTestProject(t, projectName)

vlan := helper.CreateTestVLAN(t, project.GetId())

Expand Down
9 changes: 3 additions & 6 deletions test/e2e/gateways/retrieve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ import (

func TestGateways_Retrieve(t *testing.T) {
subCommand := "gateways"
consumerToken := ""
apiURL := ""
Version := "devel"
rootClient := root.NewClient(consumerToken, apiURL, Version)

project := helper.CreateTestProject(t, "metal-cli-gateway-get")
rootClient := root.NewClient(helper.ConsumerToken, helper.URL, helper.Version)
projectName := "metal-cli-" + helper.GenerateRandomString(5) + "-gateway-get"
project := helper.CreateTestProject(t, projectName)

vlan := helper.CreateTestVLAN(t, project.GetId())

Expand Down
7 changes: 2 additions & 5 deletions test/e2e/ipstest/ips_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ func TestCli_Ips_Get(t *testing.T) {
var ipsId string
var err error
subCommand := "ip"
consumerToken := ""
apiURL := ""
Version := "metal"
rootClient := root.NewClient(consumerToken, apiURL, Version)
rootClient := root.NewClient(helper.ConsumerToken, helper.URL, helper.Version)
type fields struct {
MainCmd *cobra.Command
Outputer outputPkg.Outputer
Expand All @@ -41,7 +38,7 @@ func TestCli_Ips_Get(t *testing.T) {
t.Skip("Skipping this test because someCondition is true")
}
root := c.Root()
projectName := "metal-cli-ips-get" + helper.GenerateRandomString(5)
projectName := "metal-cli-" + helper.GenerateRandomString(5) + "-ips-get"
project := helper.CreateTestProject(t, projectName)
ipsId, err = helper.CreateTestIps(t, project.GetId(), 1, "public_ipv4")
if len(ipsId) != 0 {
Expand Down
7 changes: 2 additions & 5 deletions test/e2e/ipstest/ips_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import (

func TestCli_Vlan_Create(t *testing.T) {
subCommand := "ip"
consumerToken := ""
apiURL := ""
Version := "metal"
rootClient := root.NewClient(consumerToken, apiURL, Version)
rootClient := root.NewClient(helper.ConsumerToken, helper.URL, helper.Version)
type fields struct {
MainCmd *cobra.Command
Outputer outputPkg.Outputer
Expand All @@ -39,7 +36,7 @@ func TestCli_Vlan_Create(t *testing.T) {
t.Skip("Skipping temporarily for now")
}
root := c.Root()
projectName := "metal-cli-ips-get" + helper.GenerateRandomString(5)
projectName := "metal-cli-" + helper.GenerateRandomString(5) + "-ips-request-get"
project := helper.CreateTestProject(t, projectName)

root.SetArgs([]string{subCommand, "request", "-p", project.GetId(), "-t", "public_ipv4", "-m", "da", "-q", "4"})
Expand Down
5 changes: 1 addition & 4 deletions test/e2e/metrotest/metro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import (

func TestCli_Metros(t *testing.T) {
subCommand := "metros"
consumerToken := ""
apiURL := ""
Version := "metal"
rootClient := root.NewClient(consumerToken, apiURL, Version)
rootClient := root.NewClient(helper.ConsumerToken, helper.URL, helper.Version)
type fields struct {
MainCmd *cobra.Command
Outputer outputPkg.Outputer
Expand Down
6 changes: 2 additions & 4 deletions test/e2e/organizationtest/organization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ import (
root "github.com/equinix/metal-cli/internal/cli"
"github.com/equinix/metal-cli/internal/organizations"
outputPkg "github.com/equinix/metal-cli/internal/outputs"
"github.com/equinix/metal-cli/test/helper"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
)

func TestCli_Organization(t *testing.T) {
subCommand := "organization"
consumerToken := ""
apiURL := ""
Version := "metal"
rootClient := root.NewClient(consumerToken, apiURL, Version)
rootClient := root.NewClient(helper.ConsumerToken, helper.URL, helper.Version)
type fields struct {
MainCmd *cobra.Command
Outputer outputPkg.Outputer
Expand Down
5 changes: 1 addition & 4 deletions test/e2e/ostest/os_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import (

func TestCli_OperatingSystem(t *testing.T) {
subCommand := "operating-systems"
consumerToken := ""
apiURL := ""
Version := "metal"
rootClient := root.NewClient(consumerToken, apiURL, Version)
rootClient := root.NewClient(helper.ConsumerToken, helper.URL, helper.Version)
type fields struct {
MainCmd *cobra.Command
Outputer outputPkg.Outputer
Expand Down
8 changes: 1 addition & 7 deletions test/e2e/plantest/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,8 @@ import (
)

func TestCli_Plans(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
subCommand := "plans"
consumerToken := ""
apiURL := ""
Version := "metal"
rootClient := root.NewClient(consumerToken, apiURL, Version)
rootClient := root.NewClient(helper.ConsumerToken, helper.URL, helper.Version)
type fields struct {
MainCmd *cobra.Command
Outputer outputPkg.Outputer
Expand Down
5 changes: 1 addition & 4 deletions test/e2e/ports/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ import (

func TestPorts_Convert(t *testing.T) {
subCommand := "port"
consumerToken := ""
apiURL := ""
Version := "devel"
rootClient := root.NewClient(consumerToken, apiURL, Version)
rootClient := root.NewClient(helper.ConsumerToken, helper.URL, helper.Version)

_, device := helper.SetupProjectAndDevice(t, "metal-cli-port-convert")

Expand Down
5 changes: 1 addition & 4 deletions test/e2e/ports/retrieve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ import (

func TestPorts_Retrieve(t *testing.T) {
subCommand := "port"
consumerToken := ""
apiURL := ""
Version := "devel"
rootClient := root.NewClient(consumerToken, apiURL, Version)
rootClient := root.NewClient(helper.ConsumerToken, helper.URL, helper.Version)

_, device := helper.SetupProjectAndDevice(t, "metal-cli-port-get")

Expand Down
Loading

0 comments on commit 01f781b

Please sign in to comment.