client_option_test.go   A
last analyzed

Size/Duplication

Total Lines 121
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 12
eloc 52
dl 0
loc 121
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A orangemoney.TestWithAuthToken 0 14 2
A orangemoney.TestWithUsername 0 14 2
A orangemoney.TestWithHTTPClient 0 29 3
A orangemoney.TestWithBaseURL 0 29 3
A orangemoney.TestWithPassword 0 14 2
1
package orangemoney
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, 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 TestWithUsername(t *testing.T) {
75
	t.Run("username is set successfully", func(t *testing.T) {
76
		// Setup
77
		t.Parallel()
78
79
		// Arrange
80
		username := "username-1"
81
		config := defaultClientConfig()
82
83
		// Act
84
		WithUsername(username).apply(config)
85
86
		// Assert
87
		assert.Equal(t, username, config.username)
88
	})
89
}
90
91
func TestWithPassword(t *testing.T) {
92
	t.Run("password is set successfully", func(t *testing.T) {
93
		// Setup
94
		t.Parallel()
95
96
		// Arrange
97
		password := "password-1"
98
		config := defaultClientConfig()
99
100
		// Act
101
		WithPassword(password).apply(config)
102
103
		// Assert
104
		assert.Equal(t, password, config.password)
105
	})
106
}
107
108
func TestWithAuthToken(t *testing.T) {
109
	t.Run("authToken is set successfully", func(t *testing.T) {
110
		// Setup
111
		t.Parallel()
112
113
		// Arrange
114
		authToken := "token-1"
115
		config := defaultClientConfig()
116
117
		// Act
118
		WithAuthToken(authToken).apply(config)
119
120
		// Assert
121
		assert.Equal(t, authToken, config.authToken)
122
	})
123
}
124