forked from hobbyfarm/gargantua
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9cafa53
commit f45c766
Showing
52 changed files
with
4,742 additions
and
3,048 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,5 @@ use ( | |
./v3/services/scenariosvc | ||
./v3/services/coursesvc | ||
./v3/services/terraformsvc | ||
./v3/services/costsvc | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package v1 | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestCostResource_Duration(t *testing.T) { | ||
defaultDeletion := time.Unix(10, 0) | ||
|
||
tests := []struct { | ||
name string | ||
input CostResource | ||
want time.Duration | ||
}{ | ||
{ | ||
name: "deletion", | ||
input: CostResource{ | ||
CreationUnixTimestamp: 0, | ||
DeletionUnixTimestamp: 10, | ||
}, | ||
want: 10 * time.Second, | ||
}, | ||
{ | ||
name: "no deletion", | ||
input: CostResource{ | ||
CreationUnixTimestamp: 0, | ||
}, | ||
want: 10 * time.Second, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := tt.input.Duration(defaultDeletion); got != tt.want { | ||
t.Errorf("Duration() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestCostResource_CalcCost(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
input CostResource | ||
duration time.Duration | ||
want uint64 | ||
}{ | ||
{ | ||
name: "seconds", | ||
input: CostResource{ | ||
BasePrice: 1, | ||
TimeUnit: TimeUnitSeconds, | ||
}, | ||
duration: 10 * time.Second, | ||
want: 10, | ||
}, | ||
{ | ||
name: "minutes", | ||
input: CostResource{ | ||
BasePrice: 2, | ||
TimeUnit: TimeUnitMinutes, | ||
}, | ||
duration: 60 * time.Second, | ||
want: 2, | ||
}, | ||
{ | ||
name: "minutes and always round up", | ||
input: CostResource{ | ||
BasePrice: 2, | ||
TimeUnit: TimeUnitMinutes, | ||
}, | ||
duration: 61 * time.Second, | ||
want: 4, | ||
}, | ||
{ | ||
name: "hours", | ||
input: CostResource{ | ||
BasePrice: 2, | ||
TimeUnit: TimeUnitHours, | ||
}, | ||
duration: 1 * time.Hour, | ||
want: 2, | ||
}, | ||
{ | ||
name: "hours and always round up", | ||
input: CostResource{ | ||
BasePrice: 2, | ||
TimeUnit: TimeUnitHours, | ||
}, | ||
duration: 61 * time.Minute, | ||
want: 4, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := tt.input.CalcCost(tt.duration); got != tt.want { | ||
t.Errorf("CalcCost() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.