1
0
out-of-tree/daemon/db/job_test.go

51 lines
830 B
Go
Raw Normal View History

2024-02-20 13:25:31 +00:00
package db
import (
"os"
"testing"
2024-02-26 08:55:27 +00:00
"github.com/google/uuid"
2024-02-20 13:25:31 +00:00
"github.com/stretchr/testify/assert"
"code.dumpstack.io/tools/out-of-tree/api"
)
func TestJobTable(t *testing.T) {
2024-02-26 08:55:27 +00:00
file, db := tmpdb(t)
2024-02-20 13:25:31 +00:00
defer os.Remove(file.Name())
2024-02-26 08:55:27 +00:00
defer db.Close()
2024-02-20 13:25:31 +00:00
job := api.Job{
RepoName: "testname",
Commit: "test",
2024-02-26 08:55:27 +00:00
Group: uuid.New().String(),
2024-02-20 13:25:31 +00:00
}
err := AddJob(db, &job)
assert.Nil(t, err)
2024-02-26 08:55:27 +00:00
job.Group = uuid.New().String()
2024-02-20 13:25:31 +00:00
2024-02-27 02:00:07 +00:00
job.Status = api.StatusSuccess
2024-02-26 08:55:27 +00:00
err = UpdateJob(db, &job)
2024-02-20 13:25:31 +00:00
assert.Nil(t, err)
jobs, err := Jobs(db, "")
2024-02-20 13:25:31 +00:00
assert.Nil(t, err)
assert.Equal(t, 1, len(jobs))
2024-02-26 08:55:27 +00:00
assert.Equal(t, job.Group, jobs[0].Group)
2024-02-27 02:00:07 +00:00
job, err = Job(db, job.UUID)
assert.Nil(t, err)
assert.Equal(t, api.StatusSuccess, job.Status)
st, err := JobStatus(db, job.UUID)
assert.Nil(t, err)
assert.Equal(t, job.Status, st)
2024-02-20 13:25:31 +00:00
}