feat: 扩展 AWS 实例运行期管理 SDK
test / go (push) Successful in 1m40s

This commit is contained in:
shiran
2026-08-27 16:47:02 +08:00
parent 3d4c2dbb20
commit 8392db9ae3
4 changed files with 55 additions and 8 deletions
+32
View File
@@ -106,3 +106,35 @@ func TestListQueryParametersAreNotEscapedIntoPath(t *testing.T) {
t.Fatal(err)
}
}
func TestRuntimePricingAndInstanceEIPOperations(t *testing.T) {
paths := []string{}
client, _ := testClient(t, func(w http.ResponseWriter, r *http.Request) {
paths = append(paths, r.Method+" "+r.URL.Path)
w.Header().Set("Content-Type", "application/json")
if r.URL.Path == "/api/sdk/v1/regions/us-east-1/instances/local-1/price-estimate" {
_, _ = w.Write([]byte(`{"code":200,"message":"Success","data":{"currency":"USD","monthly_price":12.5,"configuration_fingerprint":"fingerprint"}}`))
return
}
_, _ = w.Write([]byte(`{"code":202,"message":"Accepted","data":{"task_id":"task-1","status":"queued"}}`))
})
estimate, err := client.Pricing.EstimateExistingInstance(context.Background(), "us-east-1", "local-1")
if err != nil || estimate.ConfigurationFingerprint != "fingerprint" || estimate.MonthlyPrice != 12.5 {
t.Fatalf("estimate=%#v err=%v", estimate, err)
}
if _, err := client.EIPs.Disassociate(context.Background(), "us-east-1", "local-1", WithIdempotencyKey("disassociate")); err != nil {
t.Fatal(err)
}
if _, err := client.EIPs.Release(context.Background(), "us-east-1", "local-1", WithIdempotencyKey("release")); err != nil {
t.Fatal(err)
}
want := []string{"POST /api/sdk/v1/regions/us-east-1/instances/local-1/price-estimate", "POST /api/sdk/v1/regions/us-east-1/instances/local-1/eip/disassociate", "DELETE /api/sdk/v1/regions/us-east-1/instances/local-1/eip"}
if len(paths) != len(want) {
t.Fatalf("paths=%v", paths)
}
for i := range want {
if paths[i] != want[i] {
t.Fatalf("paths=%v want=%v", paths, want)
}
}
}