func addOneJob(jobstore entities.JobStore) int { id := jobstore.AssignFreeId() c := make(<-chan entities.StatusMsg) job := entities.CreateJob(id, c) jobstore.AddJob(job) return id }
func TestEdit(t *testing.T) { jobstore := NewJobStore() id := jobstore.AssignFreeId() c := make(<-chan entities.StatusMsg) job := entities.CreateJob(id, c) jobstore.AddJob(job) outjob, _ := jobstore.GetJob(id) if outjob.Status != "Starting" { t.Error("Status before editing should have been 'Starting' but was", outjob.Status) } outjob.Status = "Done" jobstore.Replace(id, outjob) editedjob, _ := jobstore.GetJob(id) if editedjob.Status != "Done" { t.Error("Status after editing should have been 'Done' but was", outjob.Status) } }
func TestTotalCount(t *testing.T) { jobstore := storage.NewJobStore() InjectStorageReporter(&jobstore) stored := TotalCount() if stored != 0 { t.Error("Newly-created JobStore should have total count of 0 but was", stored) } id := jobstore.AssignFreeId() c := make(<-chan entities.StatusMsg) job := entities.CreateJob(id, c) jobstore.AddJob(job) stored = TotalCount() if stored != 1 { t.Error("Newly-created JobStore should have total count of 0 but was", stored) } job.Status = "Done" jobstore.Replace(id, job) stored = jobstore.TotalCount() if stored != 1 { t.Error("Newly-created JobStore should still have total count of 1 but was", stored) } }
func TestAdd(t *testing.T) { jobstore := NewJobStore() id := jobstore.AssignFreeId() _, ok := jobstore.GetJob(id) if ok { t.Error("Getting an ID before adding something to it should not have been OK") } c := make(<-chan entities.StatusMsg) job := entities.CreateJob(id, c) jobstore.AddJob(job) outjob, ok := jobstore.GetJob(id) if !ok { t.Error("Getting an ID after adding something to it should have been OK") } if outjob != job { t.Error("Was supposed to get the same job from jobstore but didn't") } }