Skip to content

Commit

Permalink
Merge pull request #14 from nlewo/fix-machine-id-opt
Browse files Browse the repository at this point in the history
Fix optionnal the comin.machineId value
  • Loading branch information
nlewo authored Mar 12, 2024
2 parents 4fbbf62 + 7dac216 commit cc7424b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
4 changes: 2 additions & 2 deletions internal/generation/generation.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ func (g Generation) Eval(ctx context.Context) (result chan EvalResult) {
if err == nil {
evaluationResult.DrvPath = drvPath
evaluationResult.OutPath = outPath
if g.machineId != "" && g.machineId != machineId {
evaluationResult.Err = fmt.Errorf("The defined comin.machineId (%s) is different to the machine id (%s) of this machine",
if machineId != "" && g.machineId != machineId {
evaluationResult.Err = fmt.Errorf("The evaluated comin.machineId '%s' is different from the /etc/machine-id '%s' of this machine",
g.machineId, machineId)
}
} else {
Expand Down
37 changes: 34 additions & 3 deletions internal/manager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestRun(t *testing.T) {
buildDone := make(chan struct{})
nixEvalMock := func(ctx context.Context, repositoryPath string, hostname string) (string, string, string, error) {
<-evalDone
return "drv-path", "out-path", "machine-id", nil
return "drv-path", "out-path", "", nil
}
nixBuildMock := func(ctx context.Context, drvPath string) error {
<-buildDone
Expand Down Expand Up @@ -123,6 +123,38 @@ func TestRestartComin(t *testing.T) {

}

func TestOptionnalMachineId(t *testing.T) {
logrus.SetLevel(logrus.DebugLevel)
r := newRepositoryMock()
m := New(r, "", "", "the-test-machine-id")

evalDone := make(chan struct{})
buildDone := make(chan struct{})
nixEvalMock := func(ctx context.Context, repositoryPath string, hostname string) (string, string, string, error) {
<-evalDone
// When comin.machineId is empty, comin evaluates it as an empty string
evaluatedMachineId := ""
return "drv-path", "out-path", evaluatedMachineId, nil
}
nixBuildMock := func(ctx context.Context, drvPath string) error {
<-buildDone
return nil
}
m.evalFunc = nixEvalMock
m.buildFunc = nixBuildMock

go m.Run()
m.Fetch("origin")
r.rsCh <- repository.RepositoryStatus{SelectedCommitId: "foo"}

// we simulate the end of the evaluation
close(evalDone)

assert.EventuallyWithT(t, func(c *assert.CollectT) {
assert.True(t, m.GetState().IsRunning)
}, 5*time.Second, 100*time.Millisecond, "evaluation is not finished")
}

func TestIncorrectMachineId(t *testing.T) {
logrus.SetLevel(logrus.DebugLevel)
r := newRepositoryMock()
Expand Down Expand Up @@ -156,8 +188,7 @@ func TestIncorrectMachineId(t *testing.T) {
close(evalDone)

assert.EventuallyWithT(t, func(c *assert.CollectT) {
// The manager is now longer running since the machine id is not correct in the generation.
// The manager is no longer running since the machine id are not identical
assert.False(t, m.GetState().IsRunning)
}, 5*time.Second, 100*time.Millisecond, "evaluation is not finished")

}

0 comments on commit cc7424b

Please sign in to comment.