Skip to content

Commit

Permalink
chore : add tests for restarting connector and task error conditions (#…
Browse files Browse the repository at this point in the history
…56)

* add tests for error conditions

Signed-off-by: Mark deVilliers <markdevilliers@gmail.com>

* tweak tests

Signed-off-by: Mark deVilliers <markdevilliers@gmail.com>

* fix test

Signed-off-by: Mark deVilliers <markdevilliers@gmail.com>
  • Loading branch information
mdevilliers authored Mar 5, 2020
1 parent fb46793 commit 009df4b
Showing 1 changed file with 72 additions and 3 deletions.
75 changes: 72 additions & 3 deletions pkg/manager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/require"
)

func Test_MissingConnectorsAreAdded(t *testing.T) {
func Test_Manage_MissingConnectorsAreAdded(t *testing.T) {

createCalled := false

Expand Down Expand Up @@ -44,7 +44,7 @@ func Test_MissingConnectorsAreAdded(t *testing.T) {

}

func Test_ExistingConnectorsAreRemovedIfNotListed(t *testing.T) {
func Test_Manage_ExistingConnectorsAreRemovedIfNotListed(t *testing.T) {

deleteCalled := false

Expand Down Expand Up @@ -74,7 +74,7 @@ func Test_ExistingConnectorsAreRemovedIfNotListed(t *testing.T) {

}

func Test_ManageErrorsAreAPIErrorsIfUnwrapped(t *testing.T) {
func Test_Manage_ErrorsAreAPIErrorsIfUnwrapped(t *testing.T) {

mock := &mocks.FakeClient{
GetConnectorStub: func(string) (*connect.Connector, *http.Response, error) {
Expand All @@ -97,3 +97,72 @@ func Test_ManageErrorsAreAPIErrorsIfUnwrapped(t *testing.T) {
rootCause := errors.Cause(err)
require.True(t, connect.IsAPIError(rootCause))
}

func Test_Manage_ConnectorRunning_FailedTasksAreRestarted(t *testing.T) {

mock := &mocks.FakeClient{
GetConnectorStatusStub: func(string) (*connect.ConnectorStatus, *http.Response, error) {
return &connect.ConnectorStatus{
Connector: connect.ConnectorState{
State: "RUNNING",
},
Tasks: []connect.TaskState{
connect.TaskState{
State: "FAILED",
},
},
}, nil, nil
}}

config := &Config{
AutoRestart: true,
}

cm, err := NewConnectorsManager(mock, config)
require.Nil(t, err)

source := func() ([]connect.Connector, error) {
return []connect.Connector{
connect.Connector{Name: "foo"},
}, nil
}

err = cm.Sync(source)
require.Nil(t, err)
require.Equal(t, mock.RestartConnectorTaskCallCount(), 1)
}

func Test_Manage_ConnectorFailed_IsRestarted(t *testing.T) {

mock := &mocks.FakeClient{
GetConnectorStatusStub: func(string) (*connect.ConnectorStatus, *http.Response, error) {
return &connect.ConnectorStatus{
Connector: connect.ConnectorState{
State: "FAILED",
},
Tasks: []connect.TaskState{
connect.TaskState{
State: "FAILED",
},
},
}, nil, nil
},
}

config := &Config{
AutoRestart: true,
}

cm, err := NewConnectorsManager(mock, config)
require.Nil(t, err)

source := func() ([]connect.Connector, error) {
return []connect.Connector{
connect.Connector{Name: "foo"},
}, nil
}

err = cm.Sync(source)
require.Nil(t, err)
require.Equal(t, mock.RestartConnectorCallCount(), 1)
}

0 comments on commit 009df4b

Please sign in to comment.