@@ -7,22 +7,23 @@ import (
77 "github.com/juju/errors"
88 "github.com/stretchr/testify/suite"
99 "github.com/urfave/cli"
10+ "github.com/wallester/migrate/direction"
1011 "github.com/wallester/migrate/file"
1112 "github.com/wallester/migrate/migrator"
1213)
1314
1415type CommanderTestSuite struct {
1516 suite.Suite
1617 migratorMock * migrator.Mock
17- instance Commander
18+ commander Commander
1819 expectedErr error
1920 flagSet * flag.FlagSet
2021 ctx * cli.Context
2122}
2223
2324func (suite * CommanderTestSuite ) SetupTest () {
2425 suite .migratorMock = & migrator.Mock {}
25- suite .instance = New (suite .migratorMock )
26+ suite .commander = New (suite .migratorMock )
2627 suite .expectedErr = errors .New ("failure" )
2728 suite .flagSet = flag .NewFlagSet ("test" , 0 )
2829 suite .ctx = cli .NewContext (nil , suite .flagSet , nil )
@@ -45,7 +46,7 @@ func (suite *CommanderTestSuite) Test_New_ReturnsInstance_InCaseOfSuccess() {
4546
4647func (suite * CommanderTestSuite ) Test_Create_ReturnsError_InCaseOfMissingArgument () {
4748 // Act
48- err := suite .instance .Create (suite .ctx )
49+ err := suite .commander .Create (suite .ctx )
4950
5051 // Assert
5152 suite .NotNil (err )
@@ -59,7 +60,7 @@ func (suite *CommanderTestSuite) Test_Create_ReturnsError_InCaseOfMissingFlag()
5960 }
6061
6162 // Act
62- err := suite .instance .Create (suite .ctx )
63+ err := suite .commander .Create (suite .ctx )
6364
6465 // Assert
6566 suite .NotNil (err )
@@ -76,7 +77,7 @@ func (suite *CommanderTestSuite) Test_Create_ReturnsError_InCaseOfMigratorError(
7677 suite .migratorMock .On ("Create" , "create_table_users" , "testdata" ).Return (pair , suite .expectedErr ).Once ()
7778
7879 // Act
79- err := suite .instance .Create (suite .ctx )
80+ err := suite .commander .Create (suite .ctx )
8081
8182 // Assert
8283 suite .NotNil (err )
@@ -93,15 +94,15 @@ func (suite *CommanderTestSuite) Test_Create_ReturnsNil_InCaseOfSuccess() {
9394 suite .migratorMock .On ("Create" , "create_table_users" , "testdata" ).Return (pair , nil ).Once ()
9495
9596 // Act
96- err := suite .instance .Create (suite .ctx )
97+ err := suite .commander .Create (suite .ctx )
9798
9899 // Assert
99100 suite .Nil (err )
100101}
101102
102103func (suite * CommanderTestSuite ) Test_Up_ReturnError_InCaseOfMissingPath () {
103104 // Act
104- err := suite .instance .Up (suite .ctx )
105+ err := suite .commander .Up (suite .ctx )
105106
106107 // Assert
107108 suite .NotNil (err )
@@ -116,7 +117,7 @@ func (suite *CommanderTestSuite) Test_Up_ReturnError_InCaseOfMissingURL() {
116117 }
117118
118119 // Act
119- err := suite .instance .Up (suite .ctx )
120+ err := suite .commander .Up (suite .ctx )
120121
121122 // Assert
122123 suite .NotNil (err )
@@ -131,10 +132,10 @@ func (suite *CommanderTestSuite) Test_Up_ReturnError_InCaseOfMigratorError() {
131132 if err := suite .flagSet .Parse ([]string {"--path" , "testdata" , "--url" , "connectionurl" , "--timeout" , "10" }); err != nil {
132133 suite .FailNow (err .Error ())
133134 }
134- suite .migratorMock .On ("Migrate" , "testdata" , "connectionurl" , true , 0 , 10 ).Return (suite .expectedErr ).Once ()
135+ suite .migratorMock .On ("Migrate" , "testdata" , "connectionurl" , direction . Up , 0 , 10 ).Return (suite .expectedErr ).Once ()
135136
136137 // Act
137- err := suite .instance .Up (suite .ctx )
138+ err := suite .commander .Up (suite .ctx )
138139
139140 // Assert
140141 suite .NotNil (err )
@@ -150,7 +151,7 @@ func (suite *CommanderTestSuite) Test_Up_ReturnError_InCaseOfInvalidArgument() {
150151 }
151152
152153 // Act
153- err := suite .instance .Up (suite .ctx )
154+ err := suite .commander .Up (suite .ctx )
154155
155156 // Assert
156157 suite .NotNil (err )
@@ -164,10 +165,10 @@ func (suite *CommanderTestSuite) Test_Up_ReturnNil_InCaseOfSuccess() {
164165 if err := suite .flagSet .Parse ([]string {"--path" , "testdata" , "--url" , "connectionurl" }); err != nil {
165166 suite .FailNow (err .Error ())
166167 }
167- suite .migratorMock .On ("Migrate" , "testdata" , "connectionurl" , true , 0 , 1 ).Return (nil ).Once ()
168+ suite .migratorMock .On ("Migrate" , "testdata" , "connectionurl" , direction . Up , 0 , 1 ).Return (nil ).Once ()
168169
169170 // Act
170- err := suite .instance .Up (suite .ctx )
171+ err := suite .commander .Up (suite .ctx )
171172
172173 // Assert
173174 suite .Nil (err )
@@ -180,18 +181,18 @@ func (suite *CommanderTestSuite) Test_Up_ReturnNil_InCaseOfArgumentN() {
180181 if err := suite .flagSet .Parse ([]string {"--path" , "testdata" , "--url" , "connectionurl" , "10" }); err != nil {
181182 suite .FailNow (err .Error ())
182183 }
183- suite .migratorMock .On ("Migrate" , "testdata" , "connectionurl" , true , 10 , 1 ).Return (nil ).Once ()
184+ suite .migratorMock .On ("Migrate" , "testdata" , "connectionurl" , direction . Up , 10 , 1 ).Return (nil ).Once ()
184185
185186 // Act
186- err := suite .instance .Up (suite .ctx )
187+ err := suite .commander .Up (suite .ctx )
187188
188189 // Assert
189190 suite .Nil (err )
190191}
191192
192193func (suite * CommanderTestSuite ) Test_Down_ReturnError_InCaseOfMissingPath () {
193194 // Act
194- err := suite .instance .Down (suite .ctx )
195+ err := suite .commander .Down (suite .ctx )
195196
196197 // Assert
197198 suite .NotNil (err )
@@ -206,7 +207,7 @@ func (suite *CommanderTestSuite) Test_Down_ReturnError_InCaseOfMissingURL() {
206207 }
207208
208209 // Act
209- err := suite .instance .Down (suite .ctx )
210+ err := suite .commander .Down (suite .ctx )
210211
211212 // Assert
212213 suite .NotNil (err )
@@ -220,10 +221,10 @@ func (suite *CommanderTestSuite) Test_Down_ReturnError_InCaseOfMigratorError() {
220221 if err := suite .flagSet .Parse ([]string {"--path" , "testdata" , "--url" , "connectionurl" }); err != nil {
221222 suite .FailNow (err .Error ())
222223 }
223- suite .migratorMock .On ("Migrate" , "testdata" , "connectionurl" , false , 0 , 1 ).Return (suite .expectedErr ).Once ()
224+ suite .migratorMock .On ("Migrate" , "testdata" , "connectionurl" , direction . Down , 0 , 1 ).Return (suite .expectedErr ).Once ()
224225
225226 // Act
226- err := suite .instance .Down (suite .ctx )
227+ err := suite .commander .Down (suite .ctx )
227228
228229 // Assert
229230 suite .NotNil (err )
@@ -237,10 +238,10 @@ func (suite *CommanderTestSuite) Test_Down_ReturnNil_InCaseOfSuccess() {
237238 if err := suite .flagSet .Parse ([]string {"--path" , "testdata" , "--url" , "connectionurl" }); err != nil {
238239 suite .FailNow (err .Error ())
239240 }
240- suite .migratorMock .On ("Migrate" , "testdata" , "connectionurl" , false , 0 , 1 ).Return (nil ).Once ()
241+ suite .migratorMock .On ("Migrate" , "testdata" , "connectionurl" , direction . Down , 0 , 1 ).Return (nil ).Once ()
241242
242243 // Act
243- err := suite .instance .Down (suite .ctx )
244+ err := suite .commander .Down (suite .ctx )
244245
245246 // Assert
246247 suite .Nil (err )
0 commit comments