Skip to content

Commit

Permalink
fix: the string source should error if the string is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
zeevallin committed Feb 8, 2019
1 parent 851296d commit 15f1273
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions keys/errors.go
Expand Up @@ -29,4 +29,7 @@ var (

// ErrEmptyFilePath represents an error for when an expected file path is an empty string
ErrEmptyFilePath = ErrGetKeySource{"file path cannot be empty"}

// ErrEmptyString represents an error for when an expected string should contain a public key
ErrEmptyString = ErrGetKeySource{"string cannot be empty"}
)
3 changes: 3 additions & 0 deletions keys/source.go
Expand Up @@ -87,5 +87,8 @@ type StringSource string

// Get converts the string to a byte slice
func (source StringSource) Get(ctx context.Context) ([]byte, error) {
if source == "" {
return nil, ErrEmptyString
}
return []byte(source), nil
}
6 changes: 6 additions & 0 deletions keys/source_test.go
Expand Up @@ -120,6 +120,12 @@ func TestStringSource(t *testing.T) {
expectedBytes: []byte("barbaz"),
expectedErr: nil,
},
{
name: "when source is empty",
source: keys.StringSource(""),
expectedBytes: nil,
expectedErr: keys.ErrEmptyString,
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
Expand Down

0 comments on commit 15f1273

Please sign in to comment.