Skip to content

Commit

Permalink
feat: update Value struct to support different value types (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gezi-lzq authored Oct 21, 2024
1 parent 89e1ef6 commit 26440a4
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 22 deletions.
38 changes: 23 additions & 15 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Terraform Provider",
"type": "go",
"request": "launch",
"mode": "debug",
// this assumes your workspace is the root of the repo
"program": "${workspaceFolder}",
"env": {},
"args": [
"-debug",
]
}
]
"version": "0.2.0",
"configurations": [
{
"name": "Debug Selected Test",
"request": "launch",
"type": "go",
"args": ["-test.v", "-test.run", "^${selectedText}$"],
"mode": "auto",
"program": "${fileDirname}",
"env": { "PKG_NAME": "${relativeFileDirname}" , "TF_ACC": "1" },
"showLog": true
},
{
"name": "Debug Terraform Provider",
"type": "go",
"request": "launch",
"mode": "debug",
// this assumes your workspace is the root of the repo
"program": "${workspaceFolder}",
"env": {},
"args": ["-debug"]
}
]
}
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 intValue, ok := value.Value.(float64); ok {
aku = types.Int64Value(int64(intValue))
}
break
}
}
Expand Down
3 changes: 2 additions & 1 deletion internal/models/kafka_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ func TestFlattenComputeSpecs(t *testing.T) {
input: client.Spec{
Version: "1.0.0",
Values: []client.Value{
{Key: "aku", Value: 4},
{Key: "aku", Value: 4.0},
{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 26440a4

Please sign in to comment.