This repository has been archived by the owner on Jan 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 558
More cmd package unit tests #2997
Merged
Merged
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2c4420c
new deploy cmd test
8d7232f
add validate test deploy
6aac6a2
fix lint
46aa80c
added newcmd tests
1b23476
fix var
f6578c1
add load function in deploy run
f8e7f6a
scale validate tests
c122886
fix upgrade test
b88c053
move authargs validation
78f470c
fixed scale.go error handling
a12af93
fix typo
441a7f9
remove unreachable code
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 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 |
---|---|---|
|
@@ -11,6 +11,7 @@ import ( | |
"github.com/Azure/acs-engine/pkg/armhelpers" | ||
"github.com/satori/go.uuid" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const ExampleAPIModel = `{ | ||
|
@@ -72,6 +73,123 @@ func getAPIModelWithoutServicePrincipalProfile(baseAPIModel string, useManagedId | |
strconv.FormatBool(useManagedIdentity)) | ||
} | ||
|
||
func TestNewDeployCmd(t *testing.T) { | ||
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. unit_test_coverage++ |
||
output := newDeployCmd() | ||
if output.Use != deployName || output.Short != deployShortDescription || output.Long != deployLongDescription { | ||
t.Fatalf("deploy command should have use %s equal %s, short %s equal %s and long %s equal to %s", output.Use, deployName, output.Short, deployShortDescription, output.Long, versionLongDescription) | ||
} | ||
|
||
expectedFlags := []string{"api-model", "dns-prefix", "auto-suffix", "output-directory", "ca-private-key-path", "resource-group", "location", "force-overwrite"} | ||
for _, f := range expectedFlags { | ||
if output.Flags().Lookup(f) == nil { | ||
t.Fatalf("deploy command should have flag %s", f) | ||
} | ||
} | ||
} | ||
|
||
func TestValidate(t *testing.T) { | ||
r := &cobra.Command{} | ||
apimodelPath := "apimodel-unit-test.json" | ||
|
||
_, err := os.Create(apimodelPath) | ||
if err != nil { | ||
t.Fatalf("unable to create test apimodel path: %s", err.Error()) | ||
} | ||
defer os.Remove(apimodelPath) | ||
|
||
cases := []struct { | ||
dc *deployCmd | ||
expectedErr error | ||
args []string | ||
}{ | ||
{ | ||
dc: &deployCmd{ | ||
apimodelPath: "", | ||
dnsPrefix: "test", | ||
outputDirectory: "output/test", | ||
forceOverwrite: false, | ||
caCertificatePath: "test", | ||
caPrivateKeyPath: "test", | ||
}, | ||
args: []string{}, | ||
expectedErr: fmt.Errorf("--api-model was not supplied, nor was one specified as a positional argument"), | ||
}, | ||
{ | ||
dc: &deployCmd{ | ||
apimodelPath: "", | ||
dnsPrefix: "test", | ||
outputDirectory: "output/test", | ||
caCertificatePath: "test", | ||
caPrivateKeyPath: "test", | ||
}, | ||
args: []string{"wrong/path"}, | ||
expectedErr: fmt.Errorf("specified api model does not exist (wrong/path)"), | ||
}, | ||
{ | ||
dc: &deployCmd{ | ||
apimodelPath: "", | ||
dnsPrefix: "test", | ||
outputDirectory: "output/test", | ||
caCertificatePath: "test", | ||
caPrivateKeyPath: "test", | ||
}, | ||
args: []string{"test/apimodel.json", "some_random_stuff"}, | ||
expectedErr: fmt.Errorf("too many arguments were provided to 'deploy'"), | ||
}, | ||
{ | ||
dc: &deployCmd{ | ||
apimodelPath: "", | ||
dnsPrefix: "test", | ||
outputDirectory: "output/test", | ||
caCertificatePath: "test", | ||
caPrivateKeyPath: "test", | ||
}, | ||
args: []string{apimodelPath}, | ||
expectedErr: fmt.Errorf("--location must be specified"), | ||
}, | ||
{ | ||
dc: &deployCmd{ | ||
apimodelPath: "", | ||
dnsPrefix: "test", | ||
outputDirectory: "output/test", | ||
caCertificatePath: "test", | ||
caPrivateKeyPath: "test", | ||
location: "west europe", | ||
}, | ||
args: []string{apimodelPath}, | ||
expectedErr: nil, | ||
}, | ||
{ | ||
dc: &deployCmd{ | ||
apimodelPath: apimodelPath, | ||
dnsPrefix: "test", | ||
outputDirectory: "output/test", | ||
caCertificatePath: "test", | ||
caPrivateKeyPath: "test", | ||
location: "canadaeast", | ||
}, | ||
args: []string{}, | ||
expectedErr: nil, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
err = c.dc.validate(r, c.args) | ||
if err != nil && c.expectedErr != nil { | ||
if err.Error() != c.expectedErr.Error() { | ||
t.Fatalf("expected validate deploy command to return error %s, but instead got %s", c.expectedErr.Error(), err.Error()) | ||
} | ||
} else { | ||
if c.expectedErr != nil { | ||
t.Fatalf("expected validate deploy command to return error %s, but instead got no error", c.expectedErr.Error()) | ||
} else if err != nil { | ||
t.Fatalf("expected validate deploy command to return no error, but instead got %s", err.Error()) | ||
} | ||
|
||
} | ||
} | ||
} | ||
|
||
func TestAutofillApimodelWithoutManagedIdentityCreatesCreds(t *testing.T) { | ||
testAutodeployCredentialHandling(t, false, "", "") | ||
} | ||
|
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small refactor here -> split validate and load into two separate functions