MCPcopy
hub / github.com/sourcegraph/checkup / withGitHubServer

Function withGitHubServer

storage/github/github_test.go:70–292  ·  view source on GitHub ↗
(t *testing.T, specimen Storage, f func(*github.Client))

Source from the content-addressed store, hash-verified

68}
69
70func withGitHubServer(t *testing.T, specimen Storage, f func(*github.Client)) {
71 // test server
72 mux := http.NewServeMux()
73 server := httptest.NewServer(mux)
74
75 // github client configured to use test server
76 client := github.NewClient(nil)
77 url, _ := url.Parse(server.URL + "/")
78 client.BaseURL = url
79 client.UploadURL = url
80 defer server.Close()
81
82 // files := map[string]string{}
83 index := map[string]int64{
84 "1501523631505010894-check.json": time.Now().UnixNano(),
85 "1501525202306053005-check.json": time.Now().UnixNano(),
86 }
87 gitRepo := struct {
88 LastUpdated int64
89 Files map[string]bool
90 }{
91 LastUpdated: time.Now().UnixNano(),
92 Files: map[string]bool{},
93 }
94
95 fixtureFiles := []string{"1501523631505010894-check.json", "1501525202306053005-check.json", "index.json"}
96 for _, file := range fixtureFiles {
97 gitRepo.Files[filepath.Join(specimen.Dir, file)] = true
98 }
99
100 serverSHAForRepo := sha(toJSON(gitRepo))
101
102 mux.HandleFunc("/repos/o/r/git/refs/heads/"+specimen.Branch, func(w http.ResponseWriter, r *http.Request) {
103 fmt.Printf("Processing %s %s\n", r.Method, r.URL.Path)
104 if got := r.Method; got != "GET" {
105 t.Errorf("Request method: %v, want %v", got, "GET")
106 }
107 mustWriteJSON(w, github.Reference{
108 Ref: github.String("refs/heads/" + specimen.Branch),
109 Object: &github.GitObject{
110 Type: github.String("commit"),
111 SHA: github.String(serverSHAForRepo),
112 },
113 })
114 })
115
116 mux.HandleFunc("/repos/o/r/git/trees/", func(w http.ResponseWriter, r *http.Request) {
117 fmt.Printf("Processing %s %s\n", r.Method, r.URL.Path)
118 if got := r.FormValue("recursive"); got != "1" {
119 t.Errorf("Expected recursive flag to be 1, got %v", got)
120 }
121
122 if sha := strings.TrimPrefix(r.URL.Path, "/repos/o/r/git/trees/"); sha != serverSHAForRepo {
123 t.Errorf("Expected to fetch tree %s, got: %v", serverSHAForRepo, sha)
124 }
125
126 entries := []github.TreeEntry{
127 {

Callers 2

TestGitHubWithoutSubdirFunction · 0.85
TestGitHubWithSubdirFunction · 0.85

Calls 10

shaFunction · 0.85
toJSONFunction · 0.85
mustWriteJSONFunction · 0.85
base64EncodedFunction · 0.85
repositoryContentFunction · 0.85
pathForIndexFunction · 0.85
pathForGitRepoFunction · 0.85
ErrorMethod · 0.80
fFunction · 0.50
StringMethod · 0.45

Tested by

no test coverage detected