(t *testing.T, specimen Storage, f func(*github.Client))
| 68 | } |
| 69 | |
| 70 | func 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 | { |
no test coverage detected