package resources_test import ( "testing" "cloud.o-forge.io/core/oc-lib/tools" "github.com/stretchr/testify/assert" "cloud.o-forge.io/core/oc-lib/models/resources" ) func TestStorageResource_GetType(t *testing.T) { res := &resources.StorageResource{} assert.Equal(t, tools.STORAGE_RESOURCE.String(), res.GetType()) } func TestStorageResource_GetAccessor(t *testing.T) { res := &resources.StorageResource{} req := &tools.APIRequest{} accessor := res.GetAccessor(req) assert.NotNil(t, accessor) } func TestStorageResource_ConvertToPricedResource_ValidType(t *testing.T) { res := &resources.StorageResource{} res.AbstractInstanciatedResource.CreatorID = "creator" res.AbstractInstanciatedResource.UUID = "res-id" priced, _ := res.ConvertToPricedResource(tools.STORAGE_RESOURCE, nil, nil, nil, nil, nil, &tools.APIRequest{}) assert.NotNil(t, priced) assert.IsType(t, &resources.PricedStorageResource{}, priced) } func TestStorageResource_ConvertToPricedResource_InvalidType(t *testing.T) { res := &resources.StorageResource{} priced, _ := res.ConvertToPricedResource(tools.COMPUTE_RESOURCE, nil, nil, nil, nil, nil, &tools.APIRequest{}) assert.Nil(t, priced) } func TestStorageResourcePricingStrategy_GetQuantity(t *testing.T) { tests := []struct { strategy resources.StorageResourcePricingStrategy dataGB float64 expect float64 }{ {resources.PER_DATA_STORED, 1.2, 1.2}, {resources.PER_TB_STORED, 1.2, 1200}, {resources.PER_GB_STORED, 2.5, 2.5}, {resources.PER_MB_STORED, 1.0, 1000}, {resources.PER_KB_STORED, 0.1, 100000}, } for _, tt := range tests { q, err := tt.strategy.GetQuantity(tt.dataGB) assert.NoError(t, err) assert.Equal(t, tt.expect, q) } } func TestStorageResourcePricingStrategy_GetQuantity_Invalid(t *testing.T) { invalid := resources.StorageResourcePricingStrategy(99) q, err := invalid.GetQuantity(1.0) assert.Error(t, err) assert.Equal(t, 0.0, q) } func TestPricedStorageResource_GetPriceHT_NoProfiles(t *testing.T) { res := &resources.PricedStorageResource{ PricedResource: resources.PricedResource[*resources.StorageResourcePricingProfile]{ ResourceID: "res-id", }, } _, err := res.GetPriceHT() assert.Error(t, err) }