cml04-gdm-int/internal/helpers/helper_test.go

41 lines
858 B
Go
Raw Permalink Normal View History

2024-08-20 10:09:47 +02:00
package helpers
import (
"testing"
"time"
)
func TestCleanString(t *testing.T) {
tests := []struct {
input string
expected string
}{
{"hello123", "hello123"},
{"_hello_123_", "hello123"},
{"!@#$%^hello&*()123", "hello123"},
{"", ""},
}
for _, test := range tests {
result := CleanString(test.input)
if result != test.expected {
t.Errorf("Input: %s, Expected: %s, Got: %s", test.input, test.expected, result)
}
}
}
func TestHeaderTimeStamp(t *testing.T) {
// Stub the current time for testing purposes
// Fixed time for consistent results
now := time.Date(2024, 2, 20, 12, 30, 45, 0, time.UTC)
expectedTimeStamp := [8]int16{20, 24, 2, 20, 12, 30, 45, 0}
result := HeaderTimeStamp(now)
for i, v := range result {
if v != expectedTimeStamp[i] {
t.Errorf("Expected: %d, Got: %d", expectedTimeStamp[i], v)
}
}
}