Skip to content

Commit d13e640

Browse files
committed
Use credentials IsEmpty again (#111)
1 parent 4f5db52 commit d13e640

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

Diff for: internal/config/credentials.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ func (c *Credentials) Validate() error {
8686
return nil
8787
}
8888

89-
// Complete checks if Credentials has all the mandatory params set.
89+
// IsEmpty checks if Credentials has no mandatory params set.
9090
// Optional parameters are not considered here.
91-
func (c *Credentials) Complete() bool {
91+
func (c *Credentials) IsEmpty() bool {
9292
return len(c.Client) == 0 && len(c.Secret) == 0
9393
}
9494

@@ -104,7 +104,7 @@ func FindCredentials() (source string, err error) {
104104
if err != nil {
105105
return "", fmt.Errorf("looking for credentials in environment variables: %w", err)
106106
}
107-
if c.Complete() {
107+
if !c.IsEmpty() {
108108
logrus.Infof("Credentials found in environment variables with prefix '%s'", EnvPrefix)
109109
return "environment variables", nil
110110
}
@@ -136,7 +136,7 @@ func RetrieveCredentials() (cred *Credentials, err error) {
136136
return nil, fmt.Errorf("reading credentials from environment variables: %w", err)
137137
}
138138
// Returns credentials if found in env
139-
if !cred.Complete() {
139+
if !cred.IsEmpty() {
140140
// Returns error if credentials are found but are not valid
141141
if err := cred.Validate(); err != nil {
142142
return nil, fmt.Errorf(

Diff for: internal/config/credentials_test.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ func TestValidate(t *testing.T) {
252252
}
253253
}
254254

255-
func TestComplete(t *testing.T) {
255+
func TestIsEmpty(t *testing.T) {
256256
var (
257257
validSecret = "qaRZGEbnQNNvmaeTLqy8Bxs22wLZ6H7obIiNSveTLPdoQuylANnuy6WBOw16XoqH"
258258
validClient = "CQ4iZ5sebOfhGRwUn3IV0r1YFMNrMTIx"
@@ -283,11 +283,16 @@ func TestComplete(t *testing.T) {
283283
config: &Credentials{Client: validClient, Secret: ""},
284284
want: false,
285285
},
286+
{
287+
name: "credentials with all mandatory params set",
288+
config: &Credentials{Client: validClient, Secret: validSecret},
289+
want: false,
290+
},
286291
}
287292

288293
for _, tt := range tests {
289294
t.Run(tt.name, func(t *testing.T) {
290-
got := tt.config.Complete()
295+
got := tt.config.IsEmpty()
291296
if got != tt.want {
292297
t.Errorf("Expected %v but got %v, with credentials: %v", tt.want, got, tt.config)
293298
}

0 commit comments

Comments
 (0)