This repository has been archived by the owner on Jan 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 482
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allows library implementations of StreamClient and StreamClientFactory to return fatal StreamErrors Signed-off-by: Michael Stergianis <[email protected]>
- Loading branch information
1 parent
cfb4958
commit 8908404
Showing
4 changed files
with
107 additions
and
24 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,39 @@ | ||
package errors | ||
|
||
import "github.com/vmware-tanzu/octant/internal/errors" | ||
|
||
type StreamError struct { | ||
*errors.GenericError | ||
Fatal bool | ||
} | ||
|
||
func NewStreamError(err error) *StreamError { | ||
return &StreamError{ | ||
errors.NewGenericError(err), | ||
false, | ||
} | ||
} | ||
|
||
func FatalStreamError(err error) *StreamError { | ||
return &StreamError{ | ||
errors.NewGenericError(err), | ||
true, | ||
} | ||
} | ||
|
||
func IsFatalStreamError(err error) bool { | ||
switch sErr := err.(type) { | ||
case StreamError: | ||
return sErr.Fatal | ||
case *StreamError: | ||
return sErr.Fatal | ||
default: | ||
return false | ||
} | ||
} | ||
|
||
const StreamingConnectionError = "StreamingConnectionError" | ||
|
||
func (s *StreamError) Name() string { | ||
return StreamingConnectionError | ||
} |
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,65 @@ | ||
package errors | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestConstructors(t *testing.T) { | ||
err := fmt.Errorf("encountered an error while streaming") | ||
table := []struct { | ||
name string | ||
sErr *StreamError | ||
fatal bool | ||
}{ | ||
{"NewStreamError", NewStreamError(err), false}, | ||
{"FatalStreamError", FatalStreamError(err), true}, | ||
} | ||
|
||
for _, test := range table { | ||
t.Run(test.name, func(t *testing.T) { | ||
assert.NotEmpty(t, test.sErr.Timestamp()) | ||
assert.Equal(t, test.sErr.Name(), StreamingConnectionError) | ||
assert.NotZero(t, test.sErr.ID()) | ||
assert.Equal(t, test.fatal, test.sErr.Fatal) | ||
assert.Equal(t, err.Error(), test.sErr.Error()) | ||
}) | ||
} | ||
} | ||
|
||
func TestIsFatalStreamError(t *testing.T) { | ||
table := []struct { | ||
name string | ||
sErr error | ||
expected bool | ||
}{ | ||
{ | ||
"Expect IsFatalStreamError to be false for a standard stream error", | ||
NewStreamError(fmt.Errorf("")), | ||
false, | ||
}, | ||
{ | ||
"Expect IsFatalStreamError to be true for fatal stream error", | ||
FatalStreamError(fmt.Errorf("")), | ||
true, | ||
}, | ||
{ | ||
"A non pointer fatal stream error is provided", | ||
*FatalStreamError(fmt.Errorf("")), | ||
true, | ||
}, | ||
{ | ||
"A generic error is provided", | ||
fmt.Errorf(""), | ||
false, | ||
}, | ||
} | ||
|
||
for _, test := range table { | ||
t.Run(test.name, func(t *testing.T) { | ||
assert.Equal(t, test.expected, IsFatalStreamError(test.sErr)) | ||
}) | ||
} | ||
} |