[🤖] Add Unit-Tests
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m34s

This commit is contained in:
2026-04-27 10:46:08 +02:00
parent dad0e3240d
commit 02d6894ec6
116 changed files with 18795 additions and 1 deletions
+54
View File
@@ -0,0 +1,54 @@
package cryptext
import (
"git.blackforestbytes.com/BlackForestBytes/goext/tst"
"strings"
"testing"
)
func TestStrSha256SameAsBytesSha256(t *testing.T) {
inputs := []string{"", "a", "Hello World", "lorem ipsum dolor sit amet", "🎉 unicode"}
for _, in := range inputs {
tst.AssertEqual(t, StrSha256(in), BytesSha256([]byte(in)))
}
}
func TestStrSha256Length(t *testing.T) {
// SHA-256 hex output must always be 64 characters
tst.AssertEqual(t, len(StrSha256("")), 64)
tst.AssertEqual(t, len(StrSha256("x")), 64)
tst.AssertEqual(t, len(StrSha256(strings.Repeat("x", 10000))), 64)
}
func TestStrSha256Deterministic(t *testing.T) {
v := "deterministic input"
a := StrSha256(v)
b := StrSha256(v)
tst.AssertEqual(t, a, b)
}
func TestStrSha256DifferentInputs(t *testing.T) {
tst.AssertNotEqual(t, StrSha256("a"), StrSha256("b"))
tst.AssertNotEqual(t, StrSha256("Hello"), StrSha256("hello"))
tst.AssertNotEqual(t, StrSha256("Hello World"), StrSha256("Hello World "))
}
func TestStrSha256IsHex(t *testing.T) {
out := StrSha256("anything")
for _, c := range out {
isLowerHex := (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f')
if !isLowerHex {
t.Errorf("non-hex char %q in StrSha256 output", c)
return
}
}
}
func TestBytesSha256NilSameAsEmpty(t *testing.T) {
tst.AssertEqual(t, BytesSha256(nil), BytesSha256([]byte{}))
}
func TestBytesSha256KnownVectors(t *testing.T) {
// "abc" => sha-256 standard vector
tst.AssertEqual(t, StrSha256("abc"), "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad")
}