Skip to content
Snippets Groups Projects
Verified Commit 9bc97743 authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

fix: prepare command

parent 5426dbfd
No related branches found
No related tags found
No related merge requests found
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)
}
}
}
# 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 = []
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment