out * 1 hour
This commit is contained in:
@@ -13,8 +13,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestBooking_GetDurations(t *testing.T) {
|
func TestBooking_GetDurations(t *testing.T) {
|
||||||
start := time.Now().Add(-2 * time.Hour)
|
start := time.Now().Add(-10 * time.Minute)
|
||||||
end := start.Add(1 * time.Hour)
|
end := start.Add(5 * time.Minute)
|
||||||
realStart := start.Add(30 * time.Minute)
|
realStart := start.Add(30 * time.Minute)
|
||||||
realEnd := realStart.Add(90 * time.Minute)
|
realEnd := realStart.Add(90 * time.Minute)
|
||||||
|
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ func getAverageTimeInSecond(averageTimeInSecond float64, start time.Time, end *t
|
|||||||
fromAverageDuration := after.Sub(now).Seconds()
|
fromAverageDuration := after.Sub(now).Seconds()
|
||||||
var tEnd time.Time
|
var tEnd time.Time
|
||||||
if end == nil {
|
if end == nil {
|
||||||
tEnd = start.Add(1 * time.Hour)
|
tEnd = start.Add(5 * time.Minute)
|
||||||
} else {
|
} else {
|
||||||
tEnd = *end
|
tEnd = *end
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ func Test_getAverageTimeInSecond_WithoutEnd(t *testing.T) {
|
|||||||
|
|
||||||
func TestBookingEstimation(t *testing.T) {
|
func TestBookingEstimation(t *testing.T) {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
end := start.Add(2 * time.Hour)
|
end := start.Add(10 * time.Minute)
|
||||||
strategies := map[pricing.TimePricingStrategy]float64{
|
strategies := map[pricing.TimePricingStrategy]float64{
|
||||||
pricing.ONCE: 50,
|
pricing.ONCE: 50,
|
||||||
pricing.PER_HOUR: 10,
|
pricing.PER_HOUR: 10,
|
||||||
@@ -102,7 +102,7 @@ func TestPricingStrategy_Getters(t *testing.T) {
|
|||||||
|
|
||||||
func TestPricingStrategy_GetPriceHT(t *testing.T) {
|
func TestPricingStrategy_GetPriceHT(t *testing.T) {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
end := start.Add(1 * time.Hour)
|
end := start.Add(5 * time.Minute)
|
||||||
|
|
||||||
// SUBSCRIPTION case
|
// SUBSCRIPTION case
|
||||||
ps := pricing.PricingStrategy[DummyStrategy]{
|
ps := pricing.PricingStrategy[DummyStrategy]{
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ func (r *PricedComputeResource) GetPriceHT() (float64, error) {
|
|||||||
r.BookingConfiguration.UsageStart = &now
|
r.BookingConfiguration.UsageStart = &now
|
||||||
}
|
}
|
||||||
if r.BookingConfiguration.UsageEnd == nil {
|
if r.BookingConfiguration.UsageEnd == nil {
|
||||||
add := r.BookingConfiguration.UsageStart.Add(time.Duration(1 * time.Hour))
|
add := r.BookingConfiguration.UsageStart.Add(time.Duration(5 * time.Minute))
|
||||||
r.BookingConfiguration.UsageEnd = &add
|
r.BookingConfiguration.UsageEnd = &add
|
||||||
}
|
}
|
||||||
pricing := r.SelectedPricing
|
pricing := r.SelectedPricing
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ func (r *PricedDataResource) GetPriceHT() (float64, error) {
|
|||||||
r.BookingConfiguration.UsageStart = &now
|
r.BookingConfiguration.UsageStart = &now
|
||||||
}
|
}
|
||||||
if r.BookingConfiguration.UsageEnd == nil {
|
if r.BookingConfiguration.UsageEnd == nil {
|
||||||
add := r.BookingConfiguration.UsageStart.Add(time.Duration(1 * time.Hour))
|
add := r.BookingConfiguration.UsageStart.Add(time.Duration(5 * time.Minute))
|
||||||
r.BookingConfiguration.UsageEnd = &add
|
r.BookingConfiguration.UsageEnd = &add
|
||||||
}
|
}
|
||||||
pricing := r.SelectedPricing
|
pricing := r.SelectedPricing
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ func (r *PricedResource[T]) GetPriceHT() (float64, error) {
|
|||||||
r.BookingConfiguration.UsageStart = &now
|
r.BookingConfiguration.UsageStart = &now
|
||||||
}
|
}
|
||||||
if r.BookingConfiguration.UsageEnd == nil {
|
if r.BookingConfiguration.UsageEnd == nil {
|
||||||
add := r.BookingConfiguration.UsageStart.Add(time.Duration(1 * time.Hour))
|
add := r.BookingConfiguration.UsageStart.Add(time.Duration(5 * time.Minute))
|
||||||
r.BookingConfiguration.UsageEnd = &add
|
r.BookingConfiguration.UsageEnd = &add
|
||||||
}
|
}
|
||||||
if any(r.SelectedPricing) == nil {
|
if any(r.SelectedPricing) == nil {
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ func (a *PricedProcessingResource) GetExplicitDurationInS() float64 {
|
|||||||
if a.IsService {
|
if a.IsService {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
return (1 * time.Hour).Seconds()
|
return (5 * time.Minute).Seconds()
|
||||||
}
|
}
|
||||||
return a.BookingConfiguration.UsageEnd.Sub(*a.BookingConfiguration.UsageStart).Seconds()
|
return a.BookingConfiguration.UsageEnd.Sub(*a.BookingConfiguration.UsageStart).Seconds()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ func TestCanUpdate(t *testing.T) {
|
|||||||
|
|
||||||
func TestCanDelete(t *testing.T) {
|
func TestCanDelete(t *testing.T) {
|
||||||
now := time.Now().UTC()
|
now := time.Now().UTC()
|
||||||
past := now.Add(-1 * time.Hour)
|
past := now.Add(-5 * time.Minute)
|
||||||
future := now.Add(1 * time.Hour)
|
future := now.Add(5 * time.Minute)
|
||||||
|
|
||||||
t.Run("nil EndDate", func(t *testing.T) {
|
t.Run("nil EndDate", func(t *testing.T) {
|
||||||
r := &purchase_resource.PurchaseResource{}
|
r := &purchase_resource.PurchaseResource{}
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ func (r *PricedStorageResource) GetPriceHT() (float64, error) {
|
|||||||
r.BookingConfiguration.UsageStart = &now
|
r.BookingConfiguration.UsageStart = &now
|
||||||
}
|
}
|
||||||
if r.BookingConfiguration.UsageEnd == nil {
|
if r.BookingConfiguration.UsageEnd == nil {
|
||||||
add := r.BookingConfiguration.UsageStart.Add(time.Duration(1 * time.Hour))
|
add := r.BookingConfiguration.UsageStart.Add(time.Duration(5 * time.Minute))
|
||||||
r.BookingConfiguration.UsageEnd = &add
|
r.BookingConfiguration.UsageEnd = &add
|
||||||
}
|
}
|
||||||
pricing := r.SelectedPricing
|
pricing := r.SelectedPricing
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ func TestComputeResource_ConvertToPricedResource(t *testing.T) {
|
|||||||
|
|
||||||
func TestComputeResourcePricingProfile_GetPriceHT_CPUs(t *testing.T) {
|
func TestComputeResourcePricingProfile_GetPriceHT_CPUs(t *testing.T) {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
end := start.Add(1 * time.Hour)
|
end := start.Add(5 * time.Minute)
|
||||||
profile := resources.ComputeResourcePricingProfile{
|
profile := resources.ComputeResourcePricingProfile{
|
||||||
CPUsPrices: map[string]float64{"Xeon": 2.0},
|
CPUsPrices: map[string]float64{"Xeon": 2.0},
|
||||||
ExploitPricingProfile: pricing.ExploitPricingProfile[pricing.TimePricingStrategy]{
|
ExploitPricingProfile: pricing.ExploitPricingProfile[pricing.TimePricingStrategy]{
|
||||||
@@ -61,7 +61,7 @@ func TestComputeResourcePricingProfile_GetPriceHT_InvalidParams(t *testing.T) {
|
|||||||
|
|
||||||
func TestPricedComputeResource_GetPriceHT(t *testing.T) {
|
func TestPricedComputeResource_GetPriceHT(t *testing.T) {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
end := start.Add(1 * time.Hour)
|
end := start.Add(5 * time.Minute)
|
||||||
r := resources.PricedComputeResource{
|
r := resources.PricedComputeResource{
|
||||||
PricedResource: resources.PricedResource[*resources.ComputeResourcePricingProfile]{
|
PricedResource: resources.PricedResource[*resources.ComputeResourcePricingProfile]{
|
||||||
ResourceID: "comp456",
|
ResourceID: "comp456",
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ func TestDataResourcePricingProfile_IsPurchased(t *testing.T) {
|
|||||||
|
|
||||||
func TestPricedDataResource_GetPriceHT(t *testing.T) {
|
func TestPricedDataResource_GetPriceHT(t *testing.T) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
later := now.Add(1 * time.Hour)
|
later := now.Add(5 * time.Minute)
|
||||||
mockPrice := 42.0
|
mockPrice := 42.0
|
||||||
|
|
||||||
pricingProfile := &resources.DataResourcePricingProfile{AccessPricingProfile: pricing.AccessPricingProfile[resources.DataResourcePricingStrategy]{
|
pricingProfile := &resources.DataResourcePricingProfile{AccessPricingProfile: pricing.AccessPricingProfile[resources.DataResourcePricingStrategy]{
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ func TestGetAndSetLocationStartEnd(t *testing.T) {
|
|||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
r.SetLocationStart(now)
|
r.SetLocationStart(now)
|
||||||
r.SetLocationEnd(now.Add(2 * time.Hour))
|
r.SetLocationEnd(now.Add(10 * time.Minute))
|
||||||
|
|
||||||
assert.Equal(t, now, *r.GetLocationStart())
|
assert.Equal(t, now, *r.GetLocationStart())
|
||||||
assert.Equal(t, now.Add(2*time.Hour), *r.GetLocationEnd())
|
assert.Equal(t, now.Add(2*time.Hour), *r.GetLocationEnd())
|
||||||
@@ -81,7 +81,7 @@ func TestGetExplicitDurationInS(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("computes duration from start and end", func(t *testing.T) {
|
t.Run("computes duration from start and end", func(t *testing.T) {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
end := start.Add(2 * time.Hour)
|
end := start.Add(10 * time.Minute)
|
||||||
r := &resources.PricedResource[pricing.PricingProfileITF]{
|
r := &resources.PricedResource[pricing.PricingProfileITF]{
|
||||||
BookingConfiguration: &resources.BookingConfiguration{
|
BookingConfiguration: &resources.BookingConfiguration{
|
||||||
UsageStart: &start, UsageEnd: &end,
|
UsageStart: &start, UsageEnd: &end,
|
||||||
@@ -117,7 +117,7 @@ func TestGetPriceHT(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("returns error if profile GetPriceHT fails", func(t *testing.T) {
|
t.Run("returns error if profile GetPriceHT fails", func(t *testing.T) {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
end := start.Add(1 * time.Hour)
|
end := start.Add(5 * time.Minute)
|
||||||
mock := &MockPricingProfile{ReturnErr: true}
|
mock := &MockPricingProfile{ReturnErr: true}
|
||||||
r := &resources.PricedResource[pricing.PricingProfileITF]{
|
r := &resources.PricedResource[pricing.PricingProfileITF]{
|
||||||
SelectedPricing: mock,
|
SelectedPricing: mock,
|
||||||
@@ -133,7 +133,7 @@ func TestGetPriceHT(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("uses SelectedPricing if set", func(t *testing.T) {
|
t.Run("uses SelectedPricing if set", func(t *testing.T) {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
end := start.Add(1 * time.Hour)
|
end := start.Add(5 * time.Minute)
|
||||||
mock := &MockPricingProfile{ReturnCost: 10.0}
|
mock := &MockPricingProfile{ReturnCost: 10.0}
|
||||||
r := &resources.PricedResource[pricing.PricingProfileITF]{
|
r := &resources.PricedResource[pricing.PricingProfileITF]{
|
||||||
SelectedPricing: mock,
|
SelectedPricing: mock,
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func TestPricedProcessingResource_GetType(t *testing.T) {
|
|||||||
|
|
||||||
func TestPricedProcessingResource_GetExplicitDurationInS(t *testing.T) {
|
func TestPricedProcessingResource_GetExplicitDurationInS(t *testing.T) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
after := now.Add(2 * time.Hour)
|
after := now.Add(10 * time.Minute)
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@@ -46,7 +46,7 @@ func TestPricedProcessingResource_GetExplicitDurationInS(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: float64((1 * time.Hour).Seconds()),
|
expected: float64((5 * time.Minute).Seconds()),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Duration computed from start and end",
|
name: "Duration computed from start and end",
|
||||||
@@ -58,7 +58,7 @@ func TestPricedProcessingResource_GetExplicitDurationInS(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: float64((2 * time.Hour).Seconds()),
|
expected: float64((10 * time.Minute).Seconds()),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Explicit duration takes precedence",
|
name: "Explicit duration takes precedence",
|
||||||
@@ -89,7 +89,7 @@ func TestProcessingResource_GetAccessor(t *testing.T) {
|
|||||||
|
|
||||||
func TestProcessingResourcePricingProfile_GetPriceHT(t *testing.T) {
|
func TestProcessingResourcePricingProfile_GetPriceHT(t *testing.T) {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
end := start.Add(2 * time.Hour)
|
end := start.Add(10 * time.Minute)
|
||||||
mockPricing := pricing.AccessPricingProfile[pricing.TimePricingStrategy]{
|
mockPricing := pricing.AccessPricingProfile[pricing.TimePricingStrategy]{
|
||||||
Pricing: pricing.PricingStrategy[pricing.TimePricingStrategy]{
|
Pricing: pricing.PricingStrategy[pricing.TimePricingStrategy]{
|
||||||
Price: 100.0,
|
Price: 100.0,
|
||||||
|
|||||||
Reference in New Issue
Block a user