Skip to content

Commit

Permalink
test: add test for new abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
Cupprum committed Jul 13, 2024
1 parent ef669cf commit 6f34196
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions logic/notifier/notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"
)

Expand All @@ -16,6 +17,37 @@ func TestGenerateText(t *testing.T) {
}
}

func TestExecutePostRequest(t *testing.T) {
os.Setenv("OTEL_SERVICE_NAME", "seatchecker-notifier-lambda-test")

ctx := context.Background()
cleanup, err := setupOtel(ctx)
if err != nil {
t.Fatal(err)
}
defer cleanup()

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
t.Fatalf("wrong http method, expected: POST, received: %v", r.Method)
}
if r.Header["Testkey"][0] != "Testval" {
t.Fatalf("wrong title, expected: Seatchecker, received: %v", r.Header["Title"][0])
}
}))
defer ts.Close()

h := map[string]string{
"Testkey": "Testval",
}
b := strings.NewReader("test-text")
err = executePostRequest(ctx, ts.URL, h, b)

if err != nil {
t.Fatalf("error: %v", err)
}
}

func TestSendNotification(t *testing.T) {
os.Setenv("OTEL_SERVICE_NAME", "seatchecker-notifier-lambda-test")

Expand Down

0 comments on commit 6f34196

Please sign in to comment.