forked from wildeyedskies/stmp
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[main] make it more testable, add some simple tests
- Loading branch information
1 parent
85d3e0a
commit 162c4a9
Showing
4 changed files
with
71 additions
and
17 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
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,46 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/spezifisch/stmps/logger" | ||
"github.com/spezifisch/stmps/mpvplayer" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// Test initialization of the player | ||
func TestPlayerInitialization(t *testing.T) { | ||
logger := logger.Init() | ||
player, err := mpvplayer.NewPlayer(logger) | ||
assert.NoError(t, err, "Player initialization should not return an error") | ||
assert.NotNil(t, player, "Player should be initialized") | ||
} | ||
|
||
func TestMainWithoutTUI(t *testing.T) { | ||
// Mock osExit to prevent actual exit during test | ||
exitCalled := false | ||
osExit = func(code int) { | ||
exitCalled = true | ||
if code != 0 { | ||
t.Fatalf("Unexpected exit with code: %d", code) | ||
} | ||
// Since we don't abort execution here, we will run main() until the end or a panic. | ||
} | ||
headlessMode = true | ||
|
||
// Restore osExit after the test | ||
defer func() { | ||
osExit = os.Exit | ||
headlessMode = false | ||
}() | ||
|
||
// Set command-line arguments to trigger the help flag | ||
os.Args = []string{"cmd", "--help"} | ||
|
||
main() | ||
|
||
if !exitCalled { | ||
t.Fatalf("osExit was not called") | ||
} | ||
} |