Skip to content

Commit 3f13670

Browse files
committed
test: update TestExtractConnectionDetails to handle ToUnstructured behavior change
DefaultUnstructuredConverter.ToUnstructured had a behavior change in PR kubernetes/kubernetes#131029, so that its JSON marshaling would be more aligned with stdlib. This means that anonymous embedded fields without JSON tags will not be included in the output. This affects only our fakes/mocks because real objects embed structs like metav1.ObjectMeta with proper JSON tags. This commit updates the paths used in the unit tests to match the new expected behavior of ToUnstructured. Signed-off-by: Jared Watts <[email protected]>
1 parent 4805552 commit 3f13670

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@
1919

2020
# Go workspace file
2121
go.work
22+
23+
# ignore AI tools settings/config
24+
/.claude
25+
CLAUDE.md
26+
AGENTS.md

connection_test.go

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"testing"
55

66
"github.com/crossplane-contrib/function-patch-and-transform/input/v1beta1"
7+
xpv1 "github.com/crossplane/crossplane-runtime/v2/apis/common/v1"
78
"github.com/crossplane/crossplane-runtime/v2/pkg/errors"
89
"github.com/crossplane/crossplane-runtime/v2/pkg/reconciler/managed"
910
"github.com/crossplane/crossplane-runtime/v2/pkg/resource"
@@ -53,6 +54,12 @@ func TestExtractConnectionDetails(t *testing.T) {
5354
Name: "test",
5455
Generation: 4,
5556
},
57+
ConnectionSecretWriterTo: fake.ConnectionSecretWriterTo{
58+
Ref: &xpv1.SecretReference{
59+
Name: "cool-secret",
60+
Namespace: "cool-namespace",
61+
},
62+
},
5663
},
5764
data: managed.ConnectionDetails{
5865
"foo": []byte("a"),
@@ -79,25 +86,40 @@ func TestExtractConnectionDetails(t *testing.T) {
7986
Name: "fixed",
8087
Value: ptr.To[string]("value"),
8188
},
89+
// Note that the FromFieldPath values don't include their
90+
// initial path segment due to being anonymous embedded
91+
// fields in the fake.Composed struct.
8292
{
8393
Type: v1beta1.ConnectionDetailTypeFromFieldPath,
8494
Name: "name",
85-
FromFieldPath: ptr.To[string]("objectMeta.name"),
95+
FromFieldPath: ptr.To[string]("name"),
8696
},
8797
{
8898
Type: v1beta1.ConnectionDetailTypeFromFieldPath,
8999
Name: "generation",
90-
FromFieldPath: ptr.To[string]("objectMeta.generation"),
100+
FromFieldPath: ptr.To[string]("generation"),
101+
},
102+
{
103+
Type: v1beta1.ConnectionDetailTypeFromFieldPath,
104+
Name: "secretName",
105+
FromFieldPath: ptr.To[string]("Ref.name"),
106+
},
107+
{
108+
Type: v1beta1.ConnectionDetailTypeFromFieldPath,
109+
Name: "secretNamespace",
110+
FromFieldPath: ptr.To[string]("Ref.namespace"),
91111
},
92112
},
93113
},
94114
want: want{
95115
conn: managed.ConnectionDetails{
96-
"convfoo": []byte("a"),
97-
"bar": []byte("b"),
98-
"fixed": []byte("value"),
99-
"name": []byte("test"),
100-
"generation": []byte("4"),
116+
"convfoo": []byte("a"),
117+
"bar": []byte("b"),
118+
"fixed": []byte("value"),
119+
"name": []byte("test"),
120+
"generation": []byte("4"),
121+
"secretName": []byte("cool-secret"),
122+
"secretNamespace": []byte("cool-namespace"),
101123
},
102124
},
103125
},

0 commit comments

Comments
 (0)