Skip to content
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

modify slug_generator to include . #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/ood_core/job/adapters/kubernetes/slug_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ module SlugGenerator

# LOWER_PLUS_HYPHEN: An array of lowercase alphanumeric characters plus the hyphen
#This constant is not frozen, so it could potentially be modified
LOWER_PLUS_HYPHEN = ALPHANUM_LOWER + ['-']
LOWER_PLUS_HYPHEN = ALPHANUM_LOWER + ['-', '.'] # Added dot here

#patterns _do_not_ need to cover the length or start/end conditions,
#which are handled separately
OBJECT_PATTERN = /^[a-z0-9-]+$/
LABEL_PATTERN = /^[a-z0-9-_]+$/i
OBJECT_PATTERN = /^[a-z0-9\-\.]+$/ # Added dot to the pattern
LABEL_PATTERN = /^[a-z0-9\-_\.]+$/i # Added dot to the pattern

#match anything that's not lowercase alphanumeric (will be stripped, replace with '-')
NON_ALPHANUM_PATTERN = /[^a-z0-9]+/
# Changed to allow dots
NON_ALPHANUM_PATTERN = /[^a-z0-9\.]+/

#length of hash suffix
HASH_LENGTH = 8
Expand Down
24 changes: 18 additions & 6 deletions spec/job/adapters/kubernetes/slug_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,28 @@

{
"preserves valid names" => ["jupyter-alex", "jupyter-alex"],
"converts uppercase to lowercase" => ["jupyter-Alex", "jupyter-alex---3a1c285c"],
"removes unicode characters" => ["jupyter-üni", "jupyter-ni---a5aaf5dd"]
"converts uppercase to lowercase" => ["jupyter-Alex", "jupyter-alex"],
"removes unicode characters" => ["jupyter-üni", "jupyter-ni---a5aaf5dd"],
"preserves dots in usernames" => ["john.doe", "john.doe"],
"handles multiple dots" => ["user.name.with.dots", "user.name.with.dots"],
"removes leading and trailing dots" => [".user.name.", "user.name"],
"handles mixture of dots and hyphens" => ["user.name-with-hyphens.and.dots", "user.name-with-hyphens.and.dots"],
"handles long names with dots" => ["very.long.user.name.that.exceeds.the.maximum.length", nil]
}.each do |description, (input, expected)|
it description do
expect(subject).to eq(expected)
result = subject
if expected.nil?
puts "For input '#{input}', the output is: #{result}"
expect(result).to match(/^very\.long\.user\.name\.that\.exceeds\.the\.maximum\.length---[a-f0-9]{8}$/)
else
expect(result).to eq(expected)
end
end
end

it "ensures slug doesn't end with '-'" do
expect(described_class.safe_slug("jupyter-")).not_to end_with('-')
it "ensures slug doesn't end with '-' or '.'" do
expect(described_class.safe_slug("jupyter-")).not_to end_with('-', '.')
expect(described_class.safe_slug("jupyter.")).not_to end_with('-', '.')
end
end
end
end