Skip to content

Commit

Permalink
Tests updated to include validation for parsing
Browse files Browse the repository at this point in the history
Improved the tests to include validation for parsing the URL.
  • Loading branch information
naveensrinivasan committed Dec 22, 2020
1 parent fd3a2a8 commit 4362368
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/scorecard.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (r *RepoURL) Set(s string) error {
}

if len(strings.TrimSpace(split[0])) == 0 || len(strings.TrimSpace(split[1])) == 0 {
log.Fatalf("invalid repo flag: [%s] pass the full repository URL", s)
log.Fatalf("invalid repo flag: [%s], pass the full repository URL", s)
}

r.Host, r.Owner, r.Repo = u.Host, split[0], split[1]
Expand Down
24 changes: 18 additions & 6 deletions pkg/scorecard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,30 @@ func TestRepoURL_Set(t *testing.T) {
name: "Valid http address",
fields: fields{
Host: "github.com",
Owner: "kubeflow",
Owner: "foo",
Repo: "kubeflow",
},
args: args{s: "https://github.com/kubeflow/kubeflow"},
args: args{s: "https://github.com/foo/kubeflow"},
wantErr: false,
},
{
name: "Valid http address with trailing slash",
fields: fields{
Host: "github.com",
Owner: "kubeflow",
Owner: "foo",
Repo: "kubeflow",
},
args: args{s: "https://github.com/kubeflow/kubeflow/"},
args: args{s: "https://github.com/foo/kubeflow/"},
wantErr: false,
},
{
name: "Non github repository",
fields: fields{
Host: "gitlab.com",
Owner: "kubeflow",
Owner: "foo",
Repo: "kubeflow",
},
args: args{s: "https://gitlab.com/kubeflow/kubeflow"},
args: args{s: "https://gitlab.com/foo/kubeflow"},
wantErr: true,
},
}
Expand All @@ -71,9 +71,21 @@ func TestRepoURL_Set(t *testing.T) {
Owner: tt.fields.Owner,
Repo: tt.fields.Repo,
}
t.Log("Test")
if err := r.Set(tt.args.s); (err != nil) != tt.wantErr {
t.Errorf("RepoURL.Set() error = %v, wantErr %v", err, tt.wantErr)
}
if !tt.wantErr {
if tt.fields.Host != r.Host {
t.Errorf("Repo Host expected to be %s but got %s", tt.fields.Host, r.Host)
}
if tt.fields.Owner != r.Owner {
t.Errorf("Repo owner expected to be %s but got %s", tt.fields.Owner, r.Owner)
}
if tt.fields.Repo != r.Repo {
t.Errorf("Repo expected to be %s but got %s", tt.fields.Repo, r.Repo)
}
}
})
}
}

0 comments on commit 4362368

Please sign in to comment.