44 "net/http"
55 "net/http/httptest"
66 "net/url"
7+ "os"
78 "testing"
89
910 "github.com/stretchr/testify/assert"
@@ -18,6 +19,31 @@ func TestNew(t *testing.T) {
1819 assert .NotNil (t , client .httpClient )
1920}
2021
22+ func TestNew_WithEnvironmentVariable (t * testing.T ) {
23+ // Save original environment variable
24+ originalURL := os .Getenv ("CLOUDAMQP_URL" )
25+ defer os .Setenv ("CLOUDAMQP_URL" , originalURL )
26+
27+ // Test with custom base URL from environment variable
28+ customURL := "https://custom.example.com/api"
29+ os .Setenv ("CLOUDAMQP_URL" , customURL )
30+
31+ apiKey := "test-api-key"
32+ client := New (apiKey )
33+
34+ assert .NotNil (t , client )
35+ assert .Equal (t , apiKey , client .apiKey )
36+ assert .Equal (t , customURL , client .baseURL )
37+ assert .NotNil (t , client .httpClient )
38+
39+ // Test with empty environment variable (should use default)
40+ os .Setenv ("CLOUDAMQP_URL" , "" )
41+ client = New (apiKey )
42+
43+ assert .NotNil (t , client )
44+ assert .Equal (t , "https://customer.cloudamqp.com/api" , client .baseURL )
45+ }
46+
2147func TestMakeRequest_GET_Success (t * testing.T ) {
2248 // Mock server
2349 server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
0 commit comments