-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpssd_test.go
109 lines (102 loc) · 3.23 KB
/
pssd_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package azrp
import (
"fmt"
"reflect"
"testing"
)
func pssdGoodGetter(url string) (ApiResponse, error) {
ar := ApiResponse{}
ar.BillingCurrency = "GBP"
ar.CustomerEntityID = "Default"
ar.CustomerEntityType = "Retail"
ar.Count = 1
ar.NextPageLink = ""
itm := Item{}
itm.CurrencyCode = "GBP"
itm.TierMinimumUnits = 0
itm.RetailPrice = 18.563811
itm.UnitPrice = 18.563811
itm.ArmRegionName = "uksouth"
itm.Location = "UK South"
itm.EffectiveStartDate = "2018-05-01T00:00:00Z"
itm.MeterID = "1e0cf0cf-919e-4cfe-a2a0-63e312f80718"
itm.MeterName = "P10 LRS Disk"
itm.ProductID = "DZH318Z0BP04"
itm.SkuID = "DZH318Z0BP04/007N"
itm.ProductName = "Premium SSD Managed Disks"
itm.SkuName = "P10 LRS"
itm.ServiceName = "Storage"
itm.ServiceID = "DZH317F1HKN0"
itm.ServiceFamily = "Storage"
itm.UnitOfMeasure = "1/Month"
itm.Type = "Consumption"
itm.IsPrimaryMeterRegion = true
itm.ArmSkuName = "Premium_SSD_Managed_Disk_P10"
ar.Items = append(ar.Items, itm)
return ar, nil
}
func pssdApiError(url string) (ApiResponse, error) {
return ApiResponse{}, fmt.Errorf("sorry, it didn't work out")
}
func pssdNoItems(url string) (ApiResponse, error) {
ar := ApiResponse{}
ar.BillingCurrency = "GBP"
ar.CustomerEntityID = "Default"
ar.CustomerEntityType = "Retail"
ar.Count = 0
ar.NextPageLink = ""
return ar, nil
}
func pssdTwoItems(url string) (ApiResponse, error) {
ar := ApiResponse{}
ar.BillingCurrency = "GBP"
ar.CustomerEntityID = "Default"
ar.CustomerEntityType = "Retail"
ar.Count = 1
ar.NextPageLink = ""
itm := Item{}
ar.Items = append(ar.Items, itm)
ar.Items = append(ar.Items, itm)
return ar, nil
}
//{"BillingCurrency":"GBP","CustomerEntityId":"Default","CustomerEntityType":"Retail","Items"
//,"skuName":"P10 LRS","serviceName":"Storage","serviceId":"DZH317F1HKN0","serviceFamily":"Storage","unitOfMeasure":"1/Month","type":"Consumption","isPrimaryMeterRegion":true,"armSkuName":"Premium_SSD_Managed_Disk_P10"}],"NextPageLink":null,"Count":1}
func TestPricer_GetPssdPrice(t *testing.T) {
type fields struct {
apg apiGetter
}
type args struct {
name string
region string
currency string
}
tests := []struct {
name string
fields fields
args args
want PssdPrice
wantErr bool
}{
{"Good", fields{pssdGoodGetter}, args{"P10", "uksouth", "GBP"}, PssdPrice{"P10", 128, "uksouth", "GBP", 18.563811}, false},
{"WrongPdiskName", fields{apiGet}, args{"P11", "germanywestcentral", "EUR"}, PssdPrice{}, true},
{"WrongRegionName", fields{apiGet}, args{"P10", "lapland", "EUR"}, PssdPrice{}, true},
{"ApiError", fields{pssdApiError}, args{"P10", "uksouth", "GBP"}, PssdPrice{}, true},
{"NoItemsReturned", fields{pssdNoItems}, args{"P10", "uksouth", "GBP"}, PssdPrice{}, true},
{"TooManyItemsReturned", fields{pssdTwoItems}, args{"P10", "uksouth", "GBP"}, PssdPrice{}, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := Pricer{
apg: tt.fields.apg,
}
got, err := p.GetPssdPrice(tt.args.name, tt.args.region, tt.args.currency)
if (err != nil) != tt.wantErr {
t.Errorf("Pricer.GetPssdPrice() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Pricer.GetPssdPrice() = %v, want %v", got, tt.want)
}
})
}
}