Beispiel #1
0
func testJobs(s datastore.DataStore, t *testing.T) {
	// Test only valid RemoteIDs are accepted
	j := model.Job{JobName: "foo", RemoteID: 0}
	created, err := s.SaveJob(&j)
	assert.NotNil(t, err)

	r := model.Remote{Driver: "ssh", Location: "foo"}
	created, err = s.SaveRemote(&r)
	r2 := model.Remote{Driver: "ssh", Location: "bar"}
	created, err = s.SaveRemote(&r2)

	j = model.Job{JobName: "foo", RemoteID: r.ID}
	created, err = s.SaveJob(&j)
	assert.Equal(t, true, created)
	assert.Nil(t, err)

	j2, err := s.Job(j.ID)
	assert.Nil(t, err)
	assert.Equal(t, j.JobName, j2.JobName)
	assert.Equal(t, j.ID, j2.ID)

	j2.JobName = "bar"
	created, err = s.SaveJob(&j2)
	assert.Equal(t, false, created)
	assert.Nil(t, err)

	jslice, err := s.Jobs()
	assert.Nil(t, err)
	assert.Equal(t, 1, len(jslice))
	assert.Equal(t, j2.JobName, jslice[0].JobName)
	assert.Equal(t, j2.ID, jslice[0].ID)

	jslice, err = s.JobsForRemote(&r)
	assert.Nil(t, err)
	assert.Equal(t, 1, len(jslice))

	jslice, err = s.JobsForRemote(&r2)
	assert.Nil(t, err)
	assert.Equal(t, 0, len(jslice))

	s.DeleteJob(&j2)

	jslice, err = s.Jobs()
	assert.Nil(t, err)
	assert.Equal(t, 0, len(jslice))

	_, err = s.Job(j.ID)
	assert.NotNil(t, err)

	s.DeleteRemote(&r)
	s.DeleteRemote(&r2)
}