Skip to content

Commit

Permalink
feat: update Value struct to support different value types
Browse files Browse the repository at this point in the history
  • Loading branch information
Gezi-lzq committed Oct 21, 2024
1 parent 89e1ef6 commit 6990444
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
8 changes: 4 additions & 4 deletions client/model_kafka_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ type PaymentPlan struct {
}

type Value struct {
Key string `json:"key"`
Name string `json:"name"`
Value int `json:"value"`
DisplayValue string `json:"displayValue"`
Key string `json:"key"`
Name string `json:"name"`
Value interface{} `json:"value"`
DisplayValue string `json:"displayValue"`
}

type Network struct {
Expand Down
4 changes: 3 additions & 1 deletion internal/models/kafka_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ func flattenComputeSpecs(spec client.Spec) *ComputeSpecsModel {
var aku types.Int64
for _, value := range spec.Values {
if value.Key == "aku" {
aku = types.Int64Value(int64(value.Value))
if v, ok := value.Value.(int); ok {
aku = types.Int64Value(int64(v))
}
break
}
}
Expand Down
1 change: 1 addition & 0 deletions internal/models/kafka_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func TestFlattenComputeSpecs(t *testing.T) {
Version: "1.0.0",
Values: []client.Value{
{Key: "aku", Value: 4},
{Key: "other", Value: "value"},
},
},
expected: ComputeSpecsModel{
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resource_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func newInstanceResponse() client.KafkaInstanceResponse {
instanceResponse.Spec.PaymentPlan.PaymentType = "ON_DEMAND"
instanceResponse.Spec.PaymentPlan.Period = 1
instanceResponse.Spec.PaymentPlan.Unit = "MONTH"
instanceResponse.Spec.Values = []client.Value{{Key: "aku", Value: 6}}
instanceResponse.Spec.Values = []client.Value{{Key: "aku", Value: 6}, {Key: "walMode", Value: "block"}}
instanceResponse.Networks = []client.Network{{Zone: "ap-southeast-1a", Subnets: []client.Subnet{{Subnet: "vsw-bp14v5eikr8wrgoqje7hr"}}}}
return instanceResponse
}
Expand Down

0 comments on commit 6990444

Please sign in to comment.