-
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.
✅ (hotfix/new-tests) Add tests to hooks
- Loading branch information
Vitor Hugo
committed
Sep 16, 2023
1 parent
f9e148b
commit e3ade2d
Showing
5 changed files
with
149 additions
and
48 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
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,84 @@ | ||
package hooks | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"gotest.tools/v3/assert" | ||
) | ||
|
||
func TestHooksImpl(t *testing.T) { | ||
t.Run("OnStart", func(t *testing.T) { | ||
h := &LifecycleHooks{} | ||
|
||
t.Run("should add function to onStart slice", func(t *testing.T) { | ||
h.OnStart(func() error { | ||
return nil | ||
}) | ||
assert.Equal(t, len(h.onStart), 1) | ||
}) | ||
}) | ||
|
||
t.Run("OnStop", func(t *testing.T) { | ||
h := &LifecycleHooks{} | ||
|
||
t.Run("should add function to onStop slice", func(t *testing.T) { | ||
h.OnStop(func() error { | ||
return nil | ||
}) | ||
assert.Equal(t, len(h.onStop), 1) | ||
}) | ||
}) | ||
|
||
t.Run("Start", func(t *testing.T) { | ||
t.Run("should execute all onStart hooks without error", func(t *testing.T) { | ||
h := &LifecycleHooks{} | ||
h.OnStart(func() error { | ||
return nil | ||
}) | ||
h.OnStart(func() error { | ||
return nil | ||
}) | ||
err := h.Start() | ||
assert.NilError(t, err) | ||
}) | ||
|
||
t.Run("should return error if any onStart hook fails", func(t *testing.T) { | ||
h := &LifecycleHooks{} | ||
h.OnStart(func() error { | ||
return nil | ||
}) | ||
h.OnStart(func() error { | ||
return errors.New("start error") | ||
}) | ||
err := h.Start() | ||
assert.ErrorContains(t, err, "start error") | ||
}) | ||
}) | ||
|
||
t.Run("Stop", func(t *testing.T) { | ||
t.Run("should execute all onStop hooks without error", func(t *testing.T) { | ||
h := &LifecycleHooks{} | ||
h.OnStop(func() error { | ||
return nil | ||
}) | ||
h.OnStop(func() error { | ||
return nil | ||
}) | ||
err := h.Stop() | ||
assert.NilError(t, err) | ||
}) | ||
|
||
t.Run("should return error if any onStop hook fails", func(t *testing.T) { | ||
h := &LifecycleHooks{} | ||
h.OnStop(func() error { | ||
return nil | ||
}) | ||
h.OnStop(func() error { | ||
return errors.New("stop error") | ||
}) | ||
err := h.Stop() | ||
assert.ErrorContains(t, err, "stop error") | ||
}) | ||
}) | ||
} |