MCPcopy
hub / github.com/github/github-mcp-server / Test_resolveGitReference

Function Test_resolveGitReference

pkg/github/repositories_test.go:4127–4386  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

4125}
4126
4127func Test_resolveGitReference(t *testing.T) {
4128 ctx := context.Background()
4129 owner := "owner"
4130 repo := "repo"
4131
4132 tests := []struct {
4133 name string
4134 ref string
4135 sha string
4136 mockSetup func() *http.Client
4137 expectedOutput *raw.ContentOpts
4138 expectError bool
4139 errorContains string
4140 }{
4141 {
4142 name: "sha takes precedence over ref",
4143 ref: "refs/heads/main",
4144 sha: "123sha456",
4145 mockSetup: func() *http.Client {
4146 // No API calls should be made when SHA is provided
4147 return NewMockedHTTPClient()
4148 },
4149 expectedOutput: &raw.ContentOpts{
4150 SHA: "123sha456",
4151 },
4152 expectError: false,
4153 },
4154 {
4155 name: "use default branch if ref and sha both empty",
4156 ref: "",
4157 sha: "",
4158 mockSetup: func() *http.Client {
4159 return NewMockedHTTPClient(
4160 WithRequestMatchHandler(
4161 GetReposByOwnerByRepo,
4162 http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
4163 w.WriteHeader(http.StatusOK)
4164 _, _ = w.Write([]byte(`{"name": "repo", "default_branch": "main"}`))
4165 }),
4166 ),
4167 WithRequestMatchHandler(
4168 GetReposGitRefByOwnerByRepoByRef,
4169 http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
4170 assert.Contains(t, r.URL.Path, "/git/ref/heads/main")
4171 w.WriteHeader(http.StatusOK)
4172 _, _ = w.Write([]byte(`{"ref": "refs/heads/main", "object": {"sha": "main-sha"}}`))
4173 }),
4174 ),
4175 )
4176 },
4177 expectedOutput: &raw.ContentOpts{
4178 Ref: "refs/heads/main",
4179 SHA: "main-sha",
4180 },
4181 expectError: false,
4182 },
4183 {
4184 name: "fully qualified ref passed through unchanged",

Callers

nothing calls this directly

Calls 7

WithRequestMatchHandlerFunction · 0.85
mustNewGHClientFunction · 0.85
resolveGitReferenceFunction · 0.85
WriteHeaderMethod · 0.80
NewMockedHTTPClientFunction · 0.70
WriteMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected