Skip to content

Commit

Permalink
update test case
Browse files Browse the repository at this point in the history
  • Loading branch information
liafizan committed Feb 22, 2024
1 parent 0071e04 commit 0dc8e4e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
3 changes: 2 additions & 1 deletion pkg/providers/pricing/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ package pricing

import (
"context"
"github.com/aws/karpenter-provider-aws/pkg/operator/options"
"time"

"github.com/aws/karpenter-provider-aws/pkg/operator/options"

lop "github.com/samber/lo/parallel"
"go.uber.org/multierr"
"sigs.k8s.io/controller-runtime/pkg/manager"
Expand Down
25 changes: 6 additions & 19 deletions pkg/providers/pricing/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,23 +263,6 @@ var _ = Describe("Pricing", func() {
To(ContainElements("Linux/UNIX", "Linux/UNIX (Amazon VPC)"))
})
It("should return static on-demand data when in isolated-vpc", func() {
ctx = options.ToContext(ctx, test.Options(test.OptionsFields{
IsolatedVPC: lo.ToPtr(true),
}))
awsEnv.PricingAPI.GetProductsOutput.Set(&awspricing.GetProductsOutput{
PriceList: []aws.JSONValue{
fake.NewOnDemandPrice("c98.large", 1.20),
fake.NewOnDemandPrice("c99.large", 1.23),
},
})
// this should fail as we are not providing spot pricing info which will be
// called even when isolated-vpc is set
ExpectReconcileFailed(ctx, controller, types.NamespacedName{})
price, ok := awsEnv.PricingProvider.OnDemandPrice("c5.large")
Expect(ok).To(BeTrue())
Expect(price).To(BeNumerically(">", 0))
})
It("should return spot pricing data when in isolated-vpc", func() {
ctx = options.ToContext(ctx, test.Options(test.OptionsFields{
IsolatedVPC: lo.ToPtr(true),
}))
Expand All @@ -300,15 +283,19 @@ var _ = Describe("Pricing", func() {
},
},
})

awsEnv.PricingAPI.GetProductsOutput.Set(&awspricing.GetProductsOutput{
PriceList: []aws.JSONValue{
fake.NewOnDemandPrice("c98.large", 1.20),
fake.NewOnDemandPrice("c99.large", 1.23),
},
})

ExpectReconcileSucceeded(ctx, controller, types.NamespacedName{})
price, ok := awsEnv.PricingProvider.OnDemandPrice("c5.large")
Expect(ok).To(BeTrue())
Expect(price).To(BeNumerically(">", 0))

price, ok := awsEnv.PricingProvider.SpotPrice("c98.large", "test-zone-1b")
price, ok = awsEnv.PricingProvider.SpotPrice("c98.large", "test-zone-1b")
Expect(ok).To(BeTrue())
Expect(price).To(BeNumerically("==", 1.10))
Expect(getPricingEstimateMetricValue("c98.large", ec2.UsageClassTypeSpot, "test-zone-1b")).To(BeNumerically("==", 1.10))
Expand Down

0 comments on commit 0dc8e4e

Please sign in to comment.