-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #118 from 1Password/fix/internal-server-conflict
Retry CLI request in case of 409 Conflict error
- Loading branch information
Showing
5 changed files
with
151 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package cli | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/1Password/connect-sdk-go/onepassword" | ||
) | ||
|
||
func TestWithRetry(t *testing.T) { | ||
op := &OP{} | ||
tests := map[string]struct { | ||
fakeAction func() (*onepassword.Item, error) | ||
validate func(item *onepassword.Item, err error) | ||
}{ | ||
"should fail when error other than 409": { | ||
fakeAction: func() (*onepassword.Item, error) { | ||
return nil, errors.New("failed to perform action") | ||
}, | ||
validate: func(item *onepassword.Item, err error) { | ||
if err == nil { | ||
t.Error("Action should fail when error is other than 409") | ||
} | ||
if item != nil { | ||
t.Error("Item should be nil when error is other than 409") | ||
} | ||
}, | ||
}, | ||
"should fail when error is 409": { | ||
fakeAction: func() (*onepassword.Item, error) { | ||
return nil, errors.New("409 Conflict error") | ||
}, | ||
validate: func(item *onepassword.Item, err error) { | ||
if err == nil { | ||
t.Error("Action should fail when error is 409") | ||
} | ||
if item != nil { | ||
t.Error("Item should be nil when error is 409") | ||
} | ||
}, | ||
}, | ||
"should succeed": { | ||
fakeAction: func() (*onepassword.Item, error) { | ||
return &onepassword.Item{}, nil | ||
}, | ||
validate: func(item *onepassword.Item, err error) { | ||
if err != nil { | ||
t.Errorf("Action should succeed, but got an error: %s", err.Error()) | ||
} | ||
if item == nil { | ||
t.Error("Item should not be nil") | ||
} | ||
}, | ||
}, | ||
} | ||
|
||
for description, test := range tests { | ||
t.Run(description, func(t *testing.T) { | ||
test.validate(op.withRetry(test.fakeAction)) | ||
}) | ||
} | ||
} |
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