Fix job encode decode

This commit is contained in:
bel
2020-03-15 16:13:44 +00:00
parent 2efb0bfcf3
commit f4016da220
21 changed files with 232 additions and 41 deletions

24
scheduler/job_test.go Normal file → Executable file
View File

@@ -3,9 +3,12 @@ package scheduler
import (
"bytes"
"io/ioutil"
"local/firestormy/config"
"local/logb"
"local/storage"
"os"
"testing"
"time"
)
func TestNewBashJobBadCron(t *testing.T) {
@@ -16,6 +19,7 @@ func TestNewBashJobBadCron(t *testing.T) {
}
func TestNewBashJobAndRun(t *testing.T) {
config.Store = storage.NewMap()
cases := []struct {
sched string
cmd string
@@ -45,12 +49,7 @@ func TestNewBashJobAndRun(t *testing.T) {
t.Error(err)
continue
}
func() {
defer func() {
recover()
}()
j.Run()
}()
j.Run()
if !bytes.Contains(b.Bytes(), []byte(c.out)) {
t.Errorf("(%s, %s) => %s", c.sched, c.cmd, b.Bytes())
}
@@ -58,6 +57,7 @@ func TestNewBashJobAndRun(t *testing.T) {
}
func TestJobEncodeDecode(t *testing.T) {
config.Store = storage.NewMap()
buff, clean := captureLog()
defer clean()
@@ -89,6 +89,18 @@ func TestJobEncodeDecode(t *testing.T) {
if k.Name != j.Name {
t.Error(k.Name, "vs", j.Name)
}
if diff := k.LastRun.Unix() - j.LastRun.Unix(); (diff > 0 && diff < int64(time.Hour)) || (diff < 0 && -1*diff < int64(time.Hour)) {
t.Error(j.LastRun, "vs", k.LastRun)
}
if k.LastStatus != j.LastStatus {
t.Error(j.LastStatus, "vs", k.LastStatus)
}
if k.LastRuntime != j.LastRuntime {
t.Error(j.LastRuntime, "vs", k.LastRuntime)
}
if string(k.LastOutput) != string(j.LastOutput) {
t.Error(j.LastOutput, "vs", k.LastOutput)
}
k.foo()
if !bytes.Contains(buff.Bytes(), []byte(os.Getenv("HOSTNAME"))) {