-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124304 from DarrylWong/backport24.1-123961
release-24.1: roachprod, roachtest: use same cluster name sanitization
- Loading branch information
Showing
9 changed files
with
203 additions
and
26 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
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
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,82 @@ | ||
// 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/cockroachdb/cockroach/pkg/roachprod/vm" | ||
"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 = vm.FindActiveAccounts | ||
}() | ||
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