-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
roachprod, roachtest: use same cluster name sanitization
Previously, roachtest had it's own function to sanitize cluster names, while roachprod had it's own function to verify cluster names. This change removes both and opts instead to use vm.DNSSafeName. This change also introduces MalformedClusterNameError which gives a hint on what is wrong with the name and tells roachtest not to retry cluster creation.
- Loading branch information
1 parent
cd17692
commit 927338d
Showing
5 changed files
with
143 additions
and
24 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,81 @@ | ||
// Copyright 2024 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package roachprod | ||
|
||
import ( | ||
"io" | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/roachprod/logger" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func nilLogger() *logger.Logger { | ||
lcfg := logger.Config{ | ||
Stdout: io.Discard, | ||
Stderr: io.Discard, | ||
} | ||
l, err := lcfg.NewLogger("" /* path */) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return l | ||
} | ||
|
||
func TestVerifyClusterName(t *testing.T) { | ||
_findActiveAccounts = func(l *logger.Logger) (map[string]string, error) { | ||
return map[string]string{"1": "user1", "2": "user2", "3": "USER4"}, nil | ||
} | ||
defer func() { | ||
_findActiveAccounts = nil | ||
}() | ||
cases := []struct { | ||
description, clusterName, username string | ||
errorExpected bool | ||
}{ | ||
{ | ||
"username found", "user1-clustername", "", false, | ||
}, | ||
{ | ||
"username not found", "user3-clustername", "", true, | ||
}, | ||
{ | ||
"specified username", "user3-clustername", "user3", false, | ||
}, | ||
{ | ||
"specified username that doesn't match", "user1-clustername", "fakeuser", true, | ||
}, | ||
{ | ||
"clustername not sanitized", "UserName-clustername", "", true, | ||
}, | ||
{ | ||
"no username", "clustername", "", true, | ||
}, | ||
{ | ||
"no clustername", "user1", "", true, | ||
}, | ||
{ | ||
"unsanitized found username", "user4-clustername", "", false, | ||
}, | ||
{ | ||
"unsanitized specified username", "user3-clustername", "USER3", false, | ||
}, | ||
} | ||
for _, c := range cases { | ||
t.Run(c.description, func(t *testing.T) { | ||
if c.errorExpected { | ||
assert.Error(t, verifyClusterName(nilLogger(), c.clusterName, c.username)) | ||
} else { | ||
assert.NoError(t, verifyClusterName(nilLogger(), c.clusterName, c.username)) | ||
} | ||
}) | ||
} | ||
} |
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