-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
v1.0.5 | ||
v1.0.6 | ||
latest |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/samber/lo" | ||
) | ||
|
||
func (r *ControlPlaneRef) String() string { | ||
if r == nil { | ||
return "<nil>" | ||
} | ||
switch r.Type { | ||
case ControlPlaneRefKonnectID: | ||
// It's safe to assume KonnectID is not nil as it's guarded by CEL rules, but just in case let's have a fallback. | ||
konnectID := lo.FromPtrOr(r.KonnectID, "nil") | ||
return fmt.Sprintf("<%s:%s>", r.Type, konnectID) | ||
case ControlPlaneRefKonnectNamespacedRef: | ||
if r.KonnectNamespacedRef.Namespace == "" { | ||
return fmt.Sprintf("<%s:%s>", r.Type, r.KonnectNamespacedRef.Name) | ||
} | ||
return fmt.Sprintf("<%s:%s/%s>", r.Type, r.KonnectNamespacedRef.Namespace, r.KonnectNamespacedRef.Name) | ||
case ControlPlaneRefKIC: | ||
return fmt.Sprintf("<%s>", r.Type) | ||
default: | ||
return fmt.Sprintf("<unknown:%s>", r.Type) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package v1alpha1_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/kong/kubernetes-configuration/api/configuration/v1alpha1" | ||
"github.com/samber/lo" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestControlPlaneRefStringer(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
ref *v1alpha1.ControlPlaneRef | ||
expected string | ||
}{ | ||
{ | ||
name: "unknown type - doesn't panic", | ||
ref: &v1alpha1.ControlPlaneRef{ | ||
Type: "notSupportedType", | ||
}, | ||
expected: "<unknown:notSupportedType>", | ||
}, | ||
{ | ||
name: "nil - doesn't panic", | ||
ref: nil, | ||
expected: "<nil>", | ||
}, | ||
{ | ||
name: "konnectNamespacedRef with no namespace", | ||
ref: &v1alpha1.ControlPlaneRef{ | ||
Type: v1alpha1.ControlPlaneRefKonnectNamespacedRef, | ||
KonnectNamespacedRef: &v1alpha1.KonnectNamespacedRef{ | ||
Name: "foo", | ||
}, | ||
}, | ||
expected: "<konnectNamespacedRef:foo>", | ||
}, | ||
{ | ||
name: "konnectNamespacedRef with namespace", | ||
ref: &v1alpha1.ControlPlaneRef{ | ||
Type: v1alpha1.ControlPlaneRefKonnectNamespacedRef, | ||
KonnectNamespacedRef: &v1alpha1.KonnectNamespacedRef{ | ||
Namespace: "bar", | ||
Name: "foo", | ||
}, | ||
}, | ||
expected: "<konnectNamespacedRef:bar/foo>", | ||
}, | ||
{ | ||
name: "konnectID without ID - doesn't panic", | ||
ref: &v1alpha1.ControlPlaneRef{ | ||
Type: v1alpha1.ControlPlaneRefKonnectID, | ||
}, | ||
expected: "<konnectID:nil>", | ||
}, | ||
{ | ||
name: "konnectID with ID", | ||
ref: &v1alpha1.ControlPlaneRef{ | ||
Type: v1alpha1.ControlPlaneRefKonnectID, | ||
KonnectID: lo.ToPtr("foo"), | ||
}, | ||
expected: "<konnectID:foo>", | ||
}, | ||
{ | ||
name: "kic", | ||
ref: &v1alpha1.ControlPlaneRef{ | ||
Type: v1alpha1.ControlPlaneRefKIC, | ||
}, | ||
expected: "<kic>", | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
require.Equal(t, tc.expected, tc.ref.String()) | ||
}) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.