150 lines
4.6 KiB
Go
150 lines
4.6 KiB
Go
package tools
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestHello(t *testing.T) {
|
|
testcases := []struct {
|
|
testcase string
|
|
valid bool
|
|
}{
|
|
{testcase: "2023-11-09T15:02:17+00:00-CH-stock.csv", valid: true},
|
|
{testcase: "2023-11-09T15:02:17+00:00-DE-delivery.csv", valid: true},
|
|
{testcase: "2023-11-09T15:02:17+00:00-EU-stock.csv", valid: true},
|
|
{testcase: "2023-11-09T15:02:17+00:00-AT-stock.csv", valid: true},
|
|
}
|
|
|
|
//"2023-11-09T15:02:17+00:00-CH-stock.csv"
|
|
|
|
for i, tc := range testcases {
|
|
result := IsFilenameValid(tc.testcase)
|
|
if result != tc.valid {
|
|
t.Errorf("Testcase %d is not valid, but %s must be valid!", i, tc.testcase)
|
|
}
|
|
}
|
|
}
|
|
func TestValidTimeZonesWith30(t *testing.T) {
|
|
testcases := []struct {
|
|
testcase string
|
|
valid bool
|
|
}{
|
|
{testcase: "2023-11-09T15:02:17+03:30-EU-stock.csv", valid: true},
|
|
{testcase: "2023-11-09T15:02:17+04:30-DE-stock.csv", valid: true},
|
|
{testcase: "2023-11-09T15:02:17+05:30-DE-stock.csv", valid: true},
|
|
{testcase: "2023-11-09T15:02:17+06:30-CH-delivery.csv", valid: true},
|
|
{testcase: "2023-11-09T15:02:17+09:30-CH-stock.csv", valid: true},
|
|
{testcase: "2023-11-09T15:02:17+10:30-AT-stock.csv", valid: true},
|
|
}
|
|
|
|
for i, tc := range testcases {
|
|
result := IsFilenameValid(tc.testcase)
|
|
if result != tc.valid {
|
|
t.Errorf("Testcase %d is not valid, but %s must be valid!", i, tc.testcase)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestValidDateTime(t *testing.T) {
|
|
testcases := []struct {
|
|
testcase string
|
|
valid bool
|
|
}{
|
|
{testcase: "2025-11-29T23:02:17+03:30-EU-stock.csv", valid: true},
|
|
{testcase: "2023-11-09T15:02:17+04:30-DE-stock.csv", valid: true},
|
|
{testcase: "2023-11-09T15:02:17+05:30-DE-stock.csv", valid: true},
|
|
{testcase: "2023-11-09T15:02:17+06:30-CH-delivery.csv", valid: true},
|
|
{testcase: "2023-11-09T15:02:17+09:30-CH-stock.csv", valid: true},
|
|
{testcase: "2023-11-09T15:02:17+10:30-AT-delivery.csv", valid: true},
|
|
}
|
|
|
|
for i, tc := range testcases {
|
|
result := IsFilenameValid(tc.testcase)
|
|
if result != tc.valid {
|
|
t.Errorf("Testcase %d is not valid, but %s must be valid!", i, tc.testcase)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestInValidTimeZonesWith30(t *testing.T) {
|
|
testcases := []struct {
|
|
testcase string
|
|
valid bool
|
|
}{
|
|
{testcase: "2023-11-09T15:02:17+02:30-EU-stock.csv", valid: false},
|
|
{testcase: "2023-11-09T15:02:17+01:30-DE-stock.csv", valid: false},
|
|
{testcase: "2023-11-09T15:02:17+23:30-DE-stock.csv", valid: false},
|
|
{testcase: "2023-11-09T15:02:17+07:30-CH-stock.csv", valid: false},
|
|
{testcase: "2023-11-09T15:02:17+08:30-CH-stock.csv", valid: false},
|
|
{testcase: "2023-11-09T15:02:17+12:30-AT-stock.csv", valid: false},
|
|
}
|
|
|
|
for i, tc := range testcases {
|
|
result := IsFilenameValid(tc.testcase)
|
|
if result != tc.valid {
|
|
t.Errorf("Testcase %d is not valid, but %s must be valid!", i, tc.testcase)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestInValidDateTimeWith(t *testing.T) {
|
|
testcases := []struct {
|
|
testcase string
|
|
valid bool
|
|
}{
|
|
{testcase: "2000-11-03T15:02:17+00:00-EU-stock.csv", valid: false},
|
|
{testcase: "2026-11-03T15:60:17+00:00-EU-stock.csv", valid: false},
|
|
{testcase: "2025-00-03T15:20:17+00:00-EU-stock.csv", valid: false},
|
|
{testcase: "2100-01-03T23:59:17+00:00-EU-stock.csv", valid: false},
|
|
{testcase: "2027-2-03T15:20:17+00:00-EU-stock.csv", valid: false},
|
|
{testcase: "2023-11-09T15:02:51+00:01-AT-stock.csv", valid: false},
|
|
}
|
|
|
|
for i, tc := range testcases {
|
|
result := IsFilenameValid(tc.testcase)
|
|
if result != tc.valid {
|
|
t.Errorf("Testcase %d is not valid, but %s must be valid!", i, tc.testcase)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestValidRFC3339StringToTime(t *testing.T) {
|
|
testcases := []struct {
|
|
testcase string
|
|
valid bool
|
|
}{
|
|
{testcase: "2000-11-03T15:02:17+00:00", valid: true},
|
|
{testcase: "2026-11-03T15:02:17+03:30", valid: true},
|
|
{testcase: "2026-12-03T23:02:17+05:30", valid: true},
|
|
{testcase: "2026-11-03T15:02:17-12:00", valid: true},
|
|
{testcase: "2026-11-03T23:59:17+14:00", valid: true},
|
|
}
|
|
|
|
for i, tc := range testcases {
|
|
result, err := RFC3339StringToTime(tc.testcase)
|
|
if err != nil || tc.valid == false {
|
|
t.Errorf("Testcase %d is not valid, but %s must be valid!", i, result)
|
|
}
|
|
}
|
|
|
|
}
|
|
func TestInValidRFC3339StringToTime(t *testing.T) {
|
|
testcases := []struct {
|
|
testcase string
|
|
invalid bool
|
|
}{
|
|
{testcase: "2026-13-03T23:02:17+05:30", invalid: true},
|
|
{testcase: "2026-00-03T23:02:17+05:30", invalid: true},
|
|
{testcase: "2026-03-03T23:02:17+99:30", invalid: true},
|
|
{testcase: "2026-03-03T23:02:17+99:00", invalid: true},
|
|
{testcase: "2026-03-03T23:02:17+16:00", invalid: true},
|
|
}
|
|
|
|
for i, tc := range testcases {
|
|
result, err := RFC3339StringToTime(tc.testcase)
|
|
if err == nil && tc.invalid {
|
|
t.Errorf("Testcase %d is valid, but %s must be invalid!", i, result.String())
|
|
}
|
|
}
|
|
}
|