From ae6a20e4d93a7bd53404fd32cbd46e9728705669 Mon Sep 17 00:00:00 2001 From: Adrien Raffin-Caboisse Date: Wed, 23 Feb 2022 14:28:20 +0100 Subject: [PATCH] fix: add valid test identified by linter --- namespaces.go | 6 +++--- namespaces_test.go | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/namespaces.go b/namespaces.go index b02f7a75..e5c6448e 100644 --- a/namespaces.go +++ b/namespaces.go @@ -271,9 +271,9 @@ func (n *Namespace) toProto() *v1.Namespace { func NormalizeNamespaceName(name string, stripEmailDomain bool) (string, error) { name = strings.ToLower(name) name = strings.ReplaceAll(name, "'", "") - if stripEmailDomain { - idx := strings.Index(name, "@") - name = name[:idx] + atIdx := strings.Index(name, "@") + if stripEmailDomain && atIdx > 0 { + name = name[:atIdx] } else { name = strings.ReplaceAll(name, "@", ".") } diff --git a/namespaces_test.go b/namespaces_test.go index 6fb572cc..6cef5f5b 100644 --- a/namespaces_test.go +++ b/namespaces_test.go @@ -280,6 +280,15 @@ func TestNormalizeNamespaceName(t *testing.T) { want: "foo.bar", wantErr: false, }, + { + name: "strip enabled no email passed as argument", + args: args{ + name: "not-email-and-strip-enabled", + stripEmailDomain: true, + }, + want: "not-email-and-strip-enabled", + wantErr: false, + }, { name: "normalize complex email", args: args{