-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(pkguri)!: Parse ref and pkg as query params (#62)
* refactor(pkguri)!: Parse ref and pkg as query params * fix: tests * fix: tests and docs * fix: tests * fix: Update string representation
- Loading branch information
Showing
9 changed files
with
142 additions
and
38 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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
version = "2" | ||
[[pipeline]] | ||
name = "bar" | ||
repo_uri = "git@github.com:bluebrown/testing.git@dev/resources" | ||
repo_uri = "git@github.com:bluebrown/testing.git?ref=dev&pkg=resources" | ||
channels = ["foo"] |
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,105 @@ | ||
package git | ||
|
||
import "testing" | ||
|
||
func TestPackageURI_UnmarshalText(t *testing.T) { | ||
type fields struct { | ||
Repo string | ||
Ref string | ||
Pkg string | ||
} | ||
type args struct { | ||
b []byte | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
args args | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "Valid url with package", | ||
fields: fields{ | ||
Repo: "git@github.com:some-org/some-repo", | ||
Ref: "main", | ||
Pkg: "some-pkg", | ||
}, | ||
args: args{ | ||
b: []byte("git@github.com:some-org/some-repo.git?ref=main&pkg=some-pkg"), | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Valid url with package specified first", | ||
fields: fields{ | ||
Repo: "git@github.com:some-org/some-repo", | ||
Ref: "main", | ||
Pkg: "some-pkg", | ||
}, | ||
args: args{ | ||
b: []byte("git@github.com:some-org/some-repo.git?pkg=some-pkg&ref=main"), | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Valid url only uses first declaration of query params", | ||
fields: fields{ | ||
Repo: "git@github.com:some-org/some-repo", | ||
Ref: "main", | ||
Pkg: "some-pkg", | ||
}, | ||
args: args{ | ||
b: []byte("git@github.com:some-org/some-repo.git?ref=main&pkg=some-pkg&ref=fail&pkg=fail"), | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Valid url without package", | ||
fields: fields{ | ||
Repo: "git@github.com:some-org/some-repo", | ||
Ref: "main", | ||
Pkg: "", | ||
}, | ||
args: args{ | ||
b: []byte("git@github.com:some-org/some-repo.git?ref=main"), | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Missing query params", | ||
fields: fields{ | ||
Repo: "", | ||
Ref: "", | ||
Pkg: "", | ||
}, | ||
args: args{ | ||
b: []byte("git@github.com:some-org/some-repo.git"), | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "Missing ref", | ||
fields: fields{ | ||
Repo: "", | ||
Ref: "", | ||
Pkg: "", | ||
}, | ||
args: args{ | ||
b: []byte("git@github.com:some-org/some-repo.git?pkg=some-pkg"), | ||
}, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
uri := &PackageURI{ | ||
Repo: tt.fields.Repo, | ||
Ref: tt.fields.Ref, | ||
Pkg: tt.fields.Pkg, | ||
} | ||
if err := uri.UnmarshalText(tt.args.b); (err != nil) != tt.wantErr { | ||
t.Errorf("UnmarshalText() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} |
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