-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
2 changed files
with
59 additions
and
0 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,58 @@ | ||
package system | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
"sync" | ||
"testing" | ||
) | ||
|
||
func Test_System(t *testing.T) { | ||
t.Run("Critical error", func(t *testing.T) { | ||
var exitCode *int | ||
exitFunc = func(code int) { | ||
exitCode = &code | ||
} | ||
|
||
CriticalError(errors.New("foo")) | ||
|
||
if exitCode == nil || *exitCode != 1 { | ||
t.Errorf("Expected exit code 1, got %d", exitCode) | ||
} | ||
}) | ||
|
||
t.Run("Error", func(t *testing.T) { | ||
var exitCode *int | ||
exitFunc = func(code int) { | ||
exitCode = &code | ||
} | ||
|
||
wg := sync.WaitGroup{} | ||
var signal *os.Signal | ||
|
||
s := GetSignalChannel() | ||
|
||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
current := <-s | ||
signal = ¤t | ||
}() | ||
|
||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
Error(errors.New("foo")) | ||
}() | ||
|
||
wg.Wait() | ||
|
||
if exitCode != nil { | ||
t.Error("Exit should not be called") | ||
} | ||
|
||
if signal == nil { | ||
t.Error("Signal should not be called") | ||
} | ||
}) | ||
} |