-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from muaz-32/add-e2e-tests
Added e2e for the `login` command using flags.
- Loading branch information
Showing
3 changed files
with
131 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package e2e | ||
|
||
import ( | ||
"github.com/goharbor/harbor-cli/cmd/harbor/root" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func Test_Success(t *testing.T) { | ||
cmd := root.LoginCommand() | ||
var err error | ||
|
||
validServerAddresses := []string{ | ||
"http://demo.goharbor.io:80", | ||
"https://demo.goharbor.io:8443", | ||
"http://demo.goharbor.io", | ||
"https://demo.goharbor.io", | ||
"demo.goharbor.io", | ||
} | ||
|
||
for _, serverAddress := range validServerAddresses { | ||
args := []string{ | ||
serverAddress, | ||
} | ||
cmd.SetArgs(args) | ||
|
||
err = cmd.Flags().Set("name", "test") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
err = cmd.Flags().Set("username", "admin") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
err = cmd.Flags().Set("password", "Harbor12345") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
err = cmd.Execute() | ||
|
||
assert.NoError(t, err) | ||
} | ||
} | ||
|
||
func Test_Failure_WrongServer(t *testing.T) { | ||
cmd := root.LoginCommand() | ||
var err error | ||
|
||
args := []string{ | ||
"demo.goharbor.io", | ||
} | ||
cmd.SetArgs(args) | ||
|
||
err = cmd.Flags().Set("name", "test") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
err = cmd.Flags().Set("username", "admin") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
err = cmd.Flags().Set("password", "Harbor12345") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
err = cmd.Execute() | ||
|
||
assert.Error(t, err) | ||
} | ||
|
||
func Test_Failure_WrongUsername(t *testing.T) { | ||
cmd := root.LoginCommand() | ||
var err error | ||
|
||
args := []string{ | ||
"http://demo.goharbor.io", | ||
} | ||
cmd.SetArgs(args) | ||
|
||
err = cmd.Flags().Set("name", "test") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
err = cmd.Flags().Set("username", "wrong") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
err = cmd.Flags().Set("password", "Harbor12345") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
err = cmd.Execute() | ||
|
||
assert.Error(t, err) | ||
} | ||
|
||
func Test_Failure_WrongPassword(t *testing.T) { | ||
cmd := root.LoginCommand() | ||
var err error | ||
|
||
args := []string{ | ||
"http://demo.goharbor.io", | ||
} | ||
cmd.SetArgs(args) | ||
|
||
err = cmd.Flags().Set("name", "test") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
err = cmd.Flags().Set("username", "admin") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
err = cmd.Flags().Set("password", "wrong") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
err = cmd.Execute() | ||
|
||
assert.Error(t, err) | ||
} |