func TestNewJob(t *testing.T) {
	mock := upload.NewMock()
	InjectUploader(mock)
	store := storage.NewJobStore()
	InjectJobstore(&store)

	err := MakeGrayFile(1000, 1000, "/tmp/upload.png")
	if err != nil {
		t.Error("Error in creating test file")
	}
	defer os.Remove("/tmp/upload.png")

	req := JobRequest{
		"/tmp/upload.png",
		image.Rect(200, 200, 200, 200),
		0, 150,
		"test.png",
	}

	jobid := NewJob(req)
	if jobid != 0 {
		t.Errorf("Expected jobid to be %d but was %d\n", 0, jobid)
	}

}
Example #2
0
func injectDependencies() {
	uploader := upload.NewAmazonS3Upload(s3accesskey, s3secretkey, s3bucketname)
	core.InjectUploader(uploader)

	store := storage.NewJobStore()
	core.InjectJobstore(&store)
	core.InjectStorageReporter(&store)
}
func TestAllWithSetup(t *testing.T) {
	go StartWebServer(portnum)
	time.Sleep(50 * time.Millisecond)
	mock = upload.NewMock()
	core.InjectUploader(mock)
	store := storage.NewJobStore()
	core.InjectJobstore(&store)
	core.InjectStorageReporter(&store)
	err := MakeGrayFile(1000, 1000, "/tmp/upload.gif")
	if err != nil {
		t.Error("Error in creating test file")
	}
	defer os.Remove("/tmp/upload.gif")

	testStartWebserver(t)
	testStatusOfBadJob(t)
	testRequestingNewJob(t)
	testStatusOfExistingJob(t)
	testStatsReturnsJSON(t)
}
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)
	}
}