202 lines
7 KiB
Text
202 lines
7 KiB
Text
#!/usr/bin/env nu
|
|
|
|
# Integration tests for AWS pricing and cost estimation
|
|
|
|
def test-result [
|
|
name: string
|
|
result: bool
|
|
] {
|
|
if $result {
|
|
print $"✓ ($name)"
|
|
} else {
|
|
print $"✗ ($name)"
|
|
}
|
|
$result
|
|
}
|
|
|
|
def load-mock-responses [] {
|
|
open ($env.PROVISIONING)/extensions/providers/aws/tests/mocks/mock_api_responses.json
|
|
}
|
|
|
|
# Test: Pricing data structure
|
|
def test-pricing-data-structure [] {
|
|
let mocks = (load-mock-responses)
|
|
let pricing = ($mocks.pricing_data | get -o 0)
|
|
|
|
let test1 = (test-result "Pricing: Entry has InstanceType" ($pricing | get -o InstanceType | is-not-empty))
|
|
let test2 = (test-result "Pricing: Entry has Pricing section" ($pricing | get -o Pricing | is-not-empty))
|
|
let test3 = (test-result "Pricing: Entry has VCpu" ($pricing | get -o VCpu | is-not-empty))
|
|
let test4 = (test-result "Pricing: Entry has Memory" ($pricing | get -o Memory | is-not-empty))
|
|
|
|
$test1 and $test2 and $test3 and $test4
|
|
}
|
|
|
|
# Test: On-demand pricing extraction
|
|
def test-on-demand-pricing [] {
|
|
let mocks = (load-mock-responses)
|
|
let pricing = ($mocks.pricing_data | get -o 0)
|
|
|
|
let test1 = (test-result "Pricing: On-demand rate present" ($pricing | get -o Pricing | get -o OnDemand | is-not-empty))
|
|
let test2 = (test-result "Pricing: On-demand rate is positive" (($pricing.Pricing | get -o OnDemand) > 0))
|
|
|
|
$test1 and $test2
|
|
}
|
|
|
|
# Test: Reserved instance pricing
|
|
def test-reserved-pricing [] {
|
|
let mocks = (load-mock-responses)
|
|
let pricing = ($mocks.pricing_data | get -o 0)
|
|
|
|
let test1 = (test-result "Pricing: Reserved rate present" ($pricing | get -o Pricing | get -o Reserved | is-not-empty))
|
|
let test2 = (test-result "Pricing: Reserved rate is less than on-demand" (($pricing.Pricing | get -o Reserved) < ($pricing.Pricing | get -o OnDemand)))
|
|
|
|
$test1 and $test2
|
|
}
|
|
|
|
# Test: Instance type filtering
|
|
def test-instance-type-filtering [] {
|
|
let mocks = (load-mock-responses)
|
|
let all_types = ($mocks.pricing_data | get -o InstanceType)
|
|
|
|
let t3_micro = ($mocks.pricing_data | where {|p| $p.InstanceType == "t3.micro"})
|
|
let t3_small = ($mocks.pricing_data | where {|p| $p.InstanceType == "t3.small"})
|
|
|
|
let test1 = (test-result "Pricing: t3.micro pricing found" (($t3_micro | length) > 0))
|
|
let test2 = (test-result "Pricing: t3.small pricing found" (($t3_small | length) > 0))
|
|
|
|
$test1 and $test2
|
|
}
|
|
|
|
# Test: Pricing scaling (smaller instance cheaper)
|
|
def test-pricing-scaling [] {
|
|
let mocks = (load-mock-responses)
|
|
let micro = ($mocks.pricing_data | where {|p| $p.InstanceType == "t3.micro"} | get -o 0)
|
|
let small = ($mocks.pricing_data | where {|p| $p.InstanceType == "t3.small"} | get -o 0)
|
|
|
|
let micro_price = ($micro.Pricing | get -o OnDemand)
|
|
let small_price = ($small.Pricing | get -o OnDemand)
|
|
|
|
test-result "Pricing: t3.small more expensive than t3.micro" ($small_price > $micro_price)
|
|
}
|
|
|
|
# Test: vCPU correlation with price
|
|
def test-vcpu-price-correlation [] {
|
|
let mocks = (load-mock-responses)
|
|
let micro = ($mocks.pricing_data | where {|p| $p.InstanceType == "t3.micro"} | get -o 0)
|
|
let medium = ($mocks.pricing_data | where {|p| $p.InstanceType == "t3.medium"} | get -o 0)
|
|
|
|
let test1 = (test-result "Pricing: t3.micro has 1 vCPU" (($micro | get -o VCpu) == 1))
|
|
let test2 = (test-result "Pricing: t3.medium has 2 vCPU" (($medium | get -o VCpu) == 2))
|
|
|
|
$test1 and $test2
|
|
}
|
|
|
|
# Test: Memory specification format
|
|
def test-memory-format [] {
|
|
let mocks = (load-mock-responses)
|
|
let pricing = ($mocks.pricing_data | get -o 0)
|
|
let memory = ($pricing | get -o Memory)
|
|
|
|
let test1 = (test-result "Pricing: Memory has value" ($memory | is-not-empty))
|
|
let test2 = (test-result "Pricing: Memory has GB unit" ($memory | str contains "GB"))
|
|
|
|
$test1 and $test2
|
|
}
|
|
|
|
# Test: Monthly cost estimation
|
|
def test-cost-estimation [] {
|
|
let mocks = (load-mock-responses)
|
|
let micro = ($mocks.pricing_data | where {|p| $p.InstanceType == "t3.micro"} | get -o 0)
|
|
|
|
let hourly_rate = ($micro.Pricing | get -o OnDemand)
|
|
let monthly_estimate = ($hourly_rate * 730)
|
|
|
|
test-result "Pricing: Monthly estimate calculated" ($monthly_estimate > 0)
|
|
}
|
|
|
|
# Test: All pricing entries have required fields
|
|
def test-pricing-completeness [] {
|
|
let mocks = (load-mock-responses)
|
|
let all_entries = $mocks.pricing_data
|
|
|
|
let complete_entries = ($all_entries | where {|p|
|
|
($p | get -o InstanceType | is-not-empty) and
|
|
($p | get -o Pricing | is-not-empty) and
|
|
($p | get -o VCpu | is-not-empty) and
|
|
($p | get -o Memory | is-not-empty)
|
|
})
|
|
|
|
test-result "Pricing: All entries have required fields" (($complete_entries | length) == ($all_entries | length))
|
|
}
|
|
|
|
# Test: Volume pricing (if available in extended pricing)
|
|
def test-volume-pricing-structure [] {
|
|
let mocks = (load-mock-responses)
|
|
let volumes = ($mocks.describe_volumes_list.Volumes)
|
|
|
|
let test1 = (test-result "Pricing: Volumes have VolumeType" ($volumes | where {|v| ($v | get -o VolumeType | is-not-empty)} | length) > 0)
|
|
let test2 = (test-result "Pricing: Volumes have Size" ($volumes | where {|v| ($v | get -o Size | is-not-empty)} | length) > 0))
|
|
|
|
$test1 and $test2
|
|
}
|
|
|
|
# Test: gp3 volume specifications
|
|
def test-gp3-volume-specs [] {
|
|
let mocks = (load-mock-responses)
|
|
let gp3_volumes = ($mocks.describe_volumes_list.Volumes | where {|v| $v.VolumeType == "gp3"})
|
|
|
|
let test1 = (test-result "Pricing: gp3 volumes have IOPS" (($gp3_volumes | where {|v| ($v | get -o Iops | is-not-empty)} | length) > 0))
|
|
let test2 = (test-result "Pricing: gp3 volumes have Throughput" (($gp3_volumes | where {|v| ($v | get -o Throughput | is-not-empty)} | length) > 0))
|
|
|
|
$test1 and $test2
|
|
}
|
|
|
|
# Test: Volume cost estimation
|
|
def test-volume-cost-calculation [] {
|
|
let mocks = (load-mock-responses)
|
|
let volumes = ($mocks.describe_volumes_list.Volumes)
|
|
|
|
# Assume $0.10 per GB-month for gp2, $0.11 for gp3
|
|
let gp2_volumes = ($volumes | where {|v| $v.VolumeType == "gp2"})
|
|
let gp3_volumes = ($volumes | where {|v| $v.VolumeType == "gp3"})
|
|
|
|
let test1 = (test-result "Pricing: gp2 volume monthly cost calculated" (($gp2_volumes | get -o 0 | get -o Size) * 0.10 > 0))
|
|
let test2 = (test-result "Pricing: gp3 volume monthly cost calculated" (($gp3_volumes | get -o 0 | get -o Size) * 0.11 > 0))
|
|
|
|
$test1 and $test2
|
|
}
|
|
|
|
# Main test execution
|
|
def main [] {
|
|
print "=== AWS Pricing Integration Tests ==="
|
|
print ""
|
|
|
|
let results = [
|
|
(test-pricing-data-structure),
|
|
(test-on-demand-pricing),
|
|
(test-reserved-pricing),
|
|
(test-instance-type-filtering),
|
|
(test-pricing-scaling),
|
|
(test-vcpu-price-correlation),
|
|
(test-memory-format),
|
|
(test-cost-estimation),
|
|
(test-pricing-completeness),
|
|
(test-volume-pricing-structure),
|
|
(test-gp3-volume-specs),
|
|
(test-volume-cost-calculation)
|
|
]
|
|
|
|
let passed = ($results | where {|it| $it == true} | length)
|
|
let failed = ($results | where {|it| $it == false} | length)
|
|
|
|
print ""
|
|
print $"Test Results: ($passed) passed, ($failed) failed"
|
|
|
|
{
|
|
passed: $passed,
|
|
failed: $failed,
|
|
total: ($passed + $failed)
|
|
}
|
|
}
|
|
|
|
main
|