accept $RECURSIVE_MISSING_WEBHOOK $RECURSIVE_MISSING_WEBHOOK_CACHE_D
This commit is contained in:
36
main_test.go
36
main_test.go
@@ -3,6 +3,8 @@ package main_test
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path"
|
||||
"slices"
|
||||
@@ -149,6 +151,38 @@ func TestRunWith(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRecursive(t *testing.T) {
|
||||
webhooks := []string{}
|
||||
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Query().Get("p") == "" {
|
||||
t.Errorf("webhook wasn't called with ?p: %s", r.URL.String())
|
||||
}
|
||||
b, _ := ioutil.ReadAll(r.Body)
|
||||
if string(b) != r.URL.Query().Get("p") {
|
||||
t.Errorf("webhook wasn't called with ?p == {body}: %q vs %q", r.URL.Query().Get("p"), b)
|
||||
}
|
||||
webhooks = append(webhooks, string(b))
|
||||
}))
|
||||
t.Cleanup(s.Close)
|
||||
t.Cleanup(func() {
|
||||
t.Logf("webhooks: %+v", webhooks)
|
||||
if len(webhooks) == 0 {
|
||||
t.Errorf("expected webhook calls but got none")
|
||||
}
|
||||
deduped := slices.Clone(webhooks)
|
||||
slices.Sort(deduped)
|
||||
slices.Compact(deduped)
|
||||
if len(deduped) != len(webhooks) {
|
||||
t.Errorf("expected no duplicate webhooks but got %+v", webhooks)
|
||||
}
|
||||
})
|
||||
|
||||
main.WebhookOnRecursiveMiss = s.URL
|
||||
main.WebhookOnRecursiveMissCacheD = t.TempDir()
|
||||
t.Cleanup(func() {
|
||||
main.WebhookOnRecursiveMiss = ""
|
||||
main.WebhookOnRecursiveMissCacheD = ""
|
||||
})
|
||||
|
||||
was, _ := os.Getwd()
|
||||
t.Cleanup(func() { os.Chdir(was) })
|
||||
os.Chdir(t.TempDir())
|
||||
@@ -196,6 +230,8 @@ func TestRecursive(t *testing.T) {
|
||||
|
||||
if err := main.Recursive(context.Background()); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if err := main.Recursive(context.Background()); err != nil {
|
||||
t.Fatalf("failed second run: %v", err)
|
||||
}
|
||||
|
||||
exists(t, path.Join(outd, "A", "A_SAEA.a"))
|
||||
|
||||
Reference in New Issue
Block a user