@@ -19,25 +19,27 @@ package emlb
19
19
20
20
import (
21
21
"os"
22
- "reflect"
23
22
"testing"
24
23
24
+ . "github.com/onsi/gomega"
25
+
25
26
corev1 "k8s.io/api/core/v1"
26
27
)
27
28
28
29
func Test_getResourceName (t * testing.T ) {
30
+ g := NewWithT (t )
29
31
loadBalancerName := "my-loadbalancer"
30
32
resourceType := "pool"
31
33
want := "my-loadbalancer-pool"
32
34
33
35
got := getResourceName (loadBalancerName , resourceType )
34
36
35
- if got != want {
36
- t .Errorf ("getResourceName() = %v, want %v" , got , want )
37
- }
37
+ // assert name is correct
38
+ g .Expect (got ).To (Equal (want ))
38
39
}
39
40
40
41
func Test_checkDebugEnabled (t * testing.T ) {
42
+ g := NewWithT (t )
41
43
// Set the PACKNGO_DEBUG environment variable to enable debug mode
42
44
if err := os .Setenv ("PACKNGO_DEBUG" , "true" ); err != nil {
43
45
t .Errorf ("Error testing checkDebugEnabled: %v" , err )
@@ -47,9 +49,7 @@ func Test_checkDebugEnabled(t *testing.T) {
47
49
debugEnabled := checkDebugEnabled ()
48
50
49
51
// Check if debugEnabled is true
50
- if ! debugEnabled {
51
- t .Errorf ("checkDebugEnabled() = %v, want %v" , debugEnabled , true )
52
- }
52
+ g .Expect (debugEnabled ).To (BeTrue ())
53
53
54
54
// Unset the PACKNGO_DEBUG environment variable
55
55
os .Unsetenv ("PACKNGO_DEBUG" )
@@ -58,9 +58,7 @@ func Test_checkDebugEnabled(t *testing.T) {
58
58
debugEnabled = checkDebugEnabled ()
59
59
60
60
// Check if debugEnabled is false
61
- if debugEnabled {
62
- t .Errorf ("checkDebugEnabled() = %v, want %v" , debugEnabled , false )
63
- }
61
+ g .Expect (debugEnabled ).To (BeFalse ())
64
62
}
65
63
66
64
func Test_convertToTarget (t * testing.T ) {
@@ -114,9 +112,9 @@ func Test_convertToTarget(t *testing.T) {
114
112
}
115
113
for _ , tt := range tests {
116
114
t .Run (tt .name , func (t * testing.T ) {
117
- if got := convertToTarget ( tt . args . devaddr ); ! reflect . DeepEqual ( got , tt . want ) {
118
- t . Errorf ( "convertToTarget() = %v, want %v" , got , tt .want )
119
- }
115
+ g := NewWithT ( t )
116
+ got := convertToTarget ( tt .args . devaddr )
117
+ g . Expect ( got ). To ( Equal ( tt . want ))
120
118
})
121
119
}
122
120
}
@@ -167,34 +165,33 @@ func Test_getExternalIPv4Target(t *testing.T) {
167
165
}
168
166
for _ , tt := range tests {
169
167
t .Run (tt .name , func (t * testing.T ) {
168
+ g := NewWithT (t )
170
169
got , err := getExternalIPv4Target (tt .args .deviceAddr )
171
170
if (err != nil ) != tt .wantErr {
172
- t . Errorf ( "getExternalIPv4Target() error = %v, wantErr %v" , err , tt .wantErr )
171
+ g . Expect ( err ). To ( Equal ( tt .wantErr ) )
173
172
return
174
173
}
175
- if ! reflect .DeepEqual (got , tt .want ) {
176
- t .Errorf ("getExternalIPv4Target() = %v, want %v" , got , tt .want )
177
- }
174
+ g .Expect (got ).To (Equal (tt .want ))
178
175
})
179
176
}
180
177
}
181
178
func TestNewEMLB (t * testing.T ) {
179
+ g := NewWithT (t )
182
180
metalAPIKey := "metal-api-key" //nolint:gosec
183
181
projectID := "project-id"
184
182
metro := "am"
185
183
186
184
emlb := NewEMLB (metalAPIKey , projectID , metro )
187
185
188
- if emlb .client == nil {
189
- t .Error ("NewEMLB() client is nil" )
190
- }
191
- if emlb .tokenExchanger == nil {
192
- t .Error ("NewEMLB() tokenExchanger is nil" )
193
- }
194
- if emlb .projectID != projectID {
195
- t .Errorf ("NewEMLB() projectID = %s, want %s" , emlb .projectID , projectID )
196
- }
197
- if emlb .metro != metro {
198
- t .Errorf ("NewEMLB() metro = %s, want %s" , emlb .metro , metro )
199
- }
186
+ // assert client is not nil
187
+ g .Expect (emlb .client ).To (Not (BeNil ()))
188
+
189
+ // assert tokenExchanger is not nil
190
+ g .Expect (emlb .tokenExchanger ).To (Not (BeNil ()))
191
+
192
+ // assert project ID is correct
193
+ g .Expect (emlb .projectID ).To (Equal (projectID ))
194
+
195
+ // assert metro is correct
196
+ g .Expect (emlb .metro ).To (Equal (metro ))
200
197
}
0 commit comments