mirror of https://github.com/knative/pkg.git
Test for and fix URIResolver being idempotent (#606)
* write test for modify original * test idempotency in an easier way * and fix the bug
This commit is contained in:
parent
c73ee7b5d2
commit
2e33eeae84
|
@ -70,11 +70,11 @@ func (r *URIResolver) URIFromDestination(dest apisv1alpha1.Destination, parent i
|
|||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return extendPath(url, dest.Path).String(), nil
|
||||
return extendPath(url.DeepCopy(), dest.Path).String(), nil
|
||||
}
|
||||
|
||||
if dest.URI != nil {
|
||||
return extendPath(dest.URI, dest.Path).String(), nil
|
||||
return extendPath(dest.URI.DeepCopy(), dest.Path).String(), nil
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("destination missing ObjectReference and URI, expected exactly one")
|
||||
|
|
|
@ -28,6 +28,7 @@ import (
|
|||
"k8s.io/client-go/kubernetes/scheme"
|
||||
"knative.dev/pkg/apis"
|
||||
duckv1alpha1 "knative.dev/pkg/apis/duck/v1alpha1"
|
||||
duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1"
|
||||
apisv1alpha1 "knative.dev/pkg/apis/v1alpha1"
|
||||
fakedynamicclient "knative.dev/pkg/injection/clients/dynamicclient/fake"
|
||||
"knative.dev/pkg/ptr"
|
||||
|
@ -52,6 +53,7 @@ var (
|
|||
func init() {
|
||||
// Add types to scheme
|
||||
duckv1alpha1.AddToScheme(scheme.Scheme)
|
||||
duckv1beta1.AddToScheme(scheme.Scheme)
|
||||
}
|
||||
|
||||
func TestGetURI_ObjectReference(t *testing.T) {
|
||||
|
@ -159,7 +161,12 @@ func TestGetURI_ObjectReference(t *testing.T) {
|
|||
t.Run(n, func(t *testing.T) {
|
||||
ctx, _ := fakedynamicclient.With(context.Background(), scheme.Scheme, tc.objects...)
|
||||
r := resolver.NewURIResolver(ctx, func(string) {})
|
||||
|
||||
// Run it twice since this should be idempotent. URI Resolver should
|
||||
// not modify the cache's copy.
|
||||
_, _ = r.URIFromDestination(tc.dest, getAddressable())
|
||||
uri, gotErr := r.URIFromDestination(tc.dest, getAddressable())
|
||||
|
||||
if gotErr != nil {
|
||||
if tc.wantErr != nil {
|
||||
if diff := cmp.Diff(tc.wantErr.Error(), gotErr.Error()); diff != "" {
|
||||
|
|
Loading…
Reference in New Issue