Skip to content

Commit

Permalink
Test DeleteListOfCredentials
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Duchesne committed Jul 21, 2019
1 parent becd438 commit 3ce9bad
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions sync/target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,41 @@ import (
"github.com/golang/mock/gomock"
)

func setSourceMock(t *testing.T, config *Configuration) *credentials.MockSource {
func setSourceMock(t *testing.T, config *Configuration) (*gomock.Controller, *credentials.MockSource) {
ctrl := gomock.NewController(t)
source := credentials.NewMockSource(ctrl)
sourceCollection := credentials.NewMockSourceCollection(ctrl)
sourceCollection.EXPECT().AllSources().Return([]credentials.Source{source}).AnyTimes()

config.SetSources(sourceCollection)
return source
return ctrl, source
}

func setTargetMock(t *testing.T, config *Configuration) *targets.MockTarget {
func setTargetMock(t *testing.T, config *Configuration) (*gomock.Controller, *targets.MockTarget) {
ctrl := gomock.NewController(t)
target := targets.NewMockTarget(ctrl)
targetCollection := targets.NewMockTargetCollection(ctrl)
targetCollection.EXPECT().AllTargets().Return([]targets.Target{target}).AnyTimes()

config.SetTargets(targetCollection)
return target
return ctrl, target
}

func TestDeleteListOfCredentials(t *testing.T) {
config := &Configuration{}
config := &Configuration{
CredentialsToDelete: []string{"test1", "test-not-exist"},
}
setSourceMock(t, config)
target := setTargetMock(t, config)
target.EXPECT().GetExistingCredentials().Return([]string{"test123"}).AnyTimes()
targetController, target := setTargetMock(t, config)
defer targetController.Finish()

// The existing creds is only `test1`
target.EXPECT().GetExistingCredentials().Return([]string{"test1"}).AnyTimes()
// Does not assert on GetName
target.EXPECT().GetName().Return("").AnyTimes()
// Asserts that DeleteCredentials is called with `test1`
target.EXPECT().DeleteCredentials("test1").Return(nil)

config.DeleteListOfCredentials(target)

target.EXPECT().DeleteCredentials("test123").Return(nil)
}

0 comments on commit 3ce9bad

Please sign in to comment.