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

Commit

Permalink
constants in naming
Browse files Browse the repository at this point in the history
  • Loading branch information
nachocano committed Jun 4, 2020
1 parent 9d3d0af commit 2ca0af1
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions pkg/reconciler/broker/resources/names_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

"github.com/google/go-cmp/cmp"
brokerv1beta1 "github.com/google/knative-gcp/pkg/apis/broker/v1beta1"
"github.com/google/knative-gcp/pkg/utils"
"github.com/google/knative-gcp/pkg/utils/naming"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)
Expand All @@ -33,9 +33,9 @@ const (
truncatedNameMax = 146
)

var maxName = strings.Repeat("n", utils.K8sNameMax)
var maxName = strings.Repeat("n", naming.K8sNameMax)

var maxNamespace = strings.Repeat("s", utils.K8sNamespaceMax)
var maxNamespace = strings.Repeat("s", naming.K8sNamespaceMax)

func TestGenerateDecouplingTopicName(t *testing.T) {
testCases := []struct {
Expand All @@ -62,13 +62,13 @@ func TestGenerateDecouplingTopicName(t *testing.T) {
ns: "default",
n: maxName,
uid: testUID,
want: fmt.Sprintf("cre-bkr_default_%s_%s", strings.Repeat("n", truncatedNameMax+(utils.K8sNamespaceMax-7)), testUID),
want: fmt.Sprintf("cre-bkr_default_%s_%s", strings.Repeat("n", truncatedNameMax+(naming.K8sNamespaceMax-7)), testUID),
}}

for _, tc := range testCases {
got := GenerateDecouplingTopicName(broker(tc.ns, tc.n, tc.uid))
if len(got) > utils.PubsubMax {
t.Errorf("name length %d is greater than %d", len(got), utils.PubsubMax)
if len(got) > naming.PubsubMax {
t.Errorf("name length %d is greater than %d", len(got), naming.PubsubMax)
}
if diff := cmp.Diff(tc.want, got); diff != "" {
t.Errorf("unexpected (-want, +got) = %v", diff)
Expand Down Expand Up @@ -101,13 +101,13 @@ func TestGenerateDecouplingSubscriptionName(t *testing.T) {
ns: "default",
n: maxName,
uid: testUID,
want: fmt.Sprintf("cre-bkr_default_%s_%s", strings.Repeat("n", truncatedNameMax+(utils.K8sNamespaceMax-7)), testUID),
want: fmt.Sprintf("cre-bkr_default_%s_%s", strings.Repeat("n", truncatedNameMax+(naming.K8sNamespaceMax-7)), testUID),
}}

for _, tc := range testCases {
got := GenerateDecouplingSubscriptionName(broker(tc.ns, tc.n, tc.uid))
if len(got) > utils.PubsubMax {
t.Errorf("name length %d is greater than %d", len(got), utils.PubsubMax)
if len(got) > naming.PubsubMax {
t.Errorf("name length %d is greater than %d", len(got), naming.PubsubMax)
}
if diff := cmp.Diff(tc.want, got); diff != "" {
t.Errorf("unexpected (want, +got) = %v", diff)
Expand Down Expand Up @@ -140,13 +140,13 @@ func TestGenerateRetryTopicName(t *testing.T) {
ns: "default",
n: maxName,
uid: testUID,
want: fmt.Sprintf("cre-tgr_default_%s_%s", strings.Repeat("n", truncatedNameMax+(utils.K8sNamespaceMax-7)), testUID),
want: fmt.Sprintf("cre-tgr_default_%s_%s", strings.Repeat("n", truncatedNameMax+(naming.K8sNamespaceMax-7)), testUID),
}}

for _, tc := range testCases {
got := GenerateRetryTopicName(trigger(tc.ns, tc.n, tc.uid))
if len(got) > utils.PubsubMax {
t.Errorf("name length %d is greater than %d", len(got), utils.PubsubMax)
if len(got) > naming.PubsubMax {
t.Errorf("name length %d is greater than %d", len(got), naming.PubsubMax)
}
if diff := cmp.Diff(tc.want, got); diff != "" {
t.Errorf("unexpected (want, +got) = %v", diff)
Expand Down Expand Up @@ -179,13 +179,13 @@ func TestGenerateRetrySubscriptionName(t *testing.T) {
ns: "default",
n: maxName,
uid: testUID,
want: fmt.Sprintf("cre-tgr_default_%s_%s", strings.Repeat("n", truncatedNameMax+(utils.K8sNamespaceMax-7)), testUID),
want: fmt.Sprintf("cre-tgr_default_%s_%s", strings.Repeat("n", truncatedNameMax+(naming.K8sNamespaceMax-7)), testUID),
}}

for _, tc := range testCases {
got := GenerateRetrySubscriptionName(trigger(tc.ns, tc.n, tc.uid))
if len(got) > utils.PubsubMax {
t.Errorf("name length %d is greater than %d", len(got), utils.PubsubMax)
if len(got) > naming.PubsubMax {
t.Errorf("name length %d is greater than %d", len(got), naming.PubsubMax)
}
if diff := cmp.Diff(tc.want, got); diff != "" {
t.Errorf("unexpected (want, +got) = %v", diff)
Expand Down

0 comments on commit 2ca0af1

Please sign in to comment.