pttodo/pttodo/schedule_test.go

48 lines
867 B
Go

package pttodo
import (
"bytes"
"encoding/json"
"testing"
)
func TestJSONSchedule(t *testing.T) {
cases := map[string]struct {
input string
wantMarshalled string
}{
"cron": {
input: "* * * * *",
wantMarshalled: `"* * * * *"`,
},
"int": {
input: "123",
wantMarshalled: `"123"`,
},
"duration": {
input: "1h",
wantMarshalled: `"1h"`,
},
}
for name, d := range cases {
c := d
t.Run(name, func(t *testing.T) {
gotMarshalled, err := json.Marshal(Schedule(c.input))
if err != nil {
t.Fatal(err)
}
if !bytes.Equal([]byte(c.wantMarshalled), gotMarshalled) {
t.Fatal(c.wantMarshalled, gotMarshalled)
}
var got Schedule
if err := json.Unmarshal(gotMarshalled, &got); err != nil {
t.Fatal(err)
}
if string(got) != c.input {
t.Fatal(got)
}
})
}
}