client_test.go   A
last analyzed

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 31
dl 0
loc 60
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B mobilenig.TestNew 0 51 5
1
package mobilenig
2
3
import (
4
	"net/http"
5
	"testing"
6
7
	"github.com/stretchr/testify/assert"
8
)
9
10
func TestNew(t *testing.T) {
11
	t.Run("default configuration is used when no option is set", func(t *testing.T) {
12
		// act
13
		client := New()
14
15
		// assert
16
		assert.NotEmpty(t, client.environment)
17
		assert.NotEmpty(t, client.common)
18
19
		assert.Empty(t, client.username)
20
		assert.Empty(t, client.apiKey)
21
22
		assert.NotNil(t, client.httpClient)
23
		assert.NotNil(t, client.Bills)
24
	})
25
26
	t.Run("single configuration value can be set using options", func(t *testing.T) {
27
		// Arrange
28
		env := TestEnvironment
29
30
		// Act
31
		client := New(WithEnvironment(env))
32
33
		// Assert
34
		assert.NotNil(t, client.environment)
35
		assert.Equal(t, env.String(), client.environment.String())
36
	})
37
38
	t.Run("multiple configuration values can be set using options", func(t *testing.T) {
39
		// Arrange
40
		env := TestEnvironment
41
		newHTTPClient := &http.Client{Timeout: 422}
42
43
		// Act
44
		client := New(WithEnvironment(env), WithHTTPClient(newHTTPClient))
45
46
		// Assert
47
		assert.NotEmpty(t, client.environment)
48
		assert.Equal(t, env.String(), client.environment.String())
49
50
		assert.NotNil(t, client.httpClient)
51
		assert.Equal(t, newHTTPClient.Timeout, client.httpClient.Timeout)
52
	})
53
54
	t.Run("it sets the Bills service correctly", func(t *testing.T) {
55
		// Arrange
56
		client := New()
57
58
		// Assert
59
		assert.NotNil(t, client.Bills)
60
		assert.Equal(t, client.environment.String(), client.Bills.client.environment.String())
61
	})
62
}
63