-
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.
test(acceptance): add acceptance tests (#10)
- Loading branch information
1 parent
13fed93
commit 8b230b7
Showing
12 changed files
with
419 additions
and
129 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright © 2022 Meroxa, Inc. and Miquido | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
sdk "github.com/conduitio/conduit-connector-sdk" | ||
sf "github.com/miquido/conduit-connector-salesforce" | ||
"github.com/miquido/conduit-connector-salesforce/internal/cometd" | ||
"github.com/miquido/conduit-connector-salesforce/internal/salesforce/oauth" | ||
sfSource "github.com/miquido/conduit-connector-salesforce/source" | ||
) | ||
|
||
type CustomConfigurableAcceptanceTestDriver struct { | ||
sdk.ConfigurableAcceptanceTestDriver | ||
|
||
streamingClient *streamingClientMock | ||
} | ||
|
||
func (d *CustomConfigurableAcceptanceTestDriver) WriteToSource(_ *testing.T, records []sdk.Record) (results []sdk.Record) { | ||
d.streamingClient.SetResults(records) | ||
|
||
// No destination connector, return wanted records | ||
for _, record := range records { | ||
record.Key = nil | ||
|
||
results = append(results, record) | ||
} | ||
|
||
return | ||
} | ||
|
||
func TestAcceptance(t *testing.T) { | ||
sourceConfig := map[string]string{ | ||
sfSource.ConfigKeyEnvironment: oauth.EnvironmentSandbox, | ||
sfSource.ConfigKeyClientID: "client-id", | ||
sfSource.ConfigKeyClientSecret: "client-secret", | ||
sfSource.ConfigKeyUsername: "username", | ||
sfSource.ConfigKeyPassword: "password", | ||
sfSource.ConfigKeySecurityToken: "security-token", | ||
sfSource.ConfigKeyPushTopicsNames: "MyTopic1,MyTopic2", | ||
} | ||
|
||
sfSource.OAuthClientFactory = func(_ oauth.Environment, _, _, _, _, _ string) oauth.Client { | ||
return &oAuthClientMock{} | ||
} | ||
|
||
streamingClient := &streamingClientMock{} | ||
sfSource.StreamingClientFactory = func(_, _ string) (cometd.Client, error) { | ||
return streamingClient, nil | ||
} | ||
|
||
sdk.AcceptanceTest(t, &CustomConfigurableAcceptanceTestDriver{ | ||
ConfigurableAcceptanceTestDriver: sdk.ConfigurableAcceptanceTestDriver{ | ||
Config: sdk.ConfigurableAcceptanceTestDriverConfig{ | ||
Connector: sdk.Connector{ | ||
NewSpecification: sf.Specification, | ||
NewSource: sfSource.NewSource, | ||
NewDestination: nil, | ||
}, | ||
|
||
SourceConfig: sourceConfig, | ||
GenerateDataType: sdk.GenerateStructuredData, | ||
|
||
Skip: []string{ | ||
"TestAcceptance/TestSource_Open_ResumeAtPositionCDC", | ||
"TestAcceptance/TestSource_Open_ResumeAtPositionSnapshot", | ||
}, | ||
}, | ||
}, | ||
|
||
streamingClient: streamingClient, | ||
}) | ||
} |
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,34 @@ | ||
// Copyright © 2022 Meroxa, Inc. and Miquido | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/miquido/conduit-connector-salesforce/internal/salesforce/oauth/response" | ||
) | ||
|
||
type oAuthClientMock struct { | ||
} | ||
|
||
func (c *oAuthClientMock) Authenticate(_ context.Context) (response.TokenResponse, error) { | ||
return response.TokenResponse{ | ||
AccessToken: "access-token", | ||
InstanceURL: "hxxp://instance.url", | ||
ID: "1", | ||
IssuedAt: "2", | ||
Signature: "3", | ||
}, 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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Copyright © 2022 Meroxa, Inc. and Miquido | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
|
||
sdk "github.com/conduitio/conduit-connector-sdk" | ||
"github.com/miquido/conduit-connector-salesforce/internal/cometd/responses" | ||
) | ||
|
||
type streamingClientMock struct { | ||
results []sdk.Record | ||
lastIndex int | ||
mutex sync.Mutex | ||
} | ||
|
||
func (s *streamingClientMock) SetResults(results []sdk.Record) { | ||
s.mutex.Lock() | ||
s.results = results | ||
s.mutex.Unlock() | ||
} | ||
|
||
func (s *streamingClientMock) Handshake(_ context.Context) (responses.SuccessfulHandshakeResponse, error) { | ||
// Make Handshake always successful | ||
return responses.SuccessfulHandshakeResponse{ | ||
Successful: true, | ||
}, nil | ||
} | ||
|
||
func (s *streamingClientMock) Connect(_ context.Context) (responses.ConnectResponse, error) { | ||
s.mutex.Lock() | ||
|
||
response := responses.ConnectResponse{ | ||
Successful: true, | ||
Events: make([]responses.ConnectResponseEvent, 0, len(s.results)), | ||
} | ||
|
||
for _, record := range s.results { | ||
response.Events = append(response.Events, responses.ConnectResponseEvent{ | ||
Data: responses.ConnectResponseEventData{ | ||
Event: responses.ConnectResponseEventDataMetadata{ | ||
CreatedDate: record.CreatedAt, | ||
ReplayID: s.lastIndex, | ||
}, | ||
SObject: record.Payload.(sdk.StructuredData), | ||
}, | ||
Channel: "MyTopic1", | ||
}) | ||
|
||
s.lastIndex++ | ||
} | ||
|
||
s.results = nil | ||
|
||
s.mutex.Unlock() | ||
|
||
// Make Connect always successful | ||
return response, nil | ||
} | ||
|
||
func (s *streamingClientMock) SubscribeToPushTopic(_ context.Context, pushTopic string) (responses.SubscribeResponse, error) { | ||
// Make SubscribeToPushTopic always successful | ||
return responses.SubscribeResponse{ | ||
Successful: true, | ||
Subscription: []string{pushTopic}, | ||
}, nil | ||
} | ||
|
||
func (s *streamingClientMock) UnsubscribeToPushTopic(ctx context.Context, pushTopic string) (responses.UnsubscribeResponse, error) { | ||
// Make UnsubscribeToPushTopic always successful | ||
return responses.UnsubscribeResponse{ | ||
Successful: true, | ||
}, nil | ||
} | ||
|
||
func (s *streamingClientMock) Disconnect(ctx context.Context) (responses.DisconnectResponse, error) { | ||
// Make Disconnect always successful | ||
return responses.DisconnectResponse{ | ||
Successful: true, | ||
}, 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
Oops, something went wrong.