mirror of https://github.com/knative/pkg.git
Move Destination under knative.dev/pkg/apis/duck/v1. (#851)
Destination sits in a strange versioned directory without a group under APIs. Destination is in fact part of our duck type space, so it belongs under the `duck` group. This moves the definition (previously v1alpha1) to `v1` because it is referenced from source types that have been designated `v1`.
This commit is contained in:
parent
93838817ef
commit
285df36be4
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
Copyright 2019 The Knative Authors
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"knative.dev/pkg/apis"
|
||||
)
|
||||
|
||||
// Destination represents a target of an invocation over HTTP.
|
||||
type Destination struct {
|
||||
// Ref points to an Addressable.
|
||||
// +optional
|
||||
Ref *corev1.ObjectReference `json:"ref,omitempty"`
|
||||
|
||||
// URI can be an absolute URL(non-empty scheme and non-empty host) pointing to the target or a relative URI. Relative URIs will be resolved using the base URI retrieved from Ref.
|
||||
// +optional
|
||||
URI *apis.URL `json:"uri,omitempty"`
|
||||
}
|
||||
|
||||
func (dest *Destination) Validate(ctx context.Context) *apis.FieldError {
|
||||
if dest == nil {
|
||||
return nil
|
||||
}
|
||||
return ValidateDestination(*dest).ViaField(apis.CurrentField)
|
||||
}
|
||||
|
||||
// ValidateDestination validates Destination.
|
||||
func ValidateDestination(dest Destination) *apis.FieldError {
|
||||
var ref *corev1.ObjectReference
|
||||
if dest.Ref != nil {
|
||||
ref = dest.Ref
|
||||
}
|
||||
if ref == nil && dest.URI == nil {
|
||||
return apis.ErrGeneric("expected at least one, got none", "ref", "uri")
|
||||
}
|
||||
|
||||
if ref != nil && dest.URI != nil && dest.URI.URL().IsAbs() {
|
||||
return apis.ErrGeneric("Absolute URI is not allowed when Ref or [apiVersion, kind, name] is present", "[apiVersion, kind, name]", "ref", "uri")
|
||||
}
|
||||
// IsAbs() check whether the URL has a non-empty scheme. Besides the non-empty scheme, we also require dest.URI has a non-empty host
|
||||
if ref == nil && dest.URI != nil && (!dest.URI.URL().IsAbs() || dest.URI.Host == "") {
|
||||
return apis.ErrInvalidValue("Relative URI is not allowed when Ref and [apiVersion, kind, name] is absent", "uri")
|
||||
}
|
||||
if ref != nil && dest.URI == nil {
|
||||
if dest.Ref != nil {
|
||||
return validateDestinationRef(*ref).ViaField("ref")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetRef gets the ObjectReference from this Destination, if one is present. If no ref is present,
|
||||
// then nil is returned.
|
||||
func (dest *Destination) GetRef() *corev1.ObjectReference {
|
||||
if dest == nil {
|
||||
return nil
|
||||
}
|
||||
return dest.Ref
|
||||
}
|
||||
|
||||
func validateDestinationRef(ref corev1.ObjectReference) *apis.FieldError {
|
||||
// Check the object.
|
||||
var errs *apis.FieldError
|
||||
// Required Fields
|
||||
if ref.Name == "" {
|
||||
errs = errs.Also(apis.ErrMissingField("name"))
|
||||
}
|
||||
if ref.APIVersion == "" {
|
||||
errs = errs.Also(apis.ErrMissingField("apiVersion"))
|
||||
}
|
||||
if ref.Kind == "" {
|
||||
errs = errs.Also(apis.ErrMissingField("kind"))
|
||||
}
|
||||
|
||||
return errs
|
||||
}
|
|
@ -0,0 +1,184 @@
|
|||
/*
|
||||
Copyright 2019 The Knative Authors
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"knative.dev/pkg/apis"
|
||||
)
|
||||
|
||||
const (
|
||||
kind = "SomeKind"
|
||||
apiVersion = "v1mega1"
|
||||
name = "a-name"
|
||||
)
|
||||
|
||||
func TestValidateDestination(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
|
||||
validRef := corev1.ObjectReference{
|
||||
Kind: kind,
|
||||
APIVersion: apiVersion,
|
||||
Name: name,
|
||||
}
|
||||
|
||||
validURL := apis.URL{
|
||||
Scheme: "http",
|
||||
Host: "host",
|
||||
}
|
||||
|
||||
tests := map[string]struct {
|
||||
dest *Destination
|
||||
want string
|
||||
}{
|
||||
"nil valid": {
|
||||
dest: nil,
|
||||
want: "",
|
||||
},
|
||||
"valid ref": {
|
||||
dest: &Destination{
|
||||
Ref: &validRef,
|
||||
},
|
||||
want: "",
|
||||
},
|
||||
"invalid ref, missing name": {
|
||||
dest: &Destination{
|
||||
Ref: &corev1.ObjectReference{
|
||||
Kind: kind,
|
||||
APIVersion: apiVersion,
|
||||
},
|
||||
},
|
||||
want: "missing field(s): ref.name",
|
||||
},
|
||||
"invalid ref, missing api version": {
|
||||
dest: &Destination{
|
||||
Ref: &corev1.ObjectReference{
|
||||
Kind: kind,
|
||||
Name: apiVersion,
|
||||
},
|
||||
},
|
||||
want: "missing field(s): ref.apiVersion",
|
||||
},
|
||||
"invalid ref, missing kind": {
|
||||
dest: &Destination{
|
||||
Ref: &corev1.ObjectReference{
|
||||
APIVersion: apiVersion,
|
||||
Name: name,
|
||||
},
|
||||
},
|
||||
want: "missing field(s): ref.kind",
|
||||
},
|
||||
"valid uri": {
|
||||
dest: &Destination{
|
||||
URI: &validURL,
|
||||
},
|
||||
},
|
||||
"invalid, uri has no host": {
|
||||
dest: &Destination{
|
||||
URI: &apis.URL{
|
||||
Scheme: "http",
|
||||
},
|
||||
},
|
||||
want: "invalid value: Relative URI is not allowed when Ref and [apiVersion, kind, name] is absent: uri",
|
||||
},
|
||||
"invalid, uri is not absolute url": {
|
||||
dest: &Destination{
|
||||
URI: &apis.URL{
|
||||
Host: "host",
|
||||
},
|
||||
},
|
||||
want: "invalid value: Relative URI is not allowed when Ref and [apiVersion, kind, name] is absent: uri",
|
||||
},
|
||||
"invalid, both uri and ref, uri is absolute URL": {
|
||||
dest: &Destination{
|
||||
URI: &validURL,
|
||||
Ref: &validRef,
|
||||
},
|
||||
want: "Absolute URI is not allowed when Ref or [apiVersion, kind, name] is present: [apiVersion, kind, name], ref, uri",
|
||||
},
|
||||
"invalid, both ref, [apiVersion, kind, name] and uri are nil": {
|
||||
dest: &Destination{},
|
||||
want: "expected at least one, got none: ref, uri",
|
||||
},
|
||||
"valid, both uri and ref, uri is not a absolute URL": {
|
||||
dest: &Destination{
|
||||
URI: &apis.URL{
|
||||
Path: "/handler",
|
||||
},
|
||||
Ref: &validRef,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range tests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
gotErr := tc.dest.Validate(ctx)
|
||||
|
||||
if tc.want != "" {
|
||||
if got, want := gotErr.Error(), tc.want; got != want {
|
||||
t.Errorf("%s: Error() = %v, wanted %v", name, got, want)
|
||||
}
|
||||
} else if gotErr != nil {
|
||||
t.Errorf("%s: Validate() = %v, wanted nil", name, gotErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDestination_GetRef(t *testing.T) {
|
||||
ref := &corev1.ObjectReference{
|
||||
APIVersion: apiVersion,
|
||||
Kind: kind,
|
||||
Name: name,
|
||||
}
|
||||
tests := map[string]struct {
|
||||
dest *Destination
|
||||
want *corev1.ObjectReference
|
||||
}{
|
||||
"nil destination": {
|
||||
dest: nil,
|
||||
want: nil,
|
||||
},
|
||||
"uri": {
|
||||
dest: &Destination{
|
||||
URI: &apis.URL{
|
||||
Host: "foo",
|
||||
},
|
||||
},
|
||||
want: nil,
|
||||
},
|
||||
"ref": {
|
||||
dest: &Destination{
|
||||
Ref: ref,
|
||||
},
|
||||
want: ref,
|
||||
},
|
||||
}
|
||||
|
||||
for n, tc := range tests {
|
||||
t.Run(n, func(t *testing.T) {
|
||||
got := tc.dest.GetRef()
|
||||
if diff := cmp.Diff(tc.want, got); diff != "" {
|
||||
t.Errorf("Unexpected result (-want +got): %s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -25,7 +25,6 @@ import (
|
|||
|
||||
"knative.dev/pkg/apis"
|
||||
"knative.dev/pkg/apis/duck"
|
||||
apisv1alpha1 "knative.dev/pkg/apis/v1alpha1"
|
||||
)
|
||||
|
||||
// Source is an Implementable "duck type".
|
||||
|
@ -51,7 +50,7 @@ type Source struct {
|
|||
type SourceSpec struct {
|
||||
// Sink is a reference to an object that will resolve to a domain name or a
|
||||
// URI directly to use as the sink.
|
||||
Sink apisv1alpha1.Destination `json:"sink,omitempty"`
|
||||
Sink Destination `json:"sink,omitempty"`
|
||||
|
||||
// CloudEventOverrides defines overrides to control the output format and
|
||||
// modifications of the event sent to the sink.
|
||||
|
@ -117,7 +116,7 @@ func (*Source) GetFullType() duck.Populatable {
|
|||
|
||||
// Populate implements duck.Populatable
|
||||
func (s *Source) Populate() {
|
||||
s.Spec.Sink = apisv1alpha1.Destination{
|
||||
s.Spec.Sink = Destination{
|
||||
URI: &apis.URL{
|
||||
Scheme: "https",
|
||||
Host: "tableflip.dev",
|
||||
|
|
|
@ -21,6 +21,7 @@ limitations under the License.
|
|||
package v1
|
||||
|
||||
import (
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
||||
apis "knative.dev/pkg/apis"
|
||||
)
|
||||
|
@ -172,6 +173,32 @@ func (in Conditions) DeepCopy() Conditions {
|
|||
return *out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *Destination) DeepCopyInto(out *Destination) {
|
||||
*out = *in
|
||||
if in.Ref != nil {
|
||||
in, out := &in.Ref, &out.Ref
|
||||
*out = new(corev1.ObjectReference)
|
||||
**out = **in
|
||||
}
|
||||
if in.URI != nil {
|
||||
in, out := &in.URI, &out.URI
|
||||
*out = new(apis.URL)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Destination.
|
||||
func (in *Destination) DeepCopy() *Destination {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(Destination)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *KResource) DeepCopyInto(out *KResource) {
|
||||
*out = *in
|
||||
|
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package v1alpha1
|
||||
package v1beta1
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package v1alpha1
|
||||
package v1beta1
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -25,7 +25,6 @@ import (
|
|||
|
||||
"knative.dev/pkg/apis"
|
||||
"knative.dev/pkg/apis/duck"
|
||||
apisv1alpha1 "knative.dev/pkg/apis/v1alpha1"
|
||||
)
|
||||
|
||||
// Source is an Implementable "duck type".
|
||||
|
@ -51,7 +50,7 @@ type Source struct {
|
|||
type SourceSpec struct {
|
||||
// Sink is a reference to an object that will resolve to a domain name or a
|
||||
// URI directly to use as the sink.
|
||||
Sink apisv1alpha1.Destination `json:"sink,omitempty"`
|
||||
Sink Destination `json:"sink,omitempty"`
|
||||
|
||||
// CloudEventOverrides defines overrides to control the output format and
|
||||
// modifications of the event sent to the sink.
|
||||
|
@ -117,7 +116,7 @@ func (*Source) GetFullType() duck.Populatable {
|
|||
|
||||
// Populate implements duck.Populatable
|
||||
func (s *Source) Populate() {
|
||||
s.Spec.Sink = apisv1alpha1.Destination{
|
||||
s.Spec.Sink = Destination{
|
||||
URI: &apis.URL{
|
||||
Scheme: "https",
|
||||
Host: "tableflip.dev",
|
||||
|
|
|
@ -21,6 +21,7 @@ limitations under the License.
|
|||
package v1beta1
|
||||
|
||||
import (
|
||||
v1 "k8s.io/api/core/v1"
|
||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
||||
apis "knative.dev/pkg/apis"
|
||||
)
|
||||
|
@ -172,6 +173,32 @@ func (in Conditions) DeepCopy() Conditions {
|
|||
return *out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *Destination) DeepCopyInto(out *Destination) {
|
||||
*out = *in
|
||||
if in.Ref != nil {
|
||||
in, out := &in.Ref, &out.Ref
|
||||
*out = new(v1.ObjectReference)
|
||||
**out = **in
|
||||
}
|
||||
if in.URI != nil {
|
||||
in, out := &in.URI, &out.URI
|
||||
*out = new(apis.URL)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Destination.
|
||||
func (in *Destination) DeepCopy() *Destination {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(Destination)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *KResource) DeepCopyInto(out *KResource) {
|
||||
*out = *in
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
/*
|
||||
Copyright 2019 The Knative Authors
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// +k8s:deepcopy-gen=package
|
||||
package v1alpha1
|
|
@ -1,52 +0,0 @@
|
|||
// +build !ignore_autogenerated
|
||||
|
||||
/*
|
||||
Copyright 2019 The Knative Authors
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by deepcopy-gen. DO NOT EDIT.
|
||||
|
||||
package v1alpha1
|
||||
|
||||
import (
|
||||
v1 "k8s.io/api/core/v1"
|
||||
apis "knative.dev/pkg/apis"
|
||||
)
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *Destination) DeepCopyInto(out *Destination) {
|
||||
*out = *in
|
||||
if in.Ref != nil {
|
||||
in, out := &in.Ref, &out.Ref
|
||||
*out = new(v1.ObjectReference)
|
||||
**out = **in
|
||||
}
|
||||
if in.URI != nil {
|
||||
in, out := &in.URI, &out.URI
|
||||
*out = new(apis.URL)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Destination.
|
||||
func (in *Destination) DeepCopy() *Destination {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(Destination)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
|
@ -20,9 +20,9 @@ set -o pipefail
|
|||
|
||||
source $(dirname $0)/../vendor/knative.dev/test-infra/scripts/library.sh
|
||||
|
||||
CODEGEN_PKG=${CODEGEN_PKG:-$(cd ${REPO_ROOT_DIR}; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../code-generator)}
|
||||
CODEGEN_PKG=${CODEGEN_PKG:-$(cd ${REPO_ROOT_DIR}; ls -d -1 $(dirname $0)/../vendor/k8s.io/code-generator 2>/dev/null || echo ../code-generator)}
|
||||
|
||||
go install ./vendor/k8s.io/code-generator/cmd/deepcopy-gen
|
||||
go install $(dirname $0)/../vendor/k8s.io/code-generator/cmd/deepcopy-gen
|
||||
|
||||
# generate the code with:
|
||||
# --output-base because this script should also be able to run inside the vendor dir of
|
||||
|
@ -64,7 +64,7 @@ ${CODEGEN_PKG}/generate-groups.sh "deepcopy" \
|
|||
|
||||
# Depends on generate-groups.sh to install bin/deepcopy-gen
|
||||
${GOPATH}/bin/deepcopy-gen --input-dirs \
|
||||
knative.dev/pkg/apis,knative.dev/pkg/apis/v1alpha1,knative.dev/pkg/logging,knative.dev/pkg/testing \
|
||||
knative.dev/pkg/apis,knative.dev/pkg/logging,knative.dev/pkg/testing \
|
||||
-O zz_generated.deepcopy \
|
||||
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@ import (
|
|||
"knative.dev/pkg/apis"
|
||||
pkgapisduck "knative.dev/pkg/apis/duck"
|
||||
duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1"
|
||||
apisv1alpha1 "knative.dev/pkg/apis/v1alpha1"
|
||||
"knative.dev/pkg/controller"
|
||||
"knative.dev/pkg/network"
|
||||
"knative.dev/pkg/tracker"
|
||||
|
@ -63,7 +62,7 @@ func NewURIResolver(ctx context.Context, callback func(types.NamespacedName)) *U
|
|||
}
|
||||
|
||||
// URIFromDestination resolves a Destination into a URI string.
|
||||
func (r *URIResolver) URIFromDestination(dest apisv1alpha1.Destination, parent interface{}) (string, error) {
|
||||
func (r *URIResolver) URIFromDestination(dest duckv1beta1.Destination, parent interface{}) (string, error) {
|
||||
var deprecatedObjectReference *corev1.ObjectReference
|
||||
if dest.DeprecatedAPIVersion == "" && dest.DeprecatedKind == "" && dest.DeprecatedName == "" && dest.DeprecatedNamespace == "" {
|
||||
deprecatedObjectReference = nil
|
||||
|
|
|
@ -30,7 +30,6 @@ import (
|
|||
"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/resolver"
|
||||
)
|
||||
|
@ -61,13 +60,13 @@ func init() {
|
|||
func TestGetURI_ObjectReference(t *testing.T) {
|
||||
tests := map[string]struct {
|
||||
objects []runtime.Object
|
||||
dest apisv1alpha1.Destination
|
||||
dest duckv1beta1.Destination
|
||||
wantURI string
|
||||
wantErr error
|
||||
}{"nil everything": {
|
||||
wantErr: fmt.Errorf("destination missing Ref, [apiVersion, kind, name] and URI, expected at least one"),
|
||||
}, "Happy URI with path": {
|
||||
dest: apisv1alpha1.Destination{
|
||||
dest: duckv1beta1.Destination{
|
||||
URI: &apis.URL{
|
||||
Scheme: "http",
|
||||
Host: "example.com",
|
||||
|
@ -76,14 +75,14 @@ func TestGetURI_ObjectReference(t *testing.T) {
|
|||
},
|
||||
wantURI: "http://example.com/foo",
|
||||
}, "URI is not absolute URL": {
|
||||
dest: apisv1alpha1.Destination{
|
||||
dest: duckv1beta1.Destination{
|
||||
URI: &apis.URL{
|
||||
Host: "example.com",
|
||||
},
|
||||
},
|
||||
wantErr: fmt.Errorf("URI is not absolute(both scheme and host should be non-empty): %v", "//example.com"),
|
||||
}, "URI with no host": {
|
||||
dest: apisv1alpha1.Destination{
|
||||
dest: duckv1beta1.Destination{
|
||||
URI: &apis.URL{
|
||||
Scheme: "http",
|
||||
},
|
||||
|
@ -94,7 +93,7 @@ func TestGetURI_ObjectReference(t *testing.T) {
|
|||
objects: []runtime.Object{
|
||||
getAddressable(),
|
||||
},
|
||||
dest: apisv1alpha1.Destination{Ref: getAddressableRef(),
|
||||
dest: duckv1beta1.Destination{Ref: getAddressableRef(),
|
||||
DeprecatedKind: addressableKind,
|
||||
DeprecatedName: addressableName,
|
||||
DeprecatedAPIVersion: addressableAPIVersion,
|
||||
|
@ -106,13 +105,13 @@ func TestGetURI_ObjectReference(t *testing.T) {
|
|||
objects: []runtime.Object{
|
||||
getAddressable(),
|
||||
},
|
||||
dest: apisv1alpha1.Destination{Ref: getAddressableRef()},
|
||||
dest: duckv1beta1.Destination{Ref: getAddressableRef()},
|
||||
wantURI: addressableDNS,
|
||||
}, "ref with relative uri": {
|
||||
objects: []runtime.Object{
|
||||
getAddressable(),
|
||||
},
|
||||
dest: apisv1alpha1.Destination{
|
||||
dest: duckv1beta1.Destination{
|
||||
Ref: getAddressableRef(),
|
||||
URI: &apis.URL{
|
||||
Path: "/foo",
|
||||
|
@ -123,7 +122,7 @@ func TestGetURI_ObjectReference(t *testing.T) {
|
|||
objects: []runtime.Object{
|
||||
getAddressable(),
|
||||
},
|
||||
dest: apisv1alpha1.Destination{
|
||||
dest: duckv1beta1.Destination{
|
||||
Ref: getAddressableRef(),
|
||||
URI: &apis.URL{
|
||||
Path: "foo",
|
||||
|
@ -134,7 +133,7 @@ func TestGetURI_ObjectReference(t *testing.T) {
|
|||
objects: []runtime.Object{
|
||||
getAddressableWithPathAndTrailingSlash(),
|
||||
},
|
||||
dest: apisv1alpha1.Destination{
|
||||
dest: duckv1beta1.Destination{
|
||||
Ref: getAddressableRef(),
|
||||
URI: &apis.URL{
|
||||
Path: "foo",
|
||||
|
@ -145,7 +144,7 @@ func TestGetURI_ObjectReference(t *testing.T) {
|
|||
objects: []runtime.Object{
|
||||
getAddressableWithPathAndTrailingSlash(),
|
||||
},
|
||||
dest: apisv1alpha1.Destination{
|
||||
dest: duckv1beta1.Destination{
|
||||
Ref: getAddressableRef(),
|
||||
URI: &apis.URL{
|
||||
Path: "/foo",
|
||||
|
@ -156,7 +155,7 @@ func TestGetURI_ObjectReference(t *testing.T) {
|
|||
objects: []runtime.Object{
|
||||
getAddressableWithPathAndNoTrailingSlash(),
|
||||
},
|
||||
dest: apisv1alpha1.Destination{
|
||||
dest: duckv1beta1.Destination{
|
||||
Ref: getAddressableRef(),
|
||||
URI: &apis.URL{
|
||||
Path: "foo",
|
||||
|
@ -167,7 +166,7 @@ func TestGetURI_ObjectReference(t *testing.T) {
|
|||
objects: []runtime.Object{
|
||||
getAddressableWithPathAndNoTrailingSlash(),
|
||||
},
|
||||
dest: apisv1alpha1.Destination{
|
||||
dest: duckv1beta1.Destination{
|
||||
Ref: getAddressableRef(),
|
||||
URI: &apis.URL{
|
||||
Path: "/foo",
|
||||
|
@ -178,7 +177,7 @@ func TestGetURI_ObjectReference(t *testing.T) {
|
|||
objects: []runtime.Object{
|
||||
getAddressable(),
|
||||
},
|
||||
dest: apisv1alpha1.Destination{
|
||||
dest: duckv1beta1.Destination{
|
||||
Ref: getAddressableRef(),
|
||||
URI: &apis.URL{
|
||||
Scheme: "http",
|
||||
|
@ -192,7 +191,7 @@ func TestGetURI_ObjectReference(t *testing.T) {
|
|||
objects: []runtime.Object{
|
||||
getAddressable(),
|
||||
},
|
||||
dest: apisv1alpha1.Destination{
|
||||
dest: duckv1beta1.Destination{
|
||||
DeprecatedKind: addressableKind,
|
||||
DeprecatedName: addressableName,
|
||||
DeprecatedAPIVersion: addressableAPIVersion,
|
||||
|
@ -203,7 +202,7 @@ func TestGetURI_ObjectReference(t *testing.T) {
|
|||
objects: []runtime.Object{
|
||||
getAddressable(),
|
||||
},
|
||||
dest: apisv1alpha1.Destination{
|
||||
dest: duckv1beta1.Destination{
|
||||
DeprecatedKind: addressableKind,
|
||||
DeprecatedName: addressableName,
|
||||
DeprecatedAPIVersion: addressableAPIVersion,
|
||||
|
@ -217,7 +216,7 @@ func TestGetURI_ObjectReference(t *testing.T) {
|
|||
objects: []runtime.Object{
|
||||
getAddressable(),
|
||||
},
|
||||
dest: apisv1alpha1.Destination{
|
||||
dest: duckv1beta1.Destination{
|
||||
DeprecatedKind: addressableKind,
|
||||
DeprecatedName: addressableName,
|
||||
DeprecatedAPIVersion: addressableAPIVersion,
|
||||
|
@ -231,7 +230,7 @@ func TestGetURI_ObjectReference(t *testing.T) {
|
|||
objects: []runtime.Object{
|
||||
getAddressableWithPathAndTrailingSlash(),
|
||||
},
|
||||
dest: apisv1alpha1.Destination{
|
||||
dest: duckv1beta1.Destination{
|
||||
DeprecatedKind: addressableKind,
|
||||
DeprecatedName: addressableName,
|
||||
DeprecatedAPIVersion: addressableAPIVersion,
|
||||
|
@ -245,7 +244,7 @@ func TestGetURI_ObjectReference(t *testing.T) {
|
|||
objects: []runtime.Object{
|
||||
getAddressableWithPathAndTrailingSlash(),
|
||||
},
|
||||
dest: apisv1alpha1.Destination{
|
||||
dest: duckv1beta1.Destination{
|
||||
DeprecatedKind: addressableKind,
|
||||
DeprecatedName: addressableName,
|
||||
DeprecatedAPIVersion: addressableAPIVersion,
|
||||
|
@ -259,7 +258,7 @@ func TestGetURI_ObjectReference(t *testing.T) {
|
|||
objects: []runtime.Object{
|
||||
getAddressableWithPathAndNoTrailingSlash(),
|
||||
},
|
||||
dest: apisv1alpha1.Destination{
|
||||
dest: duckv1beta1.Destination{
|
||||
DeprecatedKind: addressableKind,
|
||||
DeprecatedName: addressableName,
|
||||
DeprecatedAPIVersion: addressableAPIVersion,
|
||||
|
@ -273,7 +272,7 @@ func TestGetURI_ObjectReference(t *testing.T) {
|
|||
objects: []runtime.Object{
|
||||
getAddressableWithPathAndNoTrailingSlash(),
|
||||
},
|
||||
dest: apisv1alpha1.Destination{
|
||||
dest: duckv1beta1.Destination{
|
||||
DeprecatedKind: addressableKind,
|
||||
DeprecatedName: addressableName,
|
||||
DeprecatedAPIVersion: addressableAPIVersion,
|
||||
|
@ -287,7 +286,7 @@ func TestGetURI_ObjectReference(t *testing.T) {
|
|||
objects: []runtime.Object{
|
||||
getAddressable(),
|
||||
},
|
||||
dest: apisv1alpha1.Destination{
|
||||
dest: duckv1beta1.Destination{
|
||||
DeprecatedKind: addressableKind,
|
||||
DeprecatedName: addressableName,
|
||||
DeprecatedAPIVersion: addressableAPIVersion,
|
||||
|
@ -304,29 +303,29 @@ func TestGetURI_ObjectReference(t *testing.T) {
|
|||
objects: []runtime.Object{
|
||||
getAddressableNilURL(),
|
||||
},
|
||||
dest: apisv1alpha1.Destination{Ref: getUnaddressableRef()},
|
||||
dest: duckv1beta1.Destination{Ref: getUnaddressableRef()},
|
||||
wantErr: fmt.Errorf(`url missing in address of %+v`, getUnaddressableRef()),
|
||||
},
|
||||
"nil address": {
|
||||
objects: []runtime.Object{
|
||||
getAddressableNilAddress(),
|
||||
},
|
||||
dest: apisv1alpha1.Destination{Ref: getUnaddressableRef()},
|
||||
dest: duckv1beta1.Destination{Ref: getUnaddressableRef()},
|
||||
wantErr: fmt.Errorf(`address not set for %+v`, getUnaddressableRef()),
|
||||
}, "missing host": {
|
||||
objects: []runtime.Object{
|
||||
getAddressableNoHostURL(),
|
||||
},
|
||||
dest: apisv1alpha1.Destination{Ref: getUnaddressableRef()},
|
||||
dest: duckv1beta1.Destination{Ref: getUnaddressableRef()},
|
||||
wantErr: fmt.Errorf(`hostname missing in address of %+v`, getUnaddressableRef()),
|
||||
}, "missing status": {
|
||||
objects: []runtime.Object{
|
||||
getAddressableNoStatus(),
|
||||
},
|
||||
dest: apisv1alpha1.Destination{Ref: getUnaddressableRef()},
|
||||
dest: duckv1beta1.Destination{Ref: getUnaddressableRef()},
|
||||
wantErr: fmt.Errorf(`address not set for %+v`, getUnaddressableRef()),
|
||||
}, "notFound": {
|
||||
dest: apisv1alpha1.Destination{Ref: getUnaddressableRef()},
|
||||
dest: duckv1beta1.Destination{Ref: getUnaddressableRef()},
|
||||
wantErr: fmt.Errorf(`failed to get ref %+v: %s "%s" not found`, getUnaddressableRef(), unaddressableResource, unaddressableName),
|
||||
}}
|
||||
|
||||
|
|
Loading…
Reference in New Issue