Test Setup Failed
Push — main ( ca941c...e4ed3b )
by Acho
02:26
created

mtnmomo.TestWithTargetEnvironment   A

Complexity

Conditions 2

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nop 1
dl 0
loc 13
rs 10
c 0
b 0
f 0
1
package mtnmomo
2
3
import (
4
	"net/http"
5
	"testing"
6
7
	"github.com/stretchr/testify/assert"
8
)
9
10
const (
11
	testSubscriptionKey   = "subscriptionKey"
12
	testAPIKey            = "apiKey"
13
	testTargetEnvironment = "targetEnvironment"
14
	testAPIUser           = "apiUser"
15
)
16
17
func TestWithHTTPClient(t *testing.T) {
18
	t.Run("httpClient is not set when the httpClient is nil", func(t *testing.T) {
19
		// Setup
20
		t.Parallel()
21
22
		// Arrange
23
		config := defaultClientConfig()
24
25
		// Act
26
		WithHTTPClient(nil).apply(config)
27
28
		// Assert
29
		assert.NotNil(t, config.httpClient)
30
	})
31
32
	t.Run("httpClient is set when the httpClient is not nil", func(t *testing.T) {
33
		// Setup
34
		t.Parallel()
35
36
		// Arrange
37
		config := defaultClientConfig()
38
		newClient := &http.Client{Timeout: 300}
39
40
		// Act
41
		WithHTTPClient(newClient).apply(config)
42
43
		// Assert
44
		assert.NotNil(t, config.httpClient)
45
		assert.Equal(t, newClient.Timeout, config.httpClient.Timeout)
46
	})
47
}
48
49
func TestWithBaseURL(t *testing.T) {
50
	t.Run("baseURL is set successfully", func(t *testing.T) {
51
		// Setup
52
		t.Parallel()
53
54
		// Arrange
55
		baseURL := "https://example.com"
56
		config := defaultClientConfig()
57
58
		// Act
59
		WithBaseURL(baseURL).apply(config)
60
61
		// Assert
62
		assert.Equal(t, config.baseURL, config.baseURL)
63
	})
64
65
	t.Run("tailing / is trimmed from baseURL", func(t *testing.T) {
66
		// Setup
67
		t.Parallel()
68
69
		// Arrange
70
		baseURL := "https://example.com/"
71
		config := defaultClientConfig()
72
73
		// Act
74
		WithBaseURL(baseURL).apply(config)
75
76
		// Assert
77
		assert.Equal(t, "https://example.com", config.baseURL)
78
	})
79
}
80
81
func TestWithSubscriptionKey(t *testing.T) {
82
	t.Run("subscriptionKey is set successfully", func(t *testing.T) {
83
		// Setup
84
		t.Parallel()
85
86
		// Arrange
87
		config := defaultClientConfig()
88
89
		// Act
90
		WithSubscriptionKey(testSubscriptionKey).apply(config)
91
92
		// Assert
93
		assert.Equal(t, testSubscriptionKey, config.subscriptionKey)
94
	})
95
}
96
97
func TestWithAPIKey(t *testing.T) {
98
	t.Run("apiKey is set successfully", func(t *testing.T) {
99
		// Setup
100
		t.Parallel()
101
102
		// Arrange
103
		config := defaultClientConfig()
104
105
		// Act
106
		WithAPIKey(testAPIKey).apply(config)
107
108
		// Assert
109
		assert.Equal(t, testAPIKey, config.apiKey)
110
	})
111
}
112
113
func TestWithAPIUser(t *testing.T) {
114
	t.Run("apiUser is set successfully", func(t *testing.T) {
115
		// Setup
116
		t.Parallel()
117
118
		// Arrange
119
		config := defaultClientConfig()
120
121
		// Act
122
		WithAPIUser(testAPIUser).apply(config)
123
124
		// Assert
125
		assert.Equal(t, testAPIUser, config.apiUser)
126
	})
127
}
128
129
func TestWithTargetEnvironment(t *testing.T) {
130
	t.Run("targetEnvironment is set successfully", func(t *testing.T) {
131
		// Setup
132
		t.Parallel()
133
134
		// Arrange
135
		config := defaultClientConfig()
136
137
		// Act
138
		WithTargetEnvironment(testTargetEnvironment).apply(config)
139
140
		// Assert
141
		assert.Equal(t, testTargetEnvironment, config.targetEnvironment)
142
	})
143
}
144