41 lines
858 B
Go
41 lines
858 B
Go
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)
|
|
}
|
|
}
|
|
}
|