Skip to content

Commit

Permalink
fix(cli): error when account is empty
Browse files Browse the repository at this point in the history
Signed-off-by: Salim Afiune Maya <[email protected]>
  • Loading branch information
afiune committed Mar 31, 2020
1 parent 8f7343c commit 7dc59aa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"strconv"
"time"

"github.com/pkg/errors"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -63,6 +64,10 @@ func (fn clientFunc) apply(c *Client) error {
// lacework.Integrations.List()
// }
func NewClient(account string, opts ...Option) (*Client, error) {
if account == "" {
return nil, errors.New("account cannot be empty")
}

baseURL, err := url.Parse(fmt.Sprintf("https://%s.lacework.net", account))
if err != nil {
return nil, err
Expand Down
9 changes: 9 additions & 0 deletions api/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ func TestNewClient(t *testing.T) {
}
}

func TestNewClientAccountEmptyError(t *testing.T) {
c, err := api.NewClient("")
assert.Nil(t, c)
if assert.NotNil(t, err) {
assert.Equal(t, "account cannot be empty", err.Error(),
"we cannot create an api client without a Lacework account")
}
}

func TestNewClientWithOptions(t *testing.T) {
fakeServer := lacework.MockServer()
fakeServer.ApiVersion = "v2"
Expand Down

0 comments on commit 7dc59aa

Please sign in to comment.