-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated metal-go client for sub-commands ips
- Loading branch information
1 parent
c7eed25
commit d0695c1
Showing
11 changed files
with
285 additions
and
38 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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,87 @@ | ||
package ipstest | ||
|
||
import ( | ||
"io" | ||
"os" | ||
"strings" | ||
"testing" | ||
|
||
root "github.com/equinix/metal-cli/internal/cli" | ||
"github.com/equinix/metal-cli/internal/ips" | ||
outputPkg "github.com/equinix/metal-cli/internal/outputs" | ||
"github.com/equinix/metal-cli/test/helper" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func TestCli_Ips_Get(t *testing.T) { | ||
var projectId, ipsId string | ||
var err error | ||
subCommand := "ip" | ||
consumerToken := "" | ||
apiURL := "" | ||
Version := "metal" | ||
rootClient := root.NewClient(consumerToken, apiURL, Version) | ||
type fields struct { | ||
MainCmd *cobra.Command | ||
Outputer outputPkg.Outputer | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
want *cobra.Command | ||
cmdFunc func(*testing.T, *cobra.Command) | ||
}{ | ||
{ | ||
name: "get_virtual_network", | ||
fields: fields{ | ||
MainCmd: ips.NewClient(rootClient, outputPkg.Outputer(&outputPkg.Standard{})).NewCommand(), | ||
Outputer: outputPkg.Outputer(&outputPkg.Standard{}), | ||
}, | ||
want: &cobra.Command{}, | ||
cmdFunc: func(t *testing.T, c *cobra.Command) { | ||
if true { | ||
t.Skip("Skipping this test because someCondition is true") | ||
} | ||
root := c.Root() | ||
projectId, err = helper.CreateTestProject("metal-cli-ips-get-pro") | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
ipsId, err = helper.CreateTestIps(projectId, 5, "public_ipv4") | ||
if len(projectId) != 0 && len(ipsId) != 0 { | ||
root.SetArgs([]string{subCommand, "get", "-p", projectId}) | ||
rescueStdout := os.Stdout | ||
r, w, _ := os.Pipe() | ||
os.Stdout = w | ||
if err := root.Execute(); err != nil { | ||
t.Error(err) | ||
} | ||
w.Close() | ||
out, _ := io.ReadAll(r) | ||
os.Stdout = rescueStdout | ||
if !strings.Contains(string(out[:]), ipsId) && | ||
!strings.Contains(string(out[:]), "da") { | ||
t.Error("expected output should include " + ipsId + " da strings in the out string") | ||
} | ||
|
||
err = helper.CleanTestIps(ipsId) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
err = helper.CleanTestProject(projectId) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
} | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
rootCmd := rootClient.NewCommand() | ||
rootCmd.AddCommand(tt.fields.MainCmd) | ||
tt.cmdFunc(t, tt.fields.MainCmd) | ||
}) | ||
} | ||
} |
Oops, something went wrong.