Fix high prio recommendations, add error / health screen
This commit is contained in:
@@ -6,11 +6,41 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestGraphQLRequestRecordsRateLimitHeaders(t *testing.T) {
|
||||
reset := time.Now().Add(time.Hour).Unix()
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.Header().Set("X-RateLimit-Limit", "5000")
|
||||
w.Header().Set("X-RateLimit-Remaining", "321")
|
||||
w.Header().Set("X-RateLimit-Used", "4679")
|
||||
w.Header().Set("X-RateLimit-Reset", fmtInt64(reset))
|
||||
_, _ = w.Write([]byte(`{"data":{"viewer":{"login":"octocat"}}}`))
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
client := NewGitHubClient(server.URL, "secret")
|
||||
var target struct {
|
||||
Viewer struct{ Login string }
|
||||
}
|
||||
if err := client.query(context.Background(), "query { viewer { login } }", nil, &target); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rate := client.RateLimit()
|
||||
if rate.Limit != 5000 || rate.Remaining != 321 || rate.Used != 4679 ||
|
||||
rate.ResetAt.Unix() != reset || rate.UpdatedAt.IsZero() {
|
||||
t.Fatalf("rate limit = %#v", rate)
|
||||
}
|
||||
}
|
||||
|
||||
func fmtInt64(value int64) string {
|
||||
return strconv.FormatInt(value, 10)
|
||||
}
|
||||
|
||||
func TestListBranchesPaginatesAndMarksTheDefaultBranch(t *testing.T) {
|
||||
requests := 0
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -304,9 +334,13 @@ func TestCheckContextsAndAnnotationsArePaginated(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(nodes) != 2 || len(nodes[1].Annotations.Nodes) != 2 ||
|
||||
nodes[1].Annotations.Nodes[0].Location.Start.Line != 4 ||
|
||||
nodes[1].Annotations.Nodes[1].Location.End.Line != 8 {
|
||||
annotations, err := client.checkAnnotations(context.Background(), nodes[1].ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(nodes) != 2 || len(annotations) != 2 ||
|
||||
annotations[0].Location.Start.Line != 4 ||
|
||||
annotations[1].Location.End.Line != 8 {
|
||||
t.Fatalf("paginated checks = %#v", nodes)
|
||||
}
|
||||
}
|
||||
@@ -513,7 +547,11 @@ func TestGetPullRequestLoadsConflictFilesForConflictingPR(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(got.ConflictFiles, []string{"src/conflict.go", "README.md"}) {
|
||||
t.Fatalf("conflict files = %#v", got.ConflictFiles)
|
||||
if len(got.ConflictFiles) != 0 {
|
||||
t.Fatalf("core refresh loaded conflict files eagerly: %#v", got.ConflictFiles)
|
||||
}
|
||||
enrichment := client.EnrichPullRequest(context.Background(), got)
|
||||
if !reflect.DeepEqual(enrichment.ConflictFiles, []string{"src/conflict.go", "README.md"}) {
|
||||
t.Fatalf("conflict files = %#v", enrichment.ConflictFiles)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user