Skip to content

Commit

Permalink
test(hatchery): fix test spawn worker
Browse files Browse the repository at this point in the history
Signed-off-by: francois  samin <[email protected]>
  • Loading branch information
fsamin committed Oct 26, 2021
1 parent 6ff7d51 commit ddfe9a1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 29 deletions.
23 changes: 0 additions & 23 deletions engine/api/workermodel/dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,29 +135,6 @@ func TestInsert(t *testing.T) {
assert.EqualValues(t, *src, *res)
}

func TestMergeModelEnvsWithDefaultEnvs(t *testing.T) {
db, _ := test.SetupPG(t, bootstrap.InitiliazeDB)

g := assets.InsertGroup(t, db)

m := sdk.Model{
Name: sdk.RandomString(10),
Type: sdk.Docker,
ModelDocker: sdk.ModelDocker{
Image: "foo/bar:3.4",
},
GroupID: g.ID,
}
require.NoError(t, workermodel.Insert(context.TODO(), db, &m))
require.Len(t, m.ModelDocker.Envs, 6, "all default vars should be added by insert")

m.ModelDocker.Envs = map[string]string{
"myvar": "myvalue",
}
require.NoError(t, workermodel.UpdateDB(context.TODO(), db, &m))
require.Len(t, m.ModelDocker.Envs, 7, "all default vars should be merged to given vars by update")
}

func TestLoadByNameAndGroupID(t *testing.T) {
db, _ := test.SetupPG(t, bootstrap.InitiliazeDB)

Expand Down
3 changes: 1 addition & 2 deletions engine/hatchery/marathon/marathon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,7 @@ func TestSpawnWorkerTimeout(t *testing.T) {
assert.Equal(t, "BRIDGE", a.Container.Docker.Network)
assert.Equal(t, float64(1), a.CPUs)
assert.Equal(t, 1, *a.Instances)
assert.Equal(t, "1", (*a.Env)["CDS_BOOKED_WORKFLOW_JOB_ID"])
assert.Equal(t, "GroupModel/fake", (*a.Env)["CDS_MODEL_PATH"])
assert.NotEmpty(t, (*a.Env)["CDS_CONFIG"])

createAppResult.ID = a.ID
createAppResult.Env = a.Env
Expand Down
13 changes: 9 additions & 4 deletions engine/hatchery/vsphere/spawn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ func TestHatcheryVSphere_launchScriptWorker(t *testing.T) {
c.EXPECT().StartProgramInGuest(gomock.Any(), &procman, gomock.Any()).DoAndReturn(
func(ctx context.Context, procman *guest.ProcessManager, req *types.StartProgramInGuest) (int64, error) {
assert.Equal(t, "/bin/echo", req.Spec.GetGuestProgramSpec().ProgramPath)
assert.Equal(t, "-n ;\n./worker register\nshutdown -h now", req.Spec.GetGuestProgramSpec().Arguments)
assert.Contains(t, req.Spec.GetGuestProgramSpec().Arguments, "-n ;\n")
assert.Contains(t, req.Spec.GetGuestProgramSpec().Arguments, "./worker register\nshutdown -h now")
assert.Contains(t, req.Spec.GetGuestProgramSpec().Arguments, "CDS_CONFIG=")
return 1, nil
},
)
Expand Down Expand Up @@ -400,7 +402,9 @@ func TestHatcheryVSphere_SpawnWorker(t *testing.T) {
c.EXPECT().StartProgramInGuest(gomock.Any(), &procman, gomock.Any()).DoAndReturn(
func(ctx context.Context, procman *guest.ProcessManager, req *types.StartProgramInGuest) (int64, error) {
assert.Equal(t, "/bin/echo", req.Spec.GetGuestProgramSpec().ProgramPath)
assert.Equal(t, "-n ;\n./worker\nshutdown -h now", req.Spec.GetGuestProgramSpec().Arguments)
assert.Contains(t, req.Spec.GetGuestProgramSpec().Arguments, "-n ;\n")
assert.Contains(t, req.Spec.GetGuestProgramSpec().Arguments, "./worker\nshutdown -h now")
assert.Contains(t, req.Spec.GetGuestProgramSpec().Arguments, "CDS_CONFIG=")
return 1, nil
},
)
Expand Down Expand Up @@ -577,8 +581,9 @@ func TestHatcheryVSphere_SpawnWorkerFromProvisioning(t *testing.T) {

c.EXPECT().StartProgramInGuest(gomock.Any(), &procman, gomock.Any()).DoAndReturn(
func(ctx context.Context, procman *guest.ProcessManager, req *types.StartProgramInGuest) (int64, error) {
assert.Equal(t, "/bin/echo", req.Spec.GetGuestProgramSpec().ProgramPath)
assert.Equal(t, "-n ;\n./worker\nshutdown -h now", req.Spec.GetGuestProgramSpec().Arguments)
assert.Contains(t, req.Spec.GetGuestProgramSpec().Arguments, "-n ;\n")
assert.Contains(t, req.Spec.GetGuestProgramSpec().Arguments, "./worker\nshutdown -h now")
assert.Contains(t, req.Spec.GetGuestProgramSpec().Arguments, "CDS_CONFIG=")
return 1, nil
},
)
Expand Down

0 comments on commit ddfe9a1

Please sign in to comment.