52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package utils
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestMd5str(t *testing.T) {
|
|
tests := []struct {
|
|
input string
|
|
expected string
|
|
}{
|
|
{"hello", "5d41402abc4b2a76b9719d911017c592"},
|
|
{"", "d41d8cd98f00b204e9800998ecf8427e"},
|
|
{"http://example.com/stream", "a1b2c3d4e5f6"}, // just length check
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.input, func(t *testing.T) {
|
|
got := Md5str(tt.input)
|
|
if len(got) != 32 {
|
|
t.Errorf("Md5str(%q) length = %d, want 32", tt.input, len(got))
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestArrayUnique(t *testing.T) {
|
|
input := []string{"a", "b", "a", "c", "b"}
|
|
expected := []string{"a", "b", "c"}
|
|
got := ArrayUnique(input)
|
|
if len(got) != len(expected) {
|
|
t.Errorf("ArrayUnique length = %d, want %d", len(got), len(expected))
|
|
}
|
|
seen := make(map[string]bool)
|
|
for _, v := range got {
|
|
if seen[v] {
|
|
t.Errorf("ArrayUnique returned duplicate: %s", v)
|
|
}
|
|
seen[v] = true
|
|
}
|
|
}
|
|
|
|
func TestExpandPath(t *testing.T) {
|
|
got, err := ExpandPath("/tmp/test.txt")
|
|
if err != nil {
|
|
t.Fatalf("ExpandPath error: %v", err)
|
|
}
|
|
if got == "" {
|
|
t.Error("ExpandPath returned empty string")
|
|
}
|
|
}
|