-
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.
* Remove call to string() * Move gsmanager to its own package * Use interface to make gsmanager more testable * Add tests * Update deps * Remove deprecated call * Update README
- Loading branch information
Showing
7 changed files
with
126 additions
and
23 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
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,67 @@ | ||
package gsmanager | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/googleapis/gax-go/v2" | ||
. "github.com/onsi/gomega" | ||
secretmanagerpb "google.golang.org/genproto/googleapis/cloud/secretmanager/v1" | ||
) | ||
|
||
type testClient struct { | ||
accessSecretVersionCalled bool | ||
accessSecretReturnError error | ||
accessSecretVersionReturn *secretmanagerpb.AccessSecretVersionResponse | ||
closeCalled bool | ||
} | ||
|
||
func (tc *testClient) AccessSecretVersion(ctx context.Context, req *secretmanagerpb.AccessSecretVersionRequest, opts ...gax.CallOption) (*secretmanagerpb.AccessSecretVersionResponse, error) { | ||
tc.accessSecretVersionCalled = true | ||
if tc.accessSecretReturnError != nil { | ||
return nil, tc.accessSecretReturnError | ||
} | ||
|
||
return tc.accessSecretVersionReturn, nil | ||
} | ||
|
||
func (tc *testClient) Close() error { | ||
tc.closeCalled = true | ||
return nil | ||
} | ||
|
||
func TestDecrypt(t *testing.T) { | ||
g := NewWithT(t) | ||
|
||
secretIdentifier := "my/super/secret/versions/latest" | ||
decrypted := []byte("superSecret") | ||
tc := &testClient{ | ||
accessSecretVersionReturn: &secretmanagerpb.AccessSecretVersionResponse{ | ||
Name: secretIdentifier, | ||
Payload: &secretmanagerpb.SecretPayload{ | ||
Data: decrypted, | ||
}, | ||
}, | ||
} | ||
gsm := &GSManager{ | ||
smClient: tc, | ||
} | ||
|
||
dec, err := gsm.Decrypt(secretIdentifier) | ||
g.Expect(err).To(BeNil()) | ||
g.Expect(tc.accessSecretVersionCalled).To(BeTrue()) | ||
g.Expect(dec).To(Equal(string(decrypted))) | ||
} | ||
|
||
func TestClose(t *testing.T) { | ||
g := NewWithT(t) | ||
|
||
tc := &testClient{} | ||
gsm := &GSManager{ | ||
smClient: tc, | ||
} | ||
|
||
err := gsm.Close() | ||
g.Expect(err).To(BeNil()) | ||
g.Expect(tc.closeCalled).To(BeTrue()) | ||
} |
Oops, something went wrong.