@@ -32,69 +32,75 @@ func WipSpec(ctx context.Context, urlStr string) func(c convey.C) {
3232 convey .So (respResult .JSON200 , convey .ShouldHaveLength , 0 )
3333 })
3434
35- c .Convey ("create wip" , func (c convey.C ) {
35+ createWip (ctx , c , client , "create main wip" , userName , repoName , "main" )
36+
37+ c .Convey ("get wip" , func (c convey.C ) {
3638 c .Convey ("no auth" , func () {
3739 re := client .RequestEditors
3840 client .RequestEditors = nil
39- resp , err := client .CreateWip (ctx , userName , repoName , & api.CreateWipParams {
41+ resp , err := client .GetWip (ctx , userName , repoName , & api.GetWipParams {
4042 RefName : branchName ,
4143 })
4244 client .RequestEditors = re
4345 convey .So (err , convey .ShouldBeNil )
4446 convey .So (resp .StatusCode , convey .ShouldEqual , http .StatusUnauthorized )
4547 })
4648
47- c .Convey ("fail to create branch in non exit repo " , func () {
48- resp , err := client .CreateWip (ctx , userName , "fakerepo" , & api.CreateWipParams {
49+ c .Convey ("auto create a wip " , func () {
50+ resp , err := client .GetWip (ctx , userName , repoName , & api.GetWipParams {
4951 RefName : branchName ,
5052 })
5153 convey .So (err , convey .ShouldBeNil )
52- convey .So (resp .StatusCode , convey .ShouldEqual , http .StatusNotFound )
54+ convey .So (resp .StatusCode , convey .ShouldEqual , http .StatusCreated )
55+
56+ _ , err = api .ParseGetWipResponse (resp )
57+ convey .So (err , convey .ShouldBeNil )
5358 })
5459
55- c .Convey ("fail to create branch in non exit user " , func () {
56- resp , err := client .CreateWip (ctx , "mock_user" , "main" , & api.CreateWipParams {
60+ c .Convey ("success get wip " , func () {
61+ resp , err := client .GetWip (ctx , userName , repoName , & api.GetWipParams {
5762 RefName : branchName ,
5863 })
5964 convey .So (err , convey .ShouldBeNil )
60- convey .So (resp .StatusCode , convey .ShouldEqual , http .StatusNotFound )
65+ convey .So (resp .StatusCode , convey .ShouldEqual , http .StatusOK )
66+
67+ _ , err = api .ParseGetWipResponse (resp )
68+ convey .So (err , convey .ShouldBeNil )
6169 })
6270
63- c .Convey ("fail to create branch in non exit ref" , func () {
64- resp , err := client .CreateWip (ctx , userName , repoName , & api.CreateWipParams {
65- RefName : "mock ref " ,
71+ c .Convey ("fail to get wip in non exit ref" , func () {
72+ resp , err := client .GetWip (ctx , userName , repoName , & api.GetWipParams {
73+ RefName : "mock_ref " ,
6674 })
6775 convey .So (err , convey .ShouldBeNil )
6876 convey .So (resp .StatusCode , convey .ShouldEqual , http .StatusNotFound )
6977 })
7078
71- c .Convey ("forbidden create branch in others " , func () {
72- resp , err := client .CreateWip (ctx , "jimmy " , "happygo" , & api.CreateWipParams {
73- RefName : "main" ,
79+ c .Convey ("fail to get wip from non exit user " , func () {
80+ resp , err := client .GetWip (ctx , "mock_owner " , repoName , & api.GetWipParams {
81+ RefName : branchName ,
7482 })
7583 convey .So (err , convey .ShouldBeNil )
76- convey .So (resp .StatusCode , convey .ShouldEqual , http .StatusForbidden )
84+ convey .So (resp .StatusCode , convey .ShouldEqual , http .StatusNotFound )
7785 })
7886
79- c .Convey ("success create branch" , func () {
80- resp , err := client .CreateWip (ctx , userName , repoName , & api.CreateWipParams {
87+ c .Convey ("fail to get non exit branch" , func () {
88+ resp , err := client .GetWip (ctx , userName , "mock_repo" , & api.GetWipParams {
8189 RefName : branchName ,
8290 })
8391 convey .So (err , convey .ShouldBeNil )
84- convey .So (resp .StatusCode , convey .ShouldEqual , http .StatusCreated )
92+ convey .So (resp .StatusCode , convey .ShouldEqual , http .StatusNotFound )
8593 })
8694
87- c .Convey ("user only have one wip for one userName " , func () {
88- resp , err := client .CreateWip (ctx , userName , repoName , & api.CreateWipParams {
89- RefName : branchName ,
95+ c .Convey ("fail to others repo's wips " , func () {
96+ resp , err := client .GetWip (ctx , "jimmy" , "happygo" , & api.GetWipParams {
97+ RefName : "main" ,
9098 })
9199 convey .So (err , convey .ShouldBeNil )
92- convey .So (resp .StatusCode , convey .ShouldEqual , http .StatusBadRequest )
100+ convey .So (resp .StatusCode , convey .ShouldEqual , http .StatusForbidden )
93101 })
94102 })
95103
96- createWip (ctx , c , client , "create main wip" , userName , repoName , "main" )
97-
98104 c .Convey ("list wip" , func (c convey.C ) {
99105 c .Convey ("no auth" , func () {
100106 re := client .RequestEditors
@@ -134,62 +140,6 @@ func WipSpec(ctx context.Context, urlStr string) func(c convey.C) {
134140 })
135141 })
136142
137- c .Convey ("get wip" , func (c convey.C ) {
138- c .Convey ("no auth" , func () {
139- re := client .RequestEditors
140- client .RequestEditors = nil
141- resp , err := client .GetWip (ctx , userName , repoName , & api.GetWipParams {
142- RefName : branchName ,
143- })
144- client .RequestEditors = re
145- convey .So (err , convey .ShouldBeNil )
146- convey .So (resp .StatusCode , convey .ShouldEqual , http .StatusUnauthorized )
147- })
148-
149- c .Convey ("success get branch" , func () {
150- resp , err := client .GetWip (ctx , userName , repoName , & api.GetWipParams {
151- RefName : branchName ,
152- })
153- convey .So (err , convey .ShouldBeNil )
154- convey .So (resp .StatusCode , convey .ShouldEqual , http .StatusOK )
155-
156- _ , err = api .ParseGetWipResponse (resp )
157- convey .So (err , convey .ShouldBeNil )
158- })
159-
160- c .Convey ("fail to get wip in non exit ref" , func () {
161- resp , err := client .GetWip (ctx , userName , repoName , & api.GetWipParams {
162- RefName : "mock_ref" ,
163- })
164- convey .So (err , convey .ShouldBeNil )
165- convey .So (resp .StatusCode , convey .ShouldEqual , http .StatusNotFound )
166- })
167-
168- c .Convey ("fail to get wip from non exit user" , func () {
169- resp , err := client .GetWip (ctx , "mock_owner" , repoName , & api.GetWipParams {
170- RefName : branchName ,
171- })
172- convey .So (err , convey .ShouldBeNil )
173- convey .So (resp .StatusCode , convey .ShouldEqual , http .StatusNotFound )
174- })
175-
176- c .Convey ("fail to get non exit branch" , func () {
177- resp , err := client .GetWip (ctx , userName , "mock_repo" , & api.GetWipParams {
178- RefName : branchName ,
179- })
180- convey .So (err , convey .ShouldBeNil )
181- convey .So (resp .StatusCode , convey .ShouldEqual , http .StatusNotFound )
182- })
183-
184- c .Convey ("fail to others repo's wips" , func () {
185- resp , err := client .GetWip (ctx , "jimmy" , "happygo" , & api.GetWipParams {
186- RefName : "main" ,
187- })
188- convey .So (err , convey .ShouldBeNil )
189- convey .So (resp .StatusCode , convey .ShouldEqual , http .StatusForbidden )
190- })
191- })
192-
193143 c .Convey ("delete wip" , func (c convey.C ) {
194144 c .Convey ("no auth" , func () {
195145 re := client .RequestEditors
@@ -234,7 +184,7 @@ func WipSpec(ctx context.Context, urlStr string) func(c convey.C) {
234184 //ensure delete work
235185 getResp , err := client .GetWip (ctx , userName , repoName , & api.GetWipParams {RefName : branchNameForDelete })
236186 convey .So (err , convey .ShouldBeNil )
237- convey .So (getResp .StatusCode , convey .ShouldEqual , http .StatusNotFound )
187+ convey .So (getResp .StatusCode , convey .ShouldEqual , http .StatusCreated )
238188 })
239189 })
240190 }
0 commit comments