plakken/utils_test.go

44 lines
1.4 KiB
Go
Raw Normal View History

2023-12-28 00:02:50 +01:00
package main
import "testing"
func TestParseExpirationFull(t *testing.T) { // test parseExpirationFull with all valid separator
2023-12-28 13:01:21 +01:00
result, _ := ParseExpiration("2d1h3m47s")
2023-12-28 00:02:50 +01:00
correctValue := 176627
if result != correctValue {
t.Fatal("Error in parseExpirationFull, want : ", correctValue, "got : ", result)
}
}
func TestParseExpirationMissing(t *testing.T) { // test parseExpirationFull with all valid separator
2023-12-28 13:01:21 +01:00
result, _ := ParseExpiration("1h47s")
2023-12-28 00:02:50 +01:00
correctValue := 3647
if result != correctValue {
2023-12-28 13:22:57 +01:00
t.Fatal("Error in ParseExpirationFull, want : ", correctValue, "got : ", result)
2023-12-28 00:02:50 +01:00
}
}
2023-12-28 13:22:57 +01:00
func TestParseExpirationNull(t *testing.T) { // test ParseExpirationFull with all valid separator
2023-12-28 13:01:21 +01:00
result, _ := ParseExpiration("0")
2023-12-28 00:02:50 +01:00
correctValue := 0
if result != correctValue {
2023-12-28 13:22:57 +01:00
t.Fatal("Error in ParseExpirationFull, want : ", correctValue, "got : ", result)
2023-12-28 00:02:50 +01:00
}
}
2023-12-28 13:22:57 +01:00
func TestParseExpirationNegative(t *testing.T) { // test ParseExpirationFull with all valid separator
2023-12-28 13:01:21 +01:00
result, _ := ParseExpiration("-42h1m4s")
2023-12-28 00:02:50 +01:00
correctValue := -1
if result != correctValue {
2023-12-28 13:22:57 +01:00
t.Fatal("Error in ParseExpirationFull, want : ", correctValue, "got : ", result)
2023-12-28 00:02:50 +01:00
}
}
2023-12-28 13:22:57 +01:00
func TestParseExpirationInvalid(t *testing.T) { // test ParseExpirationFull with all valid separator
2023-12-28 13:01:21 +01:00
result, _ := ParseExpiration("8h42h1m1d4s")
2023-12-28 00:02:50 +01:00
correctValue := -1
if result != correctValue {
2023-12-28 13:22:57 +01:00
t.Fatal("Error in ParseExpirationFull, want : ", correctValue, "got : ", result)
2023-12-28 00:02:50 +01:00
}
}