-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate integration tests from unit tests
- Loading branch information
Showing
4 changed files
with
183 additions
and
200 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,112 @@ | ||
package onepassword | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// invalid name/version test cases may belong in integration_test.go | ||
// currently these tests fail correctly, but they have incorrect tokens, so the accuracy of these fails is in question | ||
|
||
func TestNoToken(t *testing.T) { | ||
clientFactory, err := NewClientFactory(context.TODO()) | ||
require.NoError(t, err) | ||
clientFactory := NewTestClientFactory() | ||
|
||
// missing token | ||
_, err = clientFactory.NewClient( | ||
_, err := clientFactory.NewClient( | ||
WithIntegrationInfo(DefaultIntegrationName, DefaultIntegrationVersion)) | ||
require.Error(t, err) | ||
} | ||
|
||
func TestNoIntegrationNameOrVersion(t *testing.T) { | ||
token := os.Getenv("OP_SERVICE_ACCOUNT_TOKEN") | ||
|
||
clientFactory := NewTestClientFactory() | ||
|
||
_, err := clientFactory.NewClient( | ||
WithServiceAccountToken(token), | ||
WithIntegrationInfo("", "")) | ||
require.Error(t, err) | ||
} | ||
|
||
func TestNoIntegrationName(t *testing.T) { | ||
token := os.Getenv("OP_SERVICE_ACCOUNT_TOKEN") | ||
|
||
clientFactory := NewTestClientFactory() | ||
|
||
_, err := clientFactory.NewClient( | ||
WithServiceAccountToken(token), | ||
WithIntegrationInfo("", DefaultIntegrationVersion)) | ||
require.Error(t, err) | ||
} | ||
|
||
func TestInvalidIntegrationNameLength(t *testing.T) { | ||
token := os.Getenv("OP_SERVICE_ACCOUNT_TOKEN") | ||
|
||
clientFactory := NewTestClientFactory() | ||
|
||
_, err := clientFactory.NewClient( | ||
WithServiceAccountToken(token), | ||
WithIntegrationInfo("12345678901234567890123456789012345678901234567890", DefaultIntegrationVersion)) | ||
require.Error(t, err) | ||
} | ||
|
||
func TestInvalidIntegrationNameCharacters(t *testing.T) { | ||
token := os.Getenv("OP_SERVICE_ACCOUNT_TOKEN") | ||
|
||
clientFactory := NewTestClientFactory() | ||
|
||
_, err := clientFactory.NewClient( | ||
WithServiceAccountToken(token), | ||
WithIntegrationInfo("$", DefaultIntegrationVersion)) | ||
require.Error(t, err) | ||
} | ||
|
||
func TestNoIntegrationVersion(t *testing.T) { | ||
token := os.Getenv("OP_SERVICE_ACCOUNT_TOKEN") | ||
|
||
clientFactory := NewTestClientFactory() | ||
|
||
_, err := clientFactory.NewClient( | ||
WithServiceAccountToken(token), | ||
WithIntegrationInfo(DefaultIntegrationName, "")) | ||
require.Error(t, err) | ||
} | ||
|
||
func TestInvalidIntegrationVersionLength(t *testing.T) { | ||
token := os.Getenv("OP_SERVICE_ACCOUNT_TOKEN") | ||
|
||
clientFactory := NewTestClientFactory() | ||
|
||
_, err := clientFactory.NewClient( | ||
WithServiceAccountToken(token), | ||
WithIntegrationInfo(DefaultIntegrationName, "12345678901234567890123456789012345678901234567890")) | ||
require.Error(t, err) | ||
} | ||
|
||
func TestInvalidIntegrationVersionCharacters(t *testing.T) { | ||
token := os.Getenv("OP_SERVICE_ACCOUNT_TOKEN") | ||
|
||
clientFactory := NewTestClientFactory() | ||
|
||
_, err := clientFactory.NewClient( | ||
WithServiceAccountToken(token), | ||
WithIntegrationInfo(DefaultIntegrationName, "$")) | ||
require.Error(t, err) | ||
} | ||
|
||
func NewTestClientFactory() *ClientFactory { | ||
return &ClientFactory{core: TestCore{}} | ||
} | ||
|
||
type TestCore struct{} | ||
|
||
func (c TestCore) InitClient(config ClientConfig) (*uint64, error) { | ||
var id uint64 | ||
return &id, nil | ||
} | ||
|
||
func (c TestCore) Invoke(invokeConfig Invocation) (*string, error) { | ||
response := "secret" | ||
return &response, nil | ||
} | ||
|
||
func (c TestCore) ReleaseClient(clientID uint64) {} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.