add sets up

This commit is contained in:
mr
2025-06-20 07:51:32 +02:00
parent 938f9f1326
commit d8ccdec501
23 changed files with 277 additions and 92 deletions

View File

@@ -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())
}