-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix resource kind lookup using URN.Type instead of QualifiedType (#2719)
This pull request uses the URN`Type` method, rather than `QualifiedType` to search if resources are a patch or list resource. Qualified types include the parent resource if there is one, so it would have failed the lookup. Additionally, comprehensive unit tests have been included to validate this change. Fixes: #2718 (manual validation was done to ensure this fix solves this CUJ)
- Loading branch information
Showing
6 changed files
with
102 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package kinds | ||
|
||
import ( | ||
"github.com/pulumi/pulumi/sdk/v3/go/common/resource" | ||
) | ||
|
||
// IsPatchURN returns true if the URN is for a Patch resource. | ||
func IsPatchURN(urn resource.URN) bool { | ||
urnS := urn.Type().String() | ||
|
||
return PatchQualifiedTypes.Has(urnS) | ||
} | ||
|
||
// IsListURN returns true if the URN is for a List resource. | ||
func IsListURN(urn resource.URN) bool { | ||
urnS := urn.Type().String() | ||
|
||
return ListQualifiedTypes.Has(urnS) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package kinds | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/pulumi/pulumi/sdk/v3/go/common/resource" | ||
) | ||
|
||
func TestIsPatchURN(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
urn resource.URN | ||
want bool | ||
}{ | ||
{ | ||
"Simple Patch resource - Happy Path", | ||
resource.URN("urn:pulumi:dev::kubernetes-ts::kubernetes:apps/v1:DaemonSetPatch::k8s-daemonset-patch"), | ||
true, | ||
}, | ||
{ | ||
"Patch resource within a Component Resource", | ||
resource.URN("urn:pulumi:dev::kubernetes-ts::my:component:Resource$kubernetes:apps/v1:DaemonSetPatch::k8s-daemonset-patch-child"), | ||
true, | ||
}, | ||
{ | ||
"Non-Patch DaemonSet resource", | ||
resource.URN("urn:pulumi:dev::kubernetes-ts::kubernetes:apps/v1:DaemonSet::k8s-daemonset"), | ||
false, | ||
}, | ||
} | ||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
if got := IsPatchURN(tc.urn); got != tc.want { | ||
t.Errorf("IsPatchURN() = %v, want %v", got, tc.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestIsListURN(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
urn resource.URN | ||
want bool | ||
}{ | ||
{ | ||
"Simple List resource - Happy Path", | ||
resource.URN("urn:pulumi:dev::kubernetes-ts::kubernetes:apps/v1:DaemonSetList::k8s-daemonset-list"), | ||
true, | ||
}, | ||
{ | ||
"List resource within a Component Resource", | ||
resource.URN("urn:pulumi:dev::kubernetes-ts::my:component:Resource$kubernetes:apps/v1:DaemonSetList::k8s-daemonset-list-child"), | ||
true, | ||
}, | ||
{ | ||
"Non-List DaemonSet resource", | ||
resource.URN("urn:pulumi:dev::kubernetes-ts::kubernetes:apps/v1:DaemonSet::k8s-daemonset"), | ||
false, | ||
}, | ||
} | ||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
if got := IsListURN(tc.urn); got != tc.want { | ||
t.Errorf("IsListURN() = %v, want %v", got, tc.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters