-
Notifications
You must be signed in to change notification settings - Fork 953
refactor: increase group name limit to 255 #15377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,11 @@ package codersdk_test | |
import ( | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"golang.org/x/exp/rand" | ||
|
||
"github.com/coder/coder/v2/codersdk" | ||
"github.com/coder/coder/v2/testutil" | ||
|
@@ -254,3 +256,40 @@ func TestUserRealNameValid(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
func TestGroupNameValid(t *testing.T) { | ||
t.Parallel() | ||
|
||
testCases := []struct { | ||
Name string | ||
Valid bool | ||
}{ | ||
{"", false}, | ||
{"my-group", true}, | ||
{"create", false}, | ||
{"new", false}, | ||
{"Lord Voldemort Team", false}, | ||
{randomString(255), true}, | ||
{randomString(256), false}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think get random name is limited in length 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, then perhaps There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, one last guess: |
||
} | ||
for _, testCase := range testCases { | ||
testCase := testCase | ||
t.Run(testCase.Name, func(t *testing.T) { | ||
t.Parallel() | ||
err := codersdk.GroupNameValid(testCase.Name) | ||
assert.Equal(t, testCase.Valid, err == nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you modify this to contain the error if something bad happens:
|
||
}) | ||
} | ||
} | ||
|
||
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" | ||
|
||
// RandomString generates a random string of a given length. | ||
func randomString(length int) string { | ||
seededRand := rand.New(rand.NewSource(uint64(time.Now().UnixNano()))) | ||
result := make([]byte, length) | ||
for i := range result { | ||
result[i] = charset[seededRand.Intn(len(charset))] | ||
} | ||
return string(result) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this invalid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid route conflicts.