lemonsqueezy.TestWithHTTPClient   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 29
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 13
nop 1
dl 0
loc 29
rs 9.75
c 0
b 0
f 0
1
package lemonsqueezy
2
3
import (
4
	"net/http"
5
	"testing"
6
7
	"github.com/stretchr/testify/assert"
8
)
9
10
func TestWithHTTPClient(t *testing.T) {
11
	t.Run("httpClient is not set when the httpClient is nil", func(t *testing.T) {
12
		// Setup
13
		t.Parallel()
14
15
		// Arrange
16
		config := defaultClientConfig()
17
18
		// Act
19
		WithHTTPClient(nil).apply(config)
20
21
		// Assert
22
		assert.NotNil(t, config.httpClient)
23
	})
24
25
	t.Run("httpClient is set when the httpClient is not nil", func(t *testing.T) {
26
		// Setup
27
		t.Parallel()
28
29
		// Arrange
30
		config := defaultClientConfig()
31
		newClient := &http.Client{Timeout: 300}
32
33
		// Act
34
		WithHTTPClient(newClient).apply(config)
35
36
		// Assert
37
		assert.NotNil(t, config.httpClient)
38
		assert.Equal(t, newClient.Timeout, config.httpClient.Timeout)
39
	})
40
}
41
42
func TestWithBaseURL(t *testing.T) {
43
	t.Run("baseURL is set successfully", func(t *testing.T) {
44
		// Setup
45
		t.Parallel()
46
47
		// Arrange
48
		baseURL := "https://example.com"
49
		config := defaultClientConfig()
50
51
		// Act
52
		WithBaseURL(baseURL).apply(config)
53
54
		// Assert
55
		assert.Equal(t, config.baseURL, config.baseURL)
56
	})
57
58
	t.Run("tailing / is trimmed from baseURL", func(t *testing.T) {
59
		// Setup
60
		t.Parallel()
61
62
		// Arrange
63
		baseURL := "https://example.com/"
64
		config := defaultClientConfig()
65
66
		// Act
67
		WithBaseURL(baseURL).apply(config)
68
69
		// Assert
70
		assert.Equal(t, "https://example.com", config.baseURL)
71
	})
72
}
73
74
func TestWithAPIKey(t *testing.T) {
75
	// Setup
76
	t.Parallel()
77
78
	// Arrange
79
	config := defaultClientConfig()
80
	apiKey := "api-key"
81
82
	// Act
83
	WithAPIKey(apiKey).apply(config)
84
85
	// Assert
86
	assert.Equal(t, apiKey, config.apiKey)
87
}
88
89
func TestWithSigningSecret(t *testing.T) {
90
	// Setup
91
	t.Parallel()
92
93
	// Arrange
94
	config := defaultClientConfig()
95
	signingSecret := "signing-secret"
96
97
	// Act
98
	WithSigningSecret(signingSecret).apply(config)
99
100
	// Assert
101
	assert.Equal(t, signingSecret, config.signingSecret)
102
}
103