-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
32e8cb1
commit 2ab8510
Showing
2 changed files
with
133 additions
and
4 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
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,123 @@ | ||
package pkg | ||
|
||
import ( | ||
"main/pkg/fs" | ||
reportersPkg "main/pkg/reporters" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestAppFailToLoadConfig(t *testing.T) { | ||
t.Parallel() | ||
|
||
defer func() { | ||
if r := recover(); r == nil { | ||
require.Fail(t, "Expected to have a panic here!") | ||
} | ||
}() | ||
|
||
filesystem := &fs.TestFS{} | ||
|
||
NewApp("notexisting.toml", filesystem, "1.2.3") | ||
} | ||
|
||
func TestAppFailInvalidConfig(t *testing.T) { | ||
t.Parallel() | ||
|
||
defer func() { | ||
if r := recover(); r == nil { | ||
require.Fail(t, "Expected to have a panic here!") | ||
} | ||
}() | ||
|
||
filesystem := &fs.TestFS{} | ||
|
||
NewApp("config-invalid.toml", filesystem, "1.2.3") | ||
} | ||
|
||
func TestAppCreateConfigWithWarnings(t *testing.T) { | ||
t.Parallel() | ||
|
||
filesystem := &fs.TestFS{} | ||
|
||
app := NewApp("config-with-warnings.toml", filesystem, "1.2.3") | ||
require.NotNil(t, app) | ||
} | ||
|
||
func TestAppCreateConfigValid(t *testing.T) { | ||
t.Parallel() | ||
|
||
filesystem := &fs.TestFS{} | ||
|
||
app := NewApp("config-valid.toml", filesystem, "1.2.3") | ||
require.NotNil(t, app) | ||
} | ||
|
||
func TestAppStartReporterFailedToInit(t *testing.T) { | ||
t.Parallel() | ||
|
||
filesystem := &fs.TestFS{} | ||
|
||
defer func() { | ||
if r := recover(); r == nil { | ||
require.Fail(t, "Expected to have a panic here!") | ||
} | ||
}() | ||
|
||
app := NewApp("config-valid.toml", filesystem, "1.2.3") | ||
app.ReportDispatcher.Reporters = []reportersPkg.Reporter{&reportersPkg.TestReporter{WithInitFail: true}} | ||
|
||
app.Start() | ||
require.NotNil(t, app) | ||
} | ||
|
||
func TestAppStartInvalidCronPattern(t *testing.T) { | ||
t.Parallel() | ||
|
||
filesystem := &fs.TestFS{} | ||
|
||
defer func() { | ||
if r := recover(); r == nil { | ||
require.Fail(t, "Expected to have a panic here!") | ||
} | ||
}() | ||
|
||
app := NewApp("config-valid.toml", filesystem, "1.2.3") | ||
app.Config.Interval = "invalid" | ||
|
||
app.Start() | ||
require.NotNil(t, app) | ||
} | ||
|
||
func TestAppStartOk(t *testing.T) { | ||
t.Parallel() | ||
|
||
filesystem := &fs.TestFS{} | ||
app := NewApp("config-valid.toml", filesystem, "1.2.3") | ||
app.ReportDispatcher.Reporters = []reportersPkg.Reporter{&reportersPkg.TestReporter{}} | ||
|
||
var wg sync.WaitGroup | ||
wg.Add(1) | ||
|
||
go func() { | ||
app.Start() | ||
wg.Done() | ||
}() | ||
|
||
app.Stop() | ||
wg.Wait() | ||
assert.True(t, true) | ||
} | ||
|
||
func TestAppReport(t *testing.T) { | ||
t.Parallel() | ||
|
||
filesystem := &fs.TestFS{} | ||
app := NewApp("config-valid.toml", filesystem, "1.2.3") | ||
app.Report() | ||
|
||
assert.True(t, true) | ||
} |