tests: use proper context in test + add pull request workflow

This commit is contained in:
Stevan Freeborn
2026-01-12 17:59:46 -06:00
parent a9e49906e0
commit 54865ba64c
3 changed files with 48 additions and 7 deletions
+8 -6
View File
@@ -14,7 +14,9 @@ func TestGet(t *testing.T) {
w.WriteHeader(http.StatusOK)
})
err := client.Ping.Get(nil)
var nilContext context.Context = nil
err := client.Ping.Get(nilContext)
if err == nil {
t.Errorf("Expected error for nil context, got nil")
@@ -26,7 +28,7 @@ func TestGet(t *testing.T) {
w.WriteHeader(http.StatusOK)
})
ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(t.Context())
cancel()
@@ -44,7 +46,7 @@ func TestGet(t *testing.T) {
onspring.WithHTTPClient(&http.Client{Transport: &ErrorTransport{}}),
)
err := client.Ping.Get(context.Background())
err := client.Ping.Get(t.Context())
if err == nil {
t.Errorf("Expected network error, got nil")
@@ -62,7 +64,7 @@ func TestGet(t *testing.T) {
onspring.WithHTTPClient(client.HTTPClient()),
)
err := invalidClient.Ping.Get(context.Background())
err := invalidClient.Ping.Get(t.Context())
if err == nil {
t.Errorf("Expected request creation error, got nil")
@@ -82,7 +84,7 @@ func TestGet(t *testing.T) {
w.WriteHeader(http.StatusOK)
})
err := client.Ping.Get(context.Background())
err := client.Ping.Get(t.Context())
if err != nil {
t.Errorf("Expected no error, got %v", err)
@@ -94,7 +96,7 @@ func TestGet(t *testing.T) {
w.WriteHeader(http.StatusInternalServerError)
})
err := client.Ping.Get(context.Background())
err := client.Ping.Get(t.Context())
if err == nil {
t.Errorf("Expected error, got nil")