Skip to content

Commit a7da055

Browse files
committed
fix test
1 parent db2d0cb commit a7da055

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

docs/resources/metadata.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,19 @@ resource "coder_metadata" "pod_info" {
4343
item {
4444
key = "description"
4545
value = "This description will show up in the Coder dashboard."
46+
order = 1
4647
}
4748
item {
4849
key = "pod_uid"
4950
value = kubernetes_pod.dev[0].uid
51+
order = 2
5052
}
5153
item {
5254
key = "public_key"
5355
value = tls_private_key.example_key_pair.public_key_openssh
5456
# The value of this item will be hidden from view by default
5557
sensitive = true
58+
order = 3
5659
}
5760
}
5861
```

examples/resources/coder_metadata/resource.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,18 @@ resource "coder_metadata" "pod_info" {
2525
item {
2626
key = "description"
2727
value = "This description will show up in the Coder dashboard."
28+
order = 1
2829
}
2930
item {
3031
key = "pod_uid"
3132
value = kubernetes_pod.dev[0].uid
33+
order = 2
3234
}
3335
item {
3436
key = "public_key"
3537
value = tls_private_key.example_key_pair.public_key_openssh
3638
# The value of this item will be hidden from view by default
3739
sensitive = true
40+
order = 3
3841
}
3942
}

provider/metadata_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,26 @@ func TestMetadata(t *testing.T) {
3030
item {
3131
key = "foo"
3232
value = "bar"
33-
order = 4
3433
}
3534
item {
3635
key = "secret"
3736
value = "squirrel"
3837
sensitive = true
38+
order = 1
3939
}
4040
item {
4141
key = "implicit_null"
42+
order = 2
4243
}
4344
item {
4445
key = "explicit_null"
4546
value = null
47+
order = 3
4648
}
4749
item {
4850
key = "empty"
4951
value = ""
52+
order = 4
5053
}
5154
}
5255
`,
@@ -67,20 +70,24 @@ func TestMetadata(t *testing.T) {
6770
"item.0.key": "foo",
6871
"item.0.value": "bar",
6972
"item.0.sensitive": "false",
70-
"item.0.order": "4",
73+
"item.0.order": "0",
7174
"item.1.key": "secret",
7275
"item.1.value": "squirrel",
7376
"item.1.sensitive": "true",
77+
"item.1.order": "1",
7478
"item.2.key": "implicit_null",
7579
"item.2.is_null": "true",
7680
"item.2.sensitive": "false",
81+
"item.2.order": "2",
7782
"item.3.key": "explicit_null",
7883
"item.3.is_null": "true",
7984
"item.3.sensitive": "false",
85+
"item.3.order": "3",
8086
"item.4.key": "empty",
8187
"item.4.value": "",
8288
"item.4.is_null": "false",
8389
"item.4.sensitive": "false",
90+
"item.4.order": "4",
8491
} {
8592
require.Equal(t, expected, metadata.Primary.Attributes[key])
8693
}

provider/provider.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strings"
88

99
"github.com/hashicorp/go-cty/cty"
10+
"github.com/hashicorp/go-cty/cty/gocty"
1011
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1112
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1213
"golang.org/x/xerrors"
@@ -103,6 +104,7 @@ func populateIsNull(resourceData *schema.ResourceData) (result interface{}, err
103104
"key": key,
104105
"value": valueAsString(item.GetAttr("value")),
105106
"sensitive": valueAsBool(item.GetAttr("sensitive")),
107+
"order": valueAsInt(item.GetAttr("order")),
106108
}
107109
if item.GetAttr("value").IsNull() {
108110
resultItem["is_null"] = true
@@ -132,6 +134,15 @@ func valueAsBool(value cty.Value) interface{} {
132134
return value.True()
133135
}
134136

137+
func valueAsInt(value cty.Value) interface{} {
138+
if value.IsNull() {
139+
return nil
140+
}
141+
var valueAsInt int64
142+
gocty.FromCtyValue(value, &valueAsInt)
143+
return valueAsInt
144+
}
145+
135146
// errorAsDiagnostic transforms a Go error to a diag.Diagnostics object representing a fatal error.
136147
func errorAsDiagnostics(err error) diag.Diagnostics {
137148
return []diag.Diagnostic{{

0 commit comments

Comments
 (0)