forked from majd/ipatool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
313 additions
and
117 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 was deleted.
Oops, something went wrong.
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,3 @@ | ||
package http | ||
|
||
//go:generate mockgen -source=client.go -destination=../../mocks/http_mock.go -package=mocks |
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 |
---|---|---|
@@ -1 +1,31 @@ | ||
package keychain | ||
|
||
import "github.com/99designs/keyring" | ||
|
||
//go:generate mockgen -source=keychain.go -destination=../../mocks/keychain_mock.go -package=mocks | ||
|
||
type Keyring interface { | ||
Get(key string) (keyring.Item, error) | ||
Set(item keyring.Item) error | ||
Remove(key string) error | ||
} | ||
|
||
type Keychain interface { | ||
Get(key string) ([]byte, error) | ||
Set(key string, data []byte) error | ||
Remove(key string) error | ||
} | ||
|
||
type keychain struct { | ||
keyring Keyring | ||
} | ||
|
||
type Args struct { | ||
Keyring Keyring | ||
} | ||
|
||
func NewKeychain(args *Args) Keychain { | ||
return &keychain{ | ||
keyring: args.Keyring, | ||
} | ||
} |
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 |
---|---|---|
@@ -1 +1,14 @@ | ||
package keychain | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func (k *keychain) Get(key string) ([]byte, error) { | ||
item, err := k.keyring.Get(key) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to get item from keyring") | ||
} | ||
|
||
return item.Data, nil | ||
} |
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 |
---|---|---|
@@ -1 +1,67 @@ | ||
package keychain | ||
|
||
import ( | ||
"github.com/99designs/keyring" | ||
"github.com/golang/mock/gomock" | ||
"github.com/majd/ipatool/mocks" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
var _ = Describe("Keychain (Get)", func() { | ||
var ( | ||
ctrl *gomock.Controller | ||
keychain Keychain | ||
mockKeyring *mocks.MockKeyring | ||
) | ||
|
||
BeforeEach(func() { | ||
ctrl = gomock.NewController(GinkgoT()) | ||
mockKeyring = mocks.NewMockKeyring(ctrl) | ||
keychain = NewKeychain(&Args{ | ||
Keyring: mockKeyring, | ||
}) | ||
}) | ||
|
||
AfterEach(func() { | ||
ctrl.Finish() | ||
}) | ||
|
||
When("keyring returns error", func() { | ||
const testKey = "test-key" | ||
var testErr = errors.New("test error") | ||
|
||
BeforeEach(func() { | ||
mockKeyring.EXPECT(). | ||
Get(testKey). | ||
Return(keyring.Item{}, testErr) | ||
}) | ||
|
||
It("returns wrapped error", func() { | ||
data, err := keychain.Get(testKey) | ||
Expect(err).To(MatchError(ContainSubstring(testErr.Error()))) | ||
Expect(err).To(MatchError(ContainSubstring("failed to get item from keyring"))) | ||
Expect(data).To(BeNil()) | ||
}) | ||
}) | ||
|
||
When("keyring returns item", func() { | ||
const testKey = "test-key" | ||
var testData = []byte("test") | ||
|
||
BeforeEach(func() { | ||
mockKeyring.EXPECT(). | ||
Get(testKey). | ||
Return(keyring.Item{ | ||
Data: testData, | ||
}, nil) | ||
}) | ||
|
||
It("returns data", func() { | ||
data, err := keychain.Get(testKey) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(data).To(Equal(testData)) | ||
}) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1 +1,8 @@ | ||
package keychain | ||
|
||
import "github.com/pkg/errors" | ||
|
||
func (k *keychain) Remove(key string) error { | ||
err := k.keyring.Remove(key) | ||
return errors.Wrap(err, "failed to remove item from keyring") | ||
} |
Oops, something went wrong.