Skip to content

Commit

Permalink
test(acceptance): add acceptance tests (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
donatorsky authored Jul 7, 2022
1 parent 13fed93 commit 8b230b7
Show file tree
Hide file tree
Showing 12 changed files with 419 additions and 129 deletions.
87 changes: 87 additions & 0 deletions cmd/sf/acceptance_test.go
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,
})
}
6 changes: 5 additions & 1 deletion cmd/sf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@ import (
)

func main() {
sdk.Serve(sf.Specification, sfSource.NewSource, nil)
sdk.Serve(sdk.Connector{
NewSpecification: sf.Specification,
NewSource: sfSource.NewSource,
NewDestination: nil,
})
}
34 changes: 34 additions & 0 deletions cmd/sf/oauth_client_mock_test.go
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
}
95 changes: 95 additions & 0 deletions cmd/sf/streaming_client_mock_test.go
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
}
11 changes: 7 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,37 @@ module github.com/miquido/conduit-connector-salesforce
go 1.18

require (
github.com/conduitio/conduit-connector-sdk v0.2.0
github.com/conduitio/conduit-connector-sdk v0.2.1-0.20220608071937-511c321558fc
github.com/jaswdr/faker v1.12.0
github.com/sigmavirus24/gobayeux v1.0.0
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.8.0
golang.org/x/net v0.0.0-20220531201128-c960675eff93
gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637
)

require (
github.com/conduitio/conduit-connector-protocol v0.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/hashicorp/go-hclog v1.2.0 // indirect
github.com/hashicorp/go-plugin v1.4.4 // indirect
github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/matryer/is v1.4.0 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rs/zerolog v1.26.1 // indirect
github.com/rs/zerolog v1.27.0 // indirect
go.buf.build/library/go-grpc/conduitio/conduit-connector-protocol v1.4.1 // indirect
go.uber.org/goleak v1.1.12 // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/genproto v0.0.0-20220601144221-27df5f98adab // indirect
google.golang.org/grpc v1.47.0 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 8b230b7

Please sign in to comment.