forked from knative/client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow for http and broker sinks (knative#574)
* Introduce Broker as a kind of sink, genericize sinks in general * loltest * Fix tests for mergeout * the test file I forgot * docstrings * Move fake dynamic client into seprate file * Pass whole client, not raw client, to resolve sinks * one more test
- Loading branch information
1 parent
d03cbf9
commit f1bfafe
Showing
21 changed files
with
301 additions
and
148 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,34 @@ | ||
// 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 fake | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
k8s_fake "k8s.io/client-go/dynamic/fake" | ||
|
||
"knative.dev/client/pkg/dynamic" | ||
eventing_v1alpha1 "knative.dev/eventing/pkg/apis/eventing/v1alpha1" | ||
serving_v1alpha1 "knative.dev/serving/pkg/apis/serving/v1alpha1" | ||
) | ||
|
||
// CreateFakeKnDynamicClient gives you a dynamic client for testing contianing the given objects. | ||
func CreateFakeKnDynamicClient(testNamespace string, objects ...runtime.Object) dynamic.KnDynamicClient { | ||
scheme := runtime.NewScheme() | ||
scheme.AddKnownTypeWithName(schema.GroupVersionKind{Group: "serving.knative.dev", Version: "v1alpha1", Kind: "Service"}, &serving_v1alpha1.Service{}) | ||
scheme.AddKnownTypeWithName(schema.GroupVersionKind{Group: "eventing.knative.dev", Version: "v1alpha1", Kind: "Broker"}, &eventing_v1alpha1.Broker{}) | ||
client := k8s_fake.NewSimpleDynamicClient(scheme, objects...) | ||
return dynamic.NewKnDynamicClient(client, testNamespace) | ||
} |
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,81 @@ | ||
// 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 flags | ||
|
||
import ( | ||
"testing" | ||
|
||
"gotest.tools/assert" | ||
v1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
dynamic_fake "knative.dev/client/pkg/dynamic/fake" | ||
eventing_v1alpha1 "knative.dev/eventing/pkg/apis/eventing/v1alpha1" | ||
"knative.dev/pkg/apis" | ||
duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1" | ||
serving_v1alpha1 "knative.dev/serving/pkg/apis/serving/v1alpha1" | ||
) | ||
|
||
type resolveCase struct { | ||
sink string | ||
destination *duckv1beta1.Destination | ||
errContents string | ||
} | ||
|
||
func TestResolve(t *testing.T) { | ||
targetExampleCom, err := apis.ParseURL("http://target.example.com") | ||
mysvc := &serving_v1alpha1.Service{ | ||
TypeMeta: metav1.TypeMeta{Kind: "Service", APIVersion: "serving.knative.dev/v1alpha1"}, | ||
ObjectMeta: metav1.ObjectMeta{Name: "mysvc", Namespace: "default"}, | ||
} | ||
defaultBroker := &eventing_v1alpha1.Broker{ | ||
TypeMeta: metav1.TypeMeta{Kind: "Broker", APIVersion: "eventing.knative.dev/v1alpha1"}, | ||
ObjectMeta: metav1.ObjectMeta{Name: "default", Namespace: "default"}, | ||
} | ||
|
||
assert.NilError(t, err) | ||
cases := []resolveCase{ | ||
{"svc:mysvc", &duckv1beta1.Destination{ | ||
Ref: &v1.ObjectReference{Kind: "Service", | ||
APIVersion: "serving.knative.dev/v1alpha1", | ||
Name: "mysvc", | ||
Namespace: "default"}}, ""}, | ||
{"service:mysvc", &duckv1beta1.Destination{ | ||
Ref: &v1.ObjectReference{Kind: "Service", | ||
APIVersion: "serving.knative.dev/v1alpha1", | ||
Name: "mysvc", | ||
Namespace: "default"}}, ""}, | ||
{"svc:absent", nil, "\"absent\" not found"}, | ||
{"broker:default", &duckv1beta1.Destination{ | ||
Ref: &v1.ObjectReference{Kind: "Broker", | ||
APIVersion: "eventing.knative.dev/v1alpha1", | ||
Name: "default", | ||
Namespace: "default", | ||
}}, ""}, | ||
{"http://target.example.com", &duckv1beta1.Destination{ | ||
URI: targetExampleCom, | ||
}, ""}, | ||
} | ||
dynamicClient := dynamic_fake.CreateFakeKnDynamicClient("default", mysvc, defaultBroker) | ||
for _, c := range cases { | ||
i := &SinkFlags{c.sink} | ||
result, err := i.ResolveSink(dynamicClient, "default") | ||
if c.destination != nil { | ||
assert.DeepEqual(t, result, c.destination) | ||
assert.NilError(t, err) | ||
} else { | ||
assert.ErrorContains(t, err, c.errContents) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.