Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Bob
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSS
Bob
Commits
9bc97743
Verified
Commit
9bc97743
authored
1 year ago
by
Volker Schukai
Browse files
Options
Downloads
Patches
Plain Diff
fix: prepare command
parent
5426dbfd
No related branches found
No related tags found
No related merge requests found
Changes
22
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
source/util/id_test.go
+93
-0
93 additions, 0 deletions
source/util/id_test.go
treefmt.toml
+34
-0
34 additions, 0 deletions
treefmt.toml
with
127 additions
and
0 deletions
source/util/id_test.go
0 → 100644
+
93
−
0
View file @
9bc97743
package
util
import
(
"regexp"
"strconv"
"testing"
)
func
TestNewSecret
(
t
*
testing
.
T
)
{
secret
,
err
:=
NewSecret
()
if
err
!=
nil
{
t
.
Errorf
(
"Error creating new secret: %v"
,
err
)
}
if
len
(
secret
)
==
0
{
t
.
Error
(
"Generated secret is empty"
)
}
}
func
TestNewSecretWithLength
(
t
*
testing
.
T
)
{
length
:=
10
secret
,
err
:=
NewSecretWithLength
(
length
)
if
err
!=
nil
{
t
.
Errorf
(
"Error creating new secret with length %d: %v"
,
length
,
err
)
}
if
len
(
secret
)
!=
length
{
t
.
Errorf
(
"Generated secret length expected to be %d, got %d"
,
length
,
len
(
secret
))
}
}
func
TestRandomString
(
t
*
testing
.
T
)
{
length
:=
10
str
,
err
:=
RandomString
(
length
)
if
err
!=
nil
{
t
.
Errorf
(
"Error generating random string: %v"
,
err
)
}
if
len
(
str
)
!=
length
{
t
.
Errorf
(
"Random string length expected to be %d, got %d"
,
length
,
len
(
str
))
}
}
func
TestCryptID
(
t
*
testing
.
T
)
{
input
:=
"testString"
length
:=
8
encrypted
,
err
:=
cryptID
(
input
,
length
)
if
err
!=
nil
{
t
.
Errorf
(
"Error encrypting string: %v"
,
err
)
}
if
len
(
encrypted
)
!=
length
{
t
.
Errorf
(
"Encrypted string length expected to be %d, got %d"
,
length
,
len
(
encrypted
))
}
}
func
TestHashString
(
t
*
testing
.
T
)
{
input
:=
"testString"
hashed
:=
hashString
(
input
)
if
_
,
err
:=
strconv
.
Atoi
(
hashed
);
err
!=
nil
{
t
.
Errorf
(
"Hashed string is not a valid number: %s"
,
hashed
)
}
}
func
TestBuildTextKey
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
input
string
expectedRegex
string
}{
{
"Test Key"
,
"^test-key$"
},
{
""
,
"^$"
},
{
"ThisIsALongTextKeyThatExceedsTheLimit"
,
"^this-is-along-text-k-[0-9]+$"
},
{
"MixedCaseInput"
,
"^mixed-case-input$"
},
{
"With Spaces"
,
"^with-spaces$"
},
{
"123Numbers456"
,
"^123numbers456$"
},
{
"Special#Characters!"
,
"^special-characters$"
},
{
"Short"
,
"^short$"
},
{
"LongerThanTwentyCharactersInputString"
,
"^longer-than-twenty-c-[0-9]+$"
},
{
"-StartsInDash"
,
"^starts-in-dash$"
},
{
"EndsInDash-"
,
"^ends-in-dash$"
},
{
"With--Multiple--Dashes"
,
"^with-multiple-dashes$"
},
{
"EndsInDash-"
,
"^ends-in-dash$"
},
{
"-StartsInDash"
,
"^starts-in-dash$"
},
{
"Emojis🚀AreCool"
,
"^emojis-are-cool$"
},
}
for
_
,
test
:=
range
tests
{
output
,
err
:=
BuildTextKey
(
test
.
input
)
if
err
!=
nil
{
t
.
Errorf
(
"Error building text key for input '%s': %v"
,
test
.
input
,
err
)
}
matched
,
_
:=
regexp
.
MatchString
(
test
.
expectedRegex
,
output
)
if
!
matched
{
t
.
Errorf
(
"Output '%s' does not match expected regex '%s' for input '%s'"
,
output
,
test
.
expectedRegex
,
test
.
input
)
}
}
}
This diff is collapsed.
Click to expand it.
treefmt.toml
0 → 100644
+
34
−
0
View file @
9bc97743
# One CLI to format the code tree - https://github.com/numtide/treefmt
[formatter.nix]
command
=
"nixfmt"
options
=
[]
includes
=
[
"*.nix"
]
excludes
=
[]
[formatter.go]
command
=
"gofmt"
options
=
[]
includes
=
[
"*.go"
]
excludes
=
[]
[formatter.shell]
command
=
"shfmt"
options
=
[
"-i"
,
"2"
,
"-ci"
]
includes
=
[
"*.sh"
]
excludes
=
[]
[formatter.yaml]
command
=
"yq"
options
=
[
"eval"
,
"-P"
]
includes
=
[
"*.yaml"
,
"*.yml"
]
excludes
=
[]
[formatter.json]
command
=
"jq"
options
=
[
"."
]
includes
=
[
"*.json"
]
excludes
=
[]
[formatter.toml]
command
=
"tomlfmt"
options
=
[]
includes
=
[
"*.toml"
]
excludes
=
[]
This diff is collapsed.
Click to expand it.
Prev
1
2
Next
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment