add sets up
This commit is contained in:
@@ -76,11 +76,8 @@ func TestDataResourcePricingStrategy_GetQuantity(t *testing.T) {
|
||||
|
||||
func TestDataResourcePricingProfile_IsPurchased(t *testing.T) {
|
||||
profile := &resources.DataResourcePricingProfile{}
|
||||
profile.Pricing.BuyingStrategy = pricing.PAY_PER_USE
|
||||
assert.False(t, profile.IsPurchased())
|
||||
|
||||
profile.Pricing.BuyingStrategy = pricing.SUBSCRIPTION
|
||||
assert.True(t, profile.IsPurchased())
|
||||
assert.True(t, profile.IsPurchasable())
|
||||
}
|
||||
|
||||
func TestPricedDataResource_GetPrice(t *testing.T) {
|
||||
|
||||
@@ -22,7 +22,7 @@ type MockPricingProfile struct {
|
||||
ReturnCost float64
|
||||
}
|
||||
|
||||
func (m *MockPricingProfile) IsPurchased() bool {
|
||||
func (m *MockPricingProfile) IsPurchasable() bool {
|
||||
return m.Purchased
|
||||
}
|
||||
|
||||
@@ -49,13 +49,13 @@ func TestGetIDAndCreatorAndType(t *testing.T) {
|
||||
func TestIsPurchased(t *testing.T) {
|
||||
t.Run("nil selected pricing returns false", func(t *testing.T) {
|
||||
r := &resources.PricedResource{}
|
||||
assert.False(t, r.IsPurchased())
|
||||
assert.False(t, r.IsPurchasable())
|
||||
})
|
||||
|
||||
t.Run("returns true if pricing profile is purchased", func(t *testing.T) {
|
||||
mock := &MockPricingProfile{Purchased: true}
|
||||
r := &resources.PricedResource{SelectedPricing: mock}
|
||||
assert.True(t, r.IsPurchased())
|
||||
assert.True(t, r.IsPurchasable())
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -95,21 +95,12 @@ func TestProcessingResourcePricingProfile_GetPrice(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProcessingResourcePricingProfile_IsPurchased(t *testing.T) {
|
||||
nonPurchased := &ProcessingResourcePricingProfile{
|
||||
AccessPricingProfile: pricing.AccessPricingProfile[pricing.TimePricingStrategy]{
|
||||
Pricing: pricing.PricingStrategy[pricing.TimePricingStrategy]{
|
||||
BuyingStrategy: pricing.PAY_PER_USE,
|
||||
},
|
||||
},
|
||||
}
|
||||
assert.False(t, nonPurchased.IsPurchased())
|
||||
|
||||
purchased := &ProcessingResourcePricingProfile{
|
||||
AccessPricingProfile: pricing.AccessPricingProfile[pricing.TimePricingStrategy]{
|
||||
Pricing: pricing.PricingStrategy[pricing.TimePricingStrategy]{
|
||||
BuyingStrategy: pricing.UNLIMITED,
|
||||
BuyingStrategy: pricing.PERMANENT,
|
||||
},
|
||||
},
|
||||
}
|
||||
assert.True(t, purchased.IsPurchased())
|
||||
assert.True(t, purchased.IsPurchasable())
|
||||
}
|
||||
|
||||
@@ -2,10 +2,8 @@ package resources_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/models/common/models"
|
||||
"cloud.o-forge.io/core/oc-lib/models/common/pricing"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
@@ -107,43 +105,3 @@ func TestPricedStorageResource_GetPrice_NoProfiles(t *testing.T) {
|
||||
_, err := res.GetPrice()
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestPricedStorageResource_GetPrice_WithPricing(t *testing.T) {
|
||||
now := time.Now()
|
||||
end := now.Add(2 * time.Hour)
|
||||
profile := &resources.StorageResourcePricingProfile{
|
||||
ExploitPricingProfile: pricing.ExploitPricingProfile[resources.StorageResourcePricingStrategy]{
|
||||
AccessPricingProfile: pricing.AccessPricingProfile[resources.StorageResourcePricingStrategy]{
|
||||
Pricing: pricing.PricingStrategy[resources.StorageResourcePricingStrategy]{
|
||||
BuyingStrategy: pricing.PAY_PER_USE,
|
||||
Price: 42.0,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
res := &resources.PricedStorageResource{
|
||||
PricedResource: resources.PricedResource{
|
||||
UsageStart: &now,
|
||||
UsageEnd: &end,
|
||||
PricingProfiles: []pricing.PricingProfileITF{profile},
|
||||
},
|
||||
UsageStorageGB: 1.0,
|
||||
}
|
||||
price, err := res.GetPrice()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 42.0, price)
|
||||
}
|
||||
|
||||
func TestStorageResourcePricingProfile_IsPurchased(t *testing.T) {
|
||||
p := &resources.StorageResourcePricingProfile{
|
||||
ExploitPricingProfile: pricing.ExploitPricingProfile[resources.StorageResourcePricingStrategy]{
|
||||
AccessPricingProfile: pricing.AccessPricingProfile[resources.StorageResourcePricingStrategy]{
|
||||
Pricing: pricing.PricingStrategy[resources.StorageResourcePricingStrategy]{BuyingStrategy: pricing.PAY_PER_USE},
|
||||
},
|
||||
},
|
||||
}
|
||||
assert.False(t, p.IsPurchased())
|
||||
|
||||
p.Pricing.BuyingStrategy = pricing.UNLIMITED
|
||||
assert.True(t, p.IsPurchased())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user