@@ -78,3 +78,41 @@ func TestNextSeq(t *testing.T) {
78
78
})
79
79
}
80
80
}
81
+
82
+ func TestNumDownFromArgs (t * testing.T ) {
83
+ cases := []struct {
84
+ name string
85
+ args []string
86
+ applyAll bool
87
+ expectedNeedConfirm bool
88
+ expectedNum int
89
+ expectedErrStr string
90
+ }{
91
+ {"no args" , []string {}, false , true , - 1 , "" },
92
+ {"down all" , []string {}, true , false , - 1 , "" },
93
+ {"down 5" , []string {"5" }, false , false , 5 , "" },
94
+ {"down N" , []string {"N" }, false , false , 0 , "can't read limit argument N" },
95
+ {"extra arg after -all" , []string {"5" }, true , false , 0 , "-all cannot be used with other arguments" },
96
+ {"extra arg before -all" , []string {"5" , "-all" }, false , false , 0 , "too many arguments" },
97
+ }
98
+ for _ , c := range cases {
99
+ t .Run (c .name , func (t * testing.T ) {
100
+ num , needsConfirm , err := numDownMigrationsFromArgs (c .applyAll , c .args )
101
+ if needsConfirm != c .expectedNeedConfirm {
102
+ t .Errorf ("Incorrect needsConfirm was: %v wanted %v" , needsConfirm , c .expectedNeedConfirm )
103
+ }
104
+
105
+ if num != c .expectedNum {
106
+ t .Errorf ("Incorrect num was: %v wanted %v" , num , c .expectedNum )
107
+ }
108
+
109
+ if err != nil {
110
+ if err .Error () != c .expectedErrStr {
111
+ t .Error ("Incorrect error: " + err .Error () + " != " + c .expectedErrStr )
112
+ }
113
+ } else if c .expectedErrStr != "" {
114
+ t .Error ("Expected error: " + c .expectedErrStr + " but got nil instead" )
115
+ }
116
+ })
117
+ }
118
+ }
0 commit comments