generated from golang-templates/seed
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from FMotalleb/cleanup-optimize
Major: Tests/Optimizition/Rename
- Loading branch information
Showing
34 changed files
with
1,324 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
// Package abstraction must contain only interfaces and abstract layers of modules | ||
package abstraction | ||
|
||
// Scheduler is an object that can be executed using a execute method and stopped using cancel method | ||
type Scheduler interface { | ||
// Event is an object that can be executed using a execute method and stopped using cancel method | ||
type Event interface { | ||
BuildTickChannel() <-chan any | ||
Cancel() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package cfgcompiler_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/alecthomas/assert/v2" | ||
"github.com/robfig/cron/v3" | ||
"github.com/sirupsen/logrus" | ||
|
||
"github.com/FMotalleb/crontab-go/config" | ||
cfgcompiler "github.com/FMotalleb/crontab-go/config/compiler" | ||
"github.com/FMotalleb/crontab-go/core/schedule" | ||
mocklogger "github.com/FMotalleb/crontab-go/logger/mock_logger" | ||
) | ||
|
||
// TestCompileEvent_IntervalZero tests that CompileEvents returns nil when Interval is zero | ||
func TestCompileEvent_IntervalZero(t *testing.T) { | ||
sh := &config.JobEvent{Interval: 0} | ||
cr := cron.New() | ||
logger, _ := mocklogger.HijackOutput(logrus.New()) | ||
log := logrus.NewEntry(logger) | ||
|
||
event := cfgcompiler.CompileEvent(sh, cr, log) | ||
assert.Equal(t, event, nil) | ||
} | ||
|
||
func TestCompileEvent_IntervalNonZero(t *testing.T) { | ||
sh := &config.JobEvent{Interval: 15} | ||
cr := cron.New() | ||
logger, _ := mocklogger.HijackOutput(logrus.New()) | ||
log := logrus.NewEntry(logger) | ||
|
||
sch := cfgcompiler.CompileEvent(sh, cr, log) | ||
_, ok := sch.(*schedule.Interval) | ||
assert.Equal(t, ok, true) | ||
} | ||
|
||
// TestCompileEvent_IntervalZeroWithCronSet tests CompileEvents with Interval zero but Cron expression set | ||
func TestCompileEvent_IntervalZeroWithCronSet(t *testing.T) { | ||
sh := &config.JobEvent{Cron: "0 * * * *", Interval: 0} | ||
cr := cron.New() | ||
logger, _ := mocklogger.HijackOutput(logrus.New()) | ||
log := logrus.NewEntry(logger) | ||
|
||
event := cfgcompiler.CompileEvent(sh, cr, log) | ||
if _, ok := event.(*schedule.Cron); !ok { | ||
t.Errorf("Expected Cron events, got %T", event) | ||
} | ||
} | ||
|
||
// TestCompileEvent_IntervalZeroWithOnInitSet tests CompileEvents with Interval zero and OnInit set | ||
func TestCompileEvent_IntervalZeroWithOnInitSet(t *testing.T) { | ||
sh := &config.JobEvent{OnInit: true, Interval: 0} | ||
cr := cron.New() | ||
logger, _ := mocklogger.HijackOutput(logrus.New()) | ||
log := logrus.NewEntry(logger) | ||
|
||
event := cfgcompiler.CompileEvent(sh, cr, log) | ||
if _, ok := event.(*schedule.Init); !ok { | ||
t.Errorf("Expected Init events, got %T", event) | ||
} | ||
} | ||
|
||
// TestCompileEvent_IntervalZeroWithAllFieldsEmpty tests CompileEvents with Interval zero and all other fields empty | ||
func TestCompileEvent_IntervalZeroWithAllFieldsEmpty(t *testing.T) { | ||
sh := &config.JobEvent{Interval: 0} | ||
cr := cron.New() | ||
logger, _ := mocklogger.HijackOutput(logrus.New()) | ||
log := logrus.NewEntry(logger) | ||
|
||
event := cfgcompiler.CompileEvent(sh, cr, log) | ||
if event != nil { | ||
t.Errorf("Expected nil, got %v", event) | ||
} | ||
} | ||
|
||
// TestCompileEvent_IntervalZeroWithCronAndOnInitSet tests CompileEvent with Interval zero, Cron expression, and OnInit set | ||
func TestCompileEvent_IntervalZeroWithCronAndOnInitSet(t *testing.T) { | ||
sh := &config.JobEvent{Cron: "0 * * * *", OnInit: true, Interval: 0} | ||
cr := cron.New() | ||
logger, _ := mocklogger.HijackOutput(logrus.New()) | ||
log := logrus.NewEntry(logger) | ||
|
||
event := cfgcompiler.CompileEvent(sh, cr, log) | ||
if _, ok := event.(*schedule.Cron); !ok { | ||
t.Errorf("Expected Cron event, got %T", event) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package cfgcompiler_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/alecthomas/assert/v2" | ||
"github.com/sirupsen/logrus" | ||
|
||
"github.com/FMotalleb/crontab-go/config" | ||
cfgcompiler "github.com/FMotalleb/crontab-go/config/compiler" | ||
mocklogger "github.com/FMotalleb/crontab-go/logger/mock_logger" | ||
) | ||
|
||
func TestCompileTask_NonExistingTask(t *testing.T) { | ||
logger, _ := mocklogger.HijackOutput(logrus.New()) | ||
log := logrus.NewEntry(logger) | ||
taskConfig := &config.Task{} | ||
assert.Panics( | ||
t, | ||
func() { | ||
cfgcompiler.CompileTask(taskConfig, log) | ||
}, | ||
) | ||
} | ||
|
||
func TestCompileTask_GetTask(t *testing.T) { | ||
logger, _ := mocklogger.HijackOutput(logrus.New()) | ||
log := logrus.NewEntry(logger) | ||
taskConfig := &config.Task{ | ||
Get: "test", | ||
} | ||
exe := cfgcompiler.CompileTask(taskConfig, log) | ||
assert.NotEqual(t, exe, nil) | ||
} | ||
|
||
func TestCompileTask_CommandTask(t *testing.T) { | ||
logger, _ := mocklogger.HijackOutput(logrus.New()) | ||
log := logrus.NewEntry(logger) | ||
taskConfig := &config.Task{ | ||
Command: "test", | ||
} | ||
exe := cfgcompiler.CompileTask(taskConfig, log) | ||
assert.NotEqual(t, exe, nil) | ||
} | ||
|
||
func TestCompileTask_PostTask(t *testing.T) { | ||
logger, _ := mocklogger.HijackOutput(logrus.New()) | ||
log := logrus.NewEntry(logger) | ||
taskConfig := &config.Task{ | ||
Post: "test", | ||
} | ||
exe := cfgcompiler.CompileTask(taskConfig, log) | ||
assert.NotEqual(t, exe, nil) | ||
} | ||
|
||
func TestCompileTask_WithHooks(t *testing.T) { | ||
logger, _ := mocklogger.HijackOutput(logrus.New()) | ||
log := logrus.NewEntry(logger) | ||
taskConfig := &config.Task{ | ||
Command: "test", | ||
OnDone: []config.Task{ | ||
{ | ||
Command: "test", | ||
}, | ||
}, | ||
OnFail: []config.Task{ | ||
{ | ||
Command: "test", | ||
}, | ||
}, | ||
} | ||
exe := cfgcompiler.CompileTask(taskConfig, log) | ||
assert.NotEqual(t, exe, nil) | ||
} |
Oops, something went wrong.