-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure the repo URL is a valid git, http or https URL Signed-off-by: Chmouel Boudjnah <[email protected]>
- Loading branch information
1 parent
fc02b29
commit 123a690
Showing
2 changed files
with
91 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,16 +60,84 @@ func TestGetSelector(t *testing.T) { | |
} | ||
|
||
func TestValidateParams(t *testing.T) { | ||
resolver := Resolver{} | ||
|
||
paramsWithRevision := map[string]string{ | ||
urlParam: "http://foo", | ||
pathParam: "bar", | ||
revisionParam: "baz", | ||
tests := []struct { | ||
name string | ||
wantErr string | ||
params map[string]string | ||
}{ | ||
{ | ||
name: "params with revision", | ||
params: map[string]string{ | ||
urlParam: "http://foo/bar/hello/moto", | ||
pathParam: "bar", | ||
revisionParam: "baz", | ||
}, | ||
}, | ||
{ | ||
name: "https url", | ||
params: map[string]string{ | ||
urlParam: "https://foo/bar/hello/moto", | ||
pathParam: "bar", | ||
revisionParam: "baz", | ||
}, | ||
}, | ||
{ | ||
name: "https url with username password", | ||
params: map[string]string{ | ||
urlParam: "https://user:pass@foo/bar/hello/moto", | ||
pathParam: "bar", | ||
revisionParam: "baz", | ||
}, | ||
}, | ||
{ | ||
name: "git server url", | ||
params: map[string]string{ | ||
urlParam: "git://repo/hello/moto", | ||
pathParam: "bar", | ||
revisionParam: "baz", | ||
}, | ||
}, | ||
{ | ||
name: "git url from a local repository", | ||
params: map[string]string{ | ||
urlParam: "/tmp/repo", | ||
pathParam: "bar", | ||
revisionParam: "baz", | ||
}, | ||
}, | ||
{ | ||
name: "git url from a git ssh repository", | ||
params: map[string]string{ | ||
urlParam: "[email protected]:foo/bar", | ||
pathParam: "bar", | ||
revisionParam: "baz", | ||
}, | ||
}, | ||
{ | ||
name: "bad url", | ||
params: map[string]string{ | ||
urlParam: "foo://bar", | ||
pathParam: "path", | ||
revisionParam: "revision", | ||
}, | ||
wantErr: "invalid git repository url: foo://bar", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
resolver := Resolver{} | ||
err := resolver.ValidateParams(context.Background(), toParams(tt.params)) | ||
if tt.wantErr == "" { | ||
if err != nil { | ||
t.Fatalf("unexpected error validating params: %v", err) | ||
} | ||
return | ||
} | ||
|
||
if err := resolver.ValidateParams(context.Background(), toParams(paramsWithRevision)); err != nil { | ||
t.Fatalf("unexpected error validating params: %v", err) | ||
if d := cmp.Diff(tt.wantErr, err.Error()); d != "" { | ||
t.Errorf("unexpected error: %s", diff.PrintWantGot(d)) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
|