Skip to content

Commit 9c26cb6

Browse files
committed
feat: Improve unit test
1 parent c9f032f commit 9c26cb6

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

internal/pkg/services/iaas/utils/utils_test.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,22 @@ func TestGetPublicIp(t *testing.T) {
8282
getPublicIpResp *iaas.PublicIp
8383
}
8484
tests := []struct {
85-
name string
86-
args args
87-
want string
88-
wantErr bool
85+
name string
86+
args args
87+
wantPublicIp string
88+
wantAssociatedResource string
89+
wantErr bool
8990
}{
9091
{
9192
name: "base",
9293
args: args{
9394
getPublicIpResp: &iaas.PublicIp{
9495
Ip: utils.Ptr("1.2.3.4"),
95-
NetworkInterface: iaas.NewNullableString(utils.Ptr("1.2.3.4")),
96+
NetworkInterface: iaas.NewNullableString(utils.Ptr("5.6.7.8")),
9697
},
9798
},
98-
want: "1.2.3.4",
99+
wantPublicIp: "1.2.3.4",
100+
wantAssociatedResource: "5.6.7.8",
99101
},
100102
{
101103
name: "get public ip fails",
@@ -111,13 +113,16 @@ func TestGetPublicIp(t *testing.T) {
111113
GetPublicIpFails: tt.args.getPublicIpFails,
112114
GetPublicIpResp: tt.args.getPublicIpResp,
113115
}
114-
got, _, err := GetPublicIP(context.Background(), m, "", "")
116+
gotPublicIP, gotAssociatedResource, err := GetPublicIP(context.Background(), m, "", "")
115117
if (err != nil) != tt.wantErr {
116118
t.Errorf("GetPublicIP() error = %v, wantErr %v", err, tt.wantErr)
117119
return
118120
}
119-
if got != tt.want {
120-
t.Errorf("GetPublicIP() = %v, want %v", got, tt.want)
121+
if gotPublicIP != tt.wantPublicIp {
122+
t.Errorf("GetPublicIP() = %v, want public IP %v", gotPublicIP, tt.wantPublicIp)
123+
}
124+
if gotAssociatedResource != tt.wantAssociatedResource {
125+
t.Errorf("GetPublicIP() = %v, want associated resource %v", gotAssociatedResource, tt.wantAssociatedResource)
121126
}
122127
})
123128
}

0 commit comments

Comments
 (0)