(t *testing.T)
| 134 | } |
| 135 | |
| 136 | func TestUrlFromOpts(t *testing.T) { |
| 137 | base, _ := url.Parse("https://raw.example.com/") |
| 138 | ghClient, err := github.NewClient(github.WithHTTPClient(&http.Client{})) |
| 139 | require.NoError(t, err) |
| 140 | client, err := NewClient(ghClient, base) |
| 141 | require.NoError(t, err) |
| 142 | |
| 143 | tests := []struct { |
| 144 | name string |
| 145 | opts *ContentOpts |
| 146 | owner string |
| 147 | repo string |
| 148 | path string |
| 149 | want string |
| 150 | }{ |
| 151 | { |
| 152 | name: "no opts (HEAD)", |
| 153 | opts: nil, |
| 154 | owner: "octocat", repo: "hello", path: "README.md", |
| 155 | want: "https://raw.example.com/octocat/hello/HEAD/README.md", |
| 156 | }, |
| 157 | { |
| 158 | name: "ref branch", |
| 159 | opts: &ContentOpts{Ref: "refs/heads/main"}, |
| 160 | owner: "octocat", repo: "hello", path: "README.md", |
| 161 | want: "https://raw.example.com/octocat/hello/refs/heads/main/README.md", |
| 162 | }, |
| 163 | { |
| 164 | name: "ref tag", |
| 165 | opts: &ContentOpts{Ref: "refs/tags/v1.0.0"}, |
| 166 | owner: "octocat", repo: "hello", path: "README.md", |
| 167 | want: "https://raw.example.com/octocat/hello/refs/tags/v1.0.0/README.md", |
| 168 | }, |
| 169 | { |
| 170 | name: "sha", |
| 171 | opts: &ContentOpts{SHA: "abc123"}, |
| 172 | owner: "octocat", repo: "hello", path: "README.md", |
| 173 | want: "https://raw.example.com/octocat/hello/abc123/README.md", |
| 174 | }, |
| 175 | } |
| 176 | |
| 177 | for _, tt := range tests { |
| 178 | t.Run(tt.name, func(t *testing.T) { |
| 179 | got := client.URLFromOpts(tt.opts, tt.owner, tt.repo, tt.path) |
| 180 | if got != tt.want { |
| 181 | t.Errorf("UrlFromOpts() = %q, want %q", got, tt.want) |
| 182 | } |
| 183 | }) |
| 184 | } |
| 185 | } |
nothing calls this directly
no test coverage detected