Tests: Add unit tests for pkg/clean

This commit is contained in:
graciousgrey 2023-06-26 15:57:56 +02:00
parent 186d1f26e7
commit 1e55e5b1d9
10 changed files with 78 additions and 0 deletions

View file

@ -25,6 +25,12 @@ func TestHandle(t *testing.T) {
t.Run("Windows", func(t *testing.T) {
assert.Equal(t, "jens.mander", Handle("DOMAIN\\Jens Mander "))
})
t.Run("Empty", func(t *testing.T) {
assert.Equal(t, "", Handle(" "))
})
t.Run("control character", func(t *testing.T) {
assert.Equal(t, "admin!", Handle("admin!"+string(rune(1))))
})
}
func TestUsername(t *testing.T) {
@ -46,6 +52,12 @@ func TestUsername(t *testing.T) {
t.Run("Windows", func(t *testing.T) {
assert.Equal(t, "domain\\jens mander", Username("DOMAIN\\Jens Mander "))
})
t.Run("Empty", func(t *testing.T) {
assert.Equal(t, "", Username(" "))
})
t.Run("control character", func(t *testing.T) {
assert.Equal(t, "admin!", Username("admin!"+string(rune(1))))
})
}
func TestEmail(t *testing.T) {
@ -58,6 +70,9 @@ func TestEmail(t *testing.T) {
t.Run("Invalid", func(t *testing.T) {
assert.Equal(t, "", Email(" hello-photoprism "))
})
t.Run("Empty", func(t *testing.T) {
assert.Equal(t, "", Email(""))
})
}
func TestRole(t *testing.T) {
@ -70,6 +85,12 @@ func TestRole(t *testing.T) {
t.Run(" admin ", func(t *testing.T) {
assert.Equal(t, "admin", Role(" admin "))
})
t.Run("adm}in", func(t *testing.T) {
assert.Equal(t, "admin", Role("adm}in"))
})
t.Run("Empty", func(t *testing.T) {
assert.Equal(t, "", Role(""))
})
}
func TestFlags(t *testing.T) {

View file

@ -25,4 +25,7 @@ func TestCodec(t *testing.T) {
t.Run("Quotes", func(t *testing.T) {
assert.Equal(t, "fooBaaar23", Codec("\"foo\" Baa'ar 2```3"))
})
t.Run("Empty", func(t *testing.T) {
assert.Equal(t, "", Codec(""))
})
}

View file

@ -34,4 +34,10 @@ func TestFileName(t *testing.T) {
t.Run("Replace", func(t *testing.T) {
assert.Equal(t, "", FileName("${https://<host>:<port>/<path>}"))
})
t.Run("file?name.jpg", func(t *testing.T) {
assert.Equal(t, "filename.jpg", FileName("file?name.jpg"))
})
t.Run("Control Character", func(t *testing.T) {
assert.Equal(t, "filename.", FileName("filename."+string(rune(127))))
})
}

View file

@ -16,4 +16,7 @@ func TestHex(t *testing.T) {
t.Run("SHA1", func(t *testing.T) {
assert.Equal(t, "5c50ae14f339364eb8224f23c2d3abc7e79016f3eaded", Hex("5c50ae14f339364eb8224f23c2d3abc7e79016f3 README.md"))
})
t.Run("Empty", func(t *testing.T) {
assert.Equal(t, "", Hex(""))
})
}

View file

@ -44,3 +44,12 @@ func TestLogLower(t *testing.T) {
assert.Equal(t, "?", LogLower("User-Agent: ${jndi:ldap://<host>:<port>/<path>}"))
})
}
func TestLogQuote(t *testing.T) {
t.Run("The quick brown fox.", func(t *testing.T) {
assert.Equal(t, "'The quick brown fox.'", LogQuote("The quick brown fox."))
})
t.Run("SpecialChars", func(t *testing.T) {
assert.Equal(t, "'?The quick brown fox'", LogQuote("$The quick brown fox"))
})
}

View file

@ -28,6 +28,12 @@ func TestName(t *testing.T) {
t.Run("Chinese", func(t *testing.T) {
assert.Equal(t, "陈 赵", Name(" 陈 赵"))
})
t.Run("Control Character", func(t *testing.T) {
assert.Equal(t, "William Henry Gates III", Name("William Henry Gates III"+string(rune(1))))
})
t.Run("Space", func(t *testing.T) {
assert.Equal(t, "", Name(" "))
})
}
func TestNameCapitalized(t *testing.T) {

View file

@ -34,6 +34,12 @@ func TestPath(t *testing.T) {
t.Run("Replace", func(t *testing.T) {
assert.Equal(t, "", Path("${https://<host>:<port>/<path>}"))
})
t.Run("Control Character", func(t *testing.T) {
assert.Equal(t, "filename.", Path("filename."+string(rune(127))))
})
t.Run("Special Chars", func(t *testing.T) {
assert.Equal(t, "filename.", Path("filename.?**"))
})
}
func TestUserPath(t *testing.T) {

View file

@ -19,6 +19,10 @@ func TestSearchString(t *testing.T) {
q := SearchString(" Flowers in the Park ")
assert.Equal(t, " Flowers in the Park ", q)
})
t.Run("Empty", func(t *testing.T) {
q := SearchString("")
assert.Equal(t, "", q)
})
}
func TestSearchQuery(t *testing.T) {
@ -34,4 +38,8 @@ func TestSearchQuery(t *testing.T) {
q := SearchQuery(" Flowers in the Park ")
assert.Equal(t, "Flowers&the Park", q)
})
t.Run("Empty", func(t *testing.T) {
q := SearchQuery("")
assert.Equal(t, "", q)
})
}

View file

@ -62,4 +62,14 @@ func TestState(t *testing.T) {
assert.Equal(t, "", result)
})
t.Run("Control Character", func(t *testing.T) {
result := State("Washington"+string(rune(127)), "us")
assert.Equal(t, "Washington", result)
})
t.Run("Special Chars", func(t *testing.T) {
result := State("Wa?shing*ton"+string(rune(127)), "us")
assert.Equal(t, "Washington", result)
})
}

View file

@ -19,6 +19,9 @@ func TestToken(t *testing.T) {
t.Run("SHA256", func(t *testing.T) {
assert.Equal(t, "a948904f2f0f479b8f8197694b30184b0d2ed1c1cd2a1ec0fb85d299a192a447", Token("a948904f2f0f479b8f8197694b30184b0d2ed1c1cd2a1ec0fb85d299a192a447"))
})
t.Run("Empty", func(t *testing.T) {
assert.Equal(t, "", Token(""))
})
}
func TestUrlToken(t *testing.T) {
@ -52,4 +55,7 @@ func TestShareToken(t *testing.T) {
t.Run("SHA256", func(t *testing.T) {
assert.Equal(t, "a948904f2f0f479b8f8197694b30184b0d2ed1c1cd2a1ec0fb85d299a192a447", ShareToken("a948904f2f0f479b8f8197694b30184b0d2ed1c1cd2a1ec0fb85d299a192a447"))
})
t.Run("Empty", func(t *testing.T) {
assert.Equal(t, "", ShareToken(""))
})
}