-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add alternate azure git repo urls to credentials for submodules #372
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"os" | ||
"reflect" | ||
"sort" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
@@ -115,18 +117,76 @@ func Test_processInput(t *testing.T) { | |
|
||
processInput(&input, &flags) | ||
|
||
if len(input.Credentials) != 4 { | ||
t.Fatal("expected credentials to be added") | ||
} | ||
// Ensure all credentials are either git_source or azure | ||
// Ensure all credentials are either git_source or nuget | ||
for _, cred := range input.Credentials { | ||
if cred["type"] != "git_source" && cred["type"] != "nuget_feed" { | ||
t.Errorf("expected credentials to be either git_source or nuget_feed, got %s", cred["type"]) | ||
} | ||
} | ||
|
||
// Validate NuGet feeds | ||
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. This behavior is unchanged, but was not explicitly tested. |
||
actualNuGetFeedStrings := []string{} | ||
for _, cred := range input.Credentials { | ||
if cred["type"] == "nuget_feed" { | ||
actualNuGetFeedStrings = append(actualNuGetFeedStrings, fmt.Sprintf("%s|%s", cred["host"], cred["password"])) | ||
} | ||
} | ||
|
||
expectedNuGetFeeds := []string{ | ||
"org.pkgs.visualstudio.com|$LOCAL_AZURE_ACCESS_TOKEN", | ||
"pkgs.dev.azure.com|$LOCAL_AZURE_ACCESS_TOKEN", | ||
} | ||
|
||
assertStringArraysEqual(t, expectedNuGetFeeds, actualNuGetFeedStrings) | ||
|
||
// Validate credentials | ||
actualCredentialStrings := []string{} | ||
for _, cred := range input.Credentials { | ||
if cred["type"] == "git_source" { | ||
actualCredentialStrings = append(actualCredentialStrings, fmt.Sprintf("%s|%s|%s", cred["host"], cred["username"], cred["password"])) | ||
} | ||
} | ||
|
||
expectedGitCredentials := []string{ | ||
"dev.azure.com|org|$LOCAL_AZURE_ACCESS_TOKEN", | ||
"dev.azure.com|x-access-token|$LOCAL_AZURE_ACCESS_TOKEN", | ||
"org.visualstudio.com|x-access-token|$LOCAL_AZURE_ACCESS_TOKEN", | ||
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. This is the new URL that's added to the credentials. |
||
} | ||
|
||
assertStringArraysEqual(t, expectedGitCredentials, actualCredentialStrings) | ||
|
||
// Validate credentials metadata | ||
credentialsMetadataHosts := map[string]string{} | ||
for _, cred := range input.Job.CredentialsMetadata { | ||
if cred["type"] == "git_source" { | ||
// dedup hosts with a map | ||
credentialsMetadataHosts[fmt.Sprintf("%s", cred["host"])] = "" | ||
} | ||
} | ||
|
||
actualCredentialsMetadataHosts := []string{} | ||
for host := range credentialsMetadataHosts { | ||
actualCredentialsMetadataHosts = append(actualCredentialsMetadataHosts, host) | ||
} | ||
|
||
expectedGitCredentalsMetadataHosts := []string{ | ||
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. This is what the unnecessary deleted code did, just adding explicit verification here. |
||
"dev.azure.com", | ||
"org.visualstudio.com", | ||
} | ||
|
||
assertStringArraysEqual(t, expectedGitCredentalsMetadataHosts, actualCredentialsMetadataHosts) | ||
}) | ||
} | ||
|
||
func assertStringArraysEqual(t *testing.T, expected, actual []string) { | ||
sort.Strings(expected) | ||
sort.Strings(actual) | ||
|
||
if !reflect.DeepEqual(expected, actual) { | ||
t.Errorf("expected strings to be\n\t%v\n got\n\t%v", expected, actual) | ||
} | ||
} | ||
|
||
func Test_extractInput(t *testing.T) { | ||
t.Run("test arguments", func(t *testing.T) { | ||
cmd := NewUpdateCommand() | ||
|
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.
This comment is incorrect; the next section is not skipped and the
CredentialsMetadata
is correctly updated. The test has been modified to verify this.