@@ -138,6 +138,93 @@ func TestResourceRepoCreateNoBranch(t *testing.T) {
138138 assert .Equal (t , resp .HeadCommitID , d .Get ("commit_hash" ))
139139}
140140
141+ func TestResourceRepoCreateCustomDirectory (t * testing.T ) {
142+ resp := ReposInformation {
143+ ID : 121232342 ,
144+ Url : "https://github.com/user/test.git" ,
145+ Provider : "gitHub" ,
146+ Branch : "main" ,
147+ Path : "/Repos/user@domain/test" ,
148+ HeadCommitID : "1124323423abc23424" ,
149+ }
150+ d , err := qa.ResourceFixture {
151+ Fixtures : []qa.HTTPFixture {
152+ {
153+ Method : "POST" ,
154+ Resource : "/api/2.0/repos" ,
155+ ExpectedRequest : createRequest {
156+ Url : "https://github.com/user/test.git" ,
157+ Provider : "gitHub" ,
158+ Path : "/Repos/Production/test/" ,
159+ },
160+ Response : resp ,
161+ },
162+ {
163+ Method : "POST" ,
164+ Resource : "/api/2.0/workspace/mkdirs" ,
165+ ExpectedRequest : map [string ]string {
166+ "path" : "/Repos/Production" ,
167+ },
168+ },
169+ {
170+ Method : "GET" ,
171+ Resource : "/api/2.0/repos/121232342" ,
172+ Response : resp ,
173+ },
174+ },
175+ Resource : ResourceRepo (),
176+ State : map [string ]interface {}{
177+ "url" : "https://github.com/user/test.git" ,
178+ "path" : "/Repos/Production/test/" ,
179+ },
180+ Create : true ,
181+ }.Apply (t )
182+ assert .NoError (t , err , err )
183+ assert .Equal (t , resp .RepoID (), d .Id ())
184+ assert .Equal (t , resp .Branch , d .Get ("branch" ))
185+ assert .Equal (t , resp .Provider , d .Get ("git_provider" ))
186+ assert .Equal (t , resp .Path , d .Get ("path" ))
187+ assert .Equal (t , resp .HeadCommitID , d .Get ("commit_hash" ))
188+ }
189+
190+ func TestResourceRepoCreateCustomDirectoryError (t * testing.T ) {
191+ _ , err := qa.ResourceFixture {
192+ Fixtures : []qa.HTTPFixture {
193+ {
194+ Method : "POST" ,
195+ Resource : "/api/2.0/workspace/mkdirs" ,
196+ ExpectedRequest : map [string ]string {
197+ "path" : "/Repos/Production" ,
198+ },
199+ Response : common.APIErrorBody {
200+ ErrorCode : "INVALID_REQUEST" ,
201+ Message : "Internal error happened" ,
202+ },
203+ Status : 400 ,
204+ },
205+ },
206+ Resource : ResourceRepo (),
207+ State : map [string ]interface {}{
208+ "url" : "https://github.com/user/test.git" ,
209+ "path" : "/Repos/Production/test/" ,
210+ },
211+ Create : true ,
212+ }.Apply (t )
213+ qa .AssertErrorStartsWith (t , err , "Internal error happened" )
214+ }
215+
216+ func TestResourceRepoCreateCustomDirectoryWrongLocation (t * testing.T ) {
217+ _ , err := qa.ResourceFixture {
218+ Resource : ResourceRepo (),
219+ State : map [string ]interface {}{
220+ "url" : "https://github.com/user/test.git" ,
221+ "path" : "/NotRepos/Production/test/" ,
222+ },
223+ Create : true ,
224+ }.Apply (t )
225+ qa .AssertErrorStartsWith (t , err , "path should start with /Repos/" )
226+ }
227+
141228func TestResourceRepoCreateWithBranch (t * testing.T ) {
142229 resp := ReposInformation {
143230 ID : 121232342 ,
0 commit comments