Skip to content

Commit

Permalink
crond: fixed test on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jkellerer committed Mar 19, 2024
1 parent 790ee86 commit ee54d5c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 40 deletions.
15 changes: 10 additions & 5 deletions crond/crontab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"

"github.com/creativeprojects/resticprofile/calendar"
"github.com/creativeprojects/resticprofile/platform"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -182,13 +183,17 @@ func TestLoadCurrentFromFile(t *testing.T) {

func TestLoadCurrent(t *testing.T) {
defer func() {
_ = os.Remove(CrontabBinary)
CrontabBinary = DefaultCrontabBinary
_ = os.Remove("./crontab")
}()
cmd := exec.Command("go", "build", "-o", "crontab", "./stdin")
err := cmd.Run()
require.NoError(t, err)
CrontabBinary = "./crontab"
if platform.IsWindows() {
CrontabBinary = "crontab.exe"
} else {
CrontabBinary = "./crontab"
}

cmd := exec.Command("go", "build", "-o", CrontabBinary, "./stdin")
require.NoError(t, cmd.Run())

crontab := NewCrontab(nil)
assert.NotNil(t, crontab)
Expand Down
1 change: 0 additions & 1 deletion schedule/handler_crond.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"strings"

"github.com/creativeprojects/resticprofile/calendar"
"github.com/creativeprojects/resticprofile/config"
"github.com/creativeprojects/resticprofile/constants"
"github.com/creativeprojects/resticprofile/crond"
)
Expand Down
34 changes: 0 additions & 34 deletions schedule/handler_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,40 +127,6 @@ func TestHandlerInstanceLaunchd(t *testing.T) {
assert.NotNil(t, handler)
}

func TestLaunchdJobLog(t *testing.T) {
fixtures := []struct {
log string
expected string
noLogArg bool
}{
{log: path.Join(constants.TemporaryDirMarker, "file"), expected: "local.resticprofile.profile.backup.log"},
{log: "", expected: "local.resticprofile.profile.backup.log", noLogArg: true},
{log: "udp://localhost:123", expected: "local.resticprofile.profile.backup.log"},
{log: "tcp://127.0.0.1:123", expected: "local.resticprofile.profile.backup.log"},
{log: "other file", expected: "other file", noLogArg: true},
}

for _, fixture := range fixtures {
t.Run(fixture.log, func(t *testing.T) {
handler := NewHandler(SchedulerLaunchd{}).(*HandlerLaunchd)
args := []string{"--log", fixture.log}
cfg := &Config{
ProfileName: "profile",
CommandName: "backup",
Log: fixture.log,
Arguments: args,
}
launchdJob := handler.getLaunchdJob(cfg, []*calendar.Event{})
assert.Equal(t, fixture.expected, launchdJob.StandardOutPath)
if fixture.noLogArg {
assert.NotSubset(t, launchdJob.ProgramArguments, args)
} else {
assert.Subset(t, launchdJob.ProgramArguments, args)
}
})
}
}

func TestLaunchdJobPreservesEnv(t *testing.T) {
pathEnv := os.Getenv("PATH")
fixtures := []struct {
Expand Down

0 comments on commit ee54d5c

Please sign in to comment.