added crons web apis and ui listing

This commit is contained in:
Gani Georgiev
2024-12-25 22:24:24 +02:00
parent ed1917b307
commit 56f951e5a2
46 changed files with 692 additions and 270 deletions

View File

@@ -1,6 +1,9 @@
package cron
import "testing"
import (
"encoding/json"
"testing"
)
func TestJobId(t *testing.T) {
expected := "test"
@@ -22,8 +25,8 @@ func TestJobExpr(t *testing.T) {
j := Job{schedule: s}
if j.Expr() != expected {
t.Fatalf("Expected job with cron expression %q, got %q", expected, j.Expr())
if j.Expression() != expected {
t.Fatalf("Expected job with cron expression %q, got %q", expected, j.Expression())
}
}
@@ -47,3 +50,22 @@ func TestJobRun(t *testing.T) {
t.Fatalf("Expected calls %q, got %q", expected, calls)
}
}
func TestJobMarshalJSON(t *testing.T) {
s, err := NewSchedule("1 2 3 4 5")
if err != nil {
t.Fatal(err)
}
j := Job{id: "test_id", schedule: s}
raw, err := json.Marshal(j)
if err != nil {
t.Fatal(err)
}
expected := `{"id":"test_id","expression":"1 2 3 4 5"}`
if str := string(raw); str != expected {
t.Fatalf("Expected\n%s\ngot\n%s", expected, str)
}
}