chore: remove old and unused code
This commit is contained in:
@@ -3,11 +3,13 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -406,6 +408,44 @@ func TestCheckContextsAndAnnotationsArePaginated(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPullRequestEnrichmentBoundsConcurrentAnnotationRequests(t *testing.T) {
|
||||
var active, maximum atomic.Int32
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var request graphQLRequest
|
||||
if err := json.NewDecoder(r.Body).Decode(&request); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
current := active.Add(1)
|
||||
defer active.Add(-1)
|
||||
for observed := maximum.Load(); current > observed; observed = maximum.Load() {
|
||||
if maximum.CompareAndSwap(observed, current) {
|
||||
break
|
||||
}
|
||||
}
|
||||
time.Sleep(20 * time.Millisecond)
|
||||
_, _ = w.Write([]byte(`{"data":{"node":{"annotations":{
|
||||
"pageInfo":{"hasNextPage":false},"nodes":[]
|
||||
}}}}`))
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
client := NewGitHubClient(server.URL, "secret")
|
||||
details := PRDetails{}
|
||||
for index := range 6 {
|
||||
details.Checks = append(details.Checks, Check{
|
||||
ID: fmt.Sprintf("check-%d", index), Conclusion: "FAILURE",
|
||||
})
|
||||
}
|
||||
result := client.EnrichPullRequest(context.Background(), details)
|
||||
if len(result.CheckAnnotations) != len(details.Checks) || len(result.Issues) != 0 {
|
||||
t.Fatalf("enrichment = %#v", result)
|
||||
}
|
||||
if got := maximum.Load(); got < 2 || got > 4 {
|
||||
t.Fatalf("maximum concurrent annotation requests = %d, want 2..4", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckQueriesUseCurrentGitHubSchemaShape(t *testing.T) {
|
||||
for name, query := range map[string]string{"annotations": checkAnnotationsPageQuery} {
|
||||
if strings.Contains(query, "output {") ||
|
||||
|
||||
Reference in New Issue
Block a user