@@ -3,6 +3,7 @@ package pricing
33import (
44 "math/big"
55 "testing"
6+ "time"
67
78 . "github.com/smartystreets/goconvey/convey"
89)
@@ -37,28 +38,55 @@ func TestBasket_Add(t *testing.T) {
3738
3839func TestBasket_Total (t * testing.T ) {
3940 Convey ("Testing Basket.Total" , t , FailureContinues , func () {
40- basket := NewBasket ()
41- So (basket , ShouldNotBeNil )
42- current := ratZero
43- difference := ratZero
44- So (basket .Total (), ShouldEqualBigRat , current )
41+ Convey ("3 compute instances" , func () {
42+ basket := NewBasket ()
43+ So (basket , ShouldNotBeNil )
44+ current := ratZero
45+ difference := ratZero
46+ So (basket .Total (), ShouldEqualBigRat , current )
4547
46- err := basket .Add (NewUsageByPathWithQuantity ("/compute/c1/run" , 1 ))
47- So (err , ShouldBeNil )
48- difference = new (big.Rat ).Mul (big .NewRat (60 , 1 ), new (big.Rat ).SetFloat64 (0.012 ))
49- current = new (big.Rat ).Add (current , difference )
50- So (basket .Total (), ShouldEqualBigRat , current )
48+ err := basket .Add (NewUsageByPathWithQuantity ("/compute/c1/run" , 1 ))
49+ So (err , ShouldBeNil )
50+ difference = new (big.Rat ).Mul (big .NewRat (60 , 1 ), new (big.Rat ).SetFloat64 (0.012 ))
51+ current = new (big.Rat ).Add (current , difference )
52+ So (basket .Total (), ShouldEqualBigRat , current )
5153
52- err = basket .Add (NewUsageByPathWithQuantity ("/compute/c1/run" , 42 ))
53- So (err , ShouldBeNil )
54- difference = new (big.Rat ).Mul (big .NewRat (60 , 1 ), new (big.Rat ).SetFloat64 (0.012 ))
55- current = new (big.Rat ).Add (current , difference )
56- So (basket .Total (), ShouldEqualBigRat , current )
54+ err = basket .Add (NewUsageByPathWithQuantity ("/compute/c1/run" , 42 ))
55+ So (err , ShouldBeNil )
56+ difference = new (big.Rat ).Mul (big .NewRat (60 , 1 ), new (big.Rat ).SetFloat64 (0.012 ))
57+ //difference = big.NewRat(72, 100)
58+ current = new (big.Rat ).Add (current , difference )
59+ So (basket .Total (), ShouldEqualBigRat , current )
5760
58- err = basket .Add (NewUsageByPathWithQuantity ("/compute/c1/run" , 600 ))
59- So (err , ShouldBeNil )
60- difference = big .NewRat (6 , 1 )
61- current = new (big.Rat ).Add (current , difference )
62- So (basket .Total (), ShouldEqualBigRat , current )
61+ err = basket .Add (NewUsageByPathWithQuantity ("/compute/c1/run" , 600 ))
62+ So (err , ShouldBeNil )
63+ difference = big .NewRat (6 , 1 )
64+ current = new (big.Rat ).Add (current , difference )
65+ So (basket .Total (), ShouldEqualBigRat , current )
66+ })
67+ Convey ("1 compute instance with 2 volumes and 1 ip" , func () {
68+ basket := NewBasket ()
69+
70+ basket .Add (NewUsageByPath ("/compute/c1/run" ))
71+ basket .Add (NewUsageByPath ("/ip/dynamic" ))
72+ basket .Add (NewUsageByPath ("/storage/local/ssd/storage" ))
73+ basket .Add (NewUsageByPath ("/storage/local/ssd/storage" ))
74+ So (basket .Length (), ShouldEqual , 4 )
75+
76+ basket .SetDuration (1 * time .Minute )
77+ So (basket .Total (), ShouldEqualBigRat , new (big.Rat ).SetFloat64 (1.36 ))
78+
79+ basket .SetDuration (1 * time .Hour )
80+ So (basket .Total (), ShouldEqualBigRat , new (big.Rat ).SetFloat64 (1.36 ))
81+
82+ basket .SetDuration (2 * time .Hour )
83+ So (basket .Total (), ShouldEqualBigRat , new (big.Rat ).SetFloat64 (2.32 ))
84+
85+ basket .SetDuration (2 * 24 * time .Hour )
86+ So (basket .Total (), ShouldEqualBigRat , new (big.Rat ).SetFloat64 (8.39 ))
87+
88+ basket .SetDuration (30 * 24 * time .Hour )
89+ So (basket .Total (), ShouldEqualBigRat , new (big.Rat ).SetFloat64 (1.99 ))
90+ })
6391 })
6492}
0 commit comments