MCPcopy Create free account
hub / github.com/cli/cli / Test_generateCompareURL

Function Test_generateCompareURL

pkg/cmd/pr/create/create_test.go:2802–3018  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2800}
2801
2802func Test_generateCompareURL(t *testing.T) {
2803 tests := []struct {
2804 name string
2805 ctx CreateContext
2806 state shared.IssueMetadataState
2807 httpStubs func(*testing.T, *httpmock.Registry)
2808 projectsV1Support gh.ProjectsV1Support
2809 want string
2810 wantErr bool
2811 }{
2812 {
2813 name: "basic",
2814 ctx: CreateContext{
2815 PRRefs: &skipPushRefs{
2816 qualifiedHeadRef: shared.NewQualifiedHeadRefWithoutOwner("feature"),
2817 baseRepo: api.InitRepoHostname(&api.Repository{Name: "REPO", Owner: api.RepositoryOwner{Login: "OWNER"}}, "github.com"),
2818 baseBranchName: "main",
2819 },
2820 },
2821 want: "https://github.com/OWNER/REPO/compare/main...feature?body=&expand=1",
2822 wantErr: false,
2823 },
2824 {
2825 name: "with labels",
2826 ctx: CreateContext{
2827 PRRefs: &skipPushRefs{
2828 qualifiedHeadRef: shared.NewQualifiedHeadRefWithoutOwner("b"),
2829 baseRepo: api.InitRepoHostname(&api.Repository{Name: "REPO", Owner: api.RepositoryOwner{Login: "OWNER"}}, "github.com"),
2830 baseBranchName: "a",
2831 },
2832 },
2833 state: shared.IssueMetadataState{
2834 Labels: []string{"one", "two three"},
2835 },
2836 want: "https://github.com/OWNER/REPO/compare/a...b?body=&expand=1&labels=one%2Ctwo+three",
2837 wantErr: false,
2838 },
2839 {
2840 name: "'/'s in branch names/labels are percent-encoded",
2841 ctx: CreateContext{
2842 PRRefs: &skipPushRefs{
2843 qualifiedHeadRef: mustParseQualifiedHeadRef("ORIGINOWNER:feature"),
2844 baseRepo: api.InitRepoHostname(&api.Repository{Name: "REPO", Owner: api.RepositoryOwner{Login: "UPSTREAMOWNER"}}, "github.com"),
2845 baseBranchName: "main/trunk",
2846 },
2847 },
2848 want: "https://github.com/UPSTREAMOWNER/REPO/compare/main%2Ftrunk...ORIGINOWNER:feature?body=&expand=1",
2849 wantErr: false,
2850 },
2851 {
2852 name: "Any of !'(),; but none of $&+=@ and : in branch names/labels are percent-encoded ",
2853 /*
2854 - Technically, per section 3.3 of RFC 3986, none of !$&'()*+,;= (sub-delims) and :[]@ (part of gen-delims) in path segments are optionally percent-encoded, but url.PathEscape percent-encodes !'(),; anyway
2855 - !$&'()+,;=@ is a valid Git branch name—essentially RFC 3986 sub-delims without * and gen-delims without :/?#[]
2856 - : is GitHub separator between a fork name and a branch name
2857 - See https://github.com/golang/go/issues/27559.
2858 */
2859 ctx: CreateContext{

Callers

nothing calls this directly

Calls 12

ExcludeMethod · 0.95
RegisterMethod · 0.95
VerifyMethod · 0.95
InitRepoHostnameFunction · 0.92
GraphQLFunction · 0.92
StringResponseFunction · 0.92
NewClientFromHTTPFunction · 0.92
generateCompareURLFunction · 0.85
RunMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected