forked from migimigi/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
67 lines (57 loc) · 1.63 KB
/
main_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
package main
import (
"fmt"
"testing"
"github.com/itsubaki/hermes/pkg/hermes"
"github.com/itsubaki/hermes/pkg/pricing"
"github.com/itsubaki/hermes/pkg/usage"
)
func TestPackage(t *testing.T) {
price := []pricing.Price{
{
Region: "ap-northeast-1",
UsageType: "APN1-BoxUsage:c4.large",
Tenancy: "Shared",
PreInstalled: "NA",
OperatingSystem: "Linux",
OfferingClass: "standard",
LeaseContractLength: "1yr",
PurchaseOption: "All Upfront",
OnDemand: 0.126,
ReservedQuantity: 738,
ReservedHrs: 0,
NormalizationSizeFactor: "4",
},
}
plist, err := pricing.Deserialize("/var/tmp/hermes", []string{"ap-northeast-1"})
if err != nil {
fmt.Errorf("desirialize pricing: %v", err)
}
family := pricing.Family(plist)
mini := pricing.Minimum(family, plist)
date := usage.Last12Months()
forecast, err := usage.Deserialize("/var/tmp/hermes", date)
if err != nil {
t.Errorf("deserialize usage: %v", err)
}
normalized := hermes.Normalize(forecast, mini)
merged := usage.MergeOverall(normalized)
monthly := usage.Monthly(merged)
for _, p := range price {
for k := range monthly {
if len(monthly[k][0].Platform) > 0 {
if p.UsageType != monthly[k][0].UsageType || p.OperatingSystem != hermes.OperatingSystem[monthly[k][0].Platform] {
continue
}
}
if len(monthly[k][0].Platform) < 1 {
if fmt.Sprintf("%s%s%s", p.UsageType, p.CacheEngine, p.DatabaseEngine) != k {
continue
}
}
q, _ := hermes.BreakEvenPoint(monthly[k], p)
fmt.Println(q)
break
}
}
}