Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix optionnal the comin.machineId value #14

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")

}
Loading