Skip to content
This repository has been archived by the owner on Jun 19, 2022. It is now read-only.

Commit

Permalink
fix tests and add labels.go for reconciler/pubsub/resources
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Lopez committed Feb 10, 2020
1 parent 9f3aeb5 commit 1c81433
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 9 deletions.
2 changes: 2 additions & 0 deletions pkg/reconciler/events/auditlogs/auditlogs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func TestAllCases(t *testing.T) {
}),
WithTopicLabels(map[string]string{
"receive-adapter": receiveAdapterName,
"source": sourceName,
}),
WithTopicOwnerReferences([]metav1.OwnerReference{sourceOwnerRef(sourceName, sourceUID)}),
),
Expand Down Expand Up @@ -372,6 +373,7 @@ func TestAllCases(t *testing.T) {
WithPullSubscriptionSink(sinkGVK, sinkName),
WithPullSubscriptionLabels(map[string]string{
"receive-adapter": receiveAdapterName,
"source": sourceName,
}),
WithPullSubscriptionAnnotations(map[string]string{
"metrics-resource-group": resourceGroup,
Expand Down
3 changes: 2 additions & 1 deletion pkg/reconciler/events/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ func TestAllCases(t *testing.T) {
}),
WithTopicLabels(map[string]string{
"receive-adapter": receiveAdapterName,
"source": schedulerName,
}),
WithTopicOwnerReferences([]metav1.OwnerReference{ownerRef()}),
),
Expand Down Expand Up @@ -435,7 +436,7 @@ func TestAllCases(t *testing.T) {
WithPullSubscriptionSink(sinkGVK, sinkName),
WithPullSubscriptionLabels(map[string]string{
"receive-adapter": receiveAdapterName,
}),
"source": schedulerName}),
WithPullSubscriptionAnnotations(map[string]string{
"metrics-resource-group": resourceGroup,
}),
Expand Down
10 changes: 2 additions & 8 deletions pkg/reconciler/pubsub/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ func (psb *PubSubBase) ReconcilePubSub(ctx context.Context, pubsubable duck.PubS
Spec: spec,
Owner: pubsubable,
Topic: topic,
Labels: map[string]string{
"receive-adapter": psb.receiveAdapterName,
"source": name,
},
Labels: resources.GetLabels(psb.receiveAdapterName, name),
}
newTopic := resources.MakeTopic(args)
t, err = topics.Create(newTopic)
Expand Down Expand Up @@ -110,10 +107,7 @@ func (psb *PubSubBase) ReconcilePubSub(ctx context.Context, pubsubable duck.PubS
Topic: topic,
AdapterType: psb.adapterType,
ResourceGroup: resourceGroup,
Labels: map[string]string{
"receive-adapter": psb.receiveAdapterName,
"source": name,
},
Labels: resources.GetLabels(psb.receiveAdapterName, name),
}
newPS := resources.MakePullSubscription(args)
ps, err = pullSubscriptions.Create(newPS)
Expand Down
24 changes: 24 additions & 0 deletions pkg/reconciler/pubsub/resources/labels.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Copyright 2019 Google LLC
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 resources

func GetLabels(receiveAdapterName, source string) map[string]string {
return map[string]string{
"receive-adapter": receiveAdapterName,
"events.cloud.google.com/source-name": source,
}
}
35 changes: 35 additions & 0 deletions pkg/reconciler/pubsub/resources/labesl_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Copyright 2019 Google LLC
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 resources

import (
"testing"

"github.com/google/go-cmp/cmp"
)

func TestGetLabels(t *testing.T) {
want := map[string]string{
"receive-adapter": "receive-adapter-name",
"events.cloud.google.com/source-name": "source",
}
got := GetLabels("receive-adapter-name", "source")

if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("unexpected (-want, +got) = %v", diff)
}
}

0 comments on commit 1c81433

Please sign in to comment.