[🤖] 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
+43
View File
@@ -0,0 +1,43 @@
package langext
import (
"git.blackforestbytes.com/BlackForestBytes/goext/tst"
"testing"
)
func TestDeepCopyByJsonStruct(t *testing.T) {
type item struct {
Name string `json:"name"`
Age int `json:"age"`
}
src := item{Name: "alice", Age: 30}
dst, err := DeepCopyByJson(src)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
tst.AssertEqual(t, dst.Name, "alice")
tst.AssertEqual(t, dst.Age, 30)
}
func TestDeepCopyByJsonSlice(t *testing.T) {
src := []int{1, 2, 3}
dst, err := DeepCopyByJson(src)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
tst.AssertArrayEqual(t, dst, []int{1, 2, 3})
// Mutating the copy must not affect the source
dst[0] = 99
tst.AssertEqual(t, src[0], 1)
}
func TestDeepCopyByJsonError(t *testing.T) {
type bad struct {
C chan int
}
_, err := DeepCopyByJson(bad{C: make(chan int)})
if err == nil {
t.Errorf("expected error for un-marshalable type")
}
}