@@ -61,10 +61,15 @@ class ModelClientV2Test {
61
61
block()
62
62
}
63
63
64
+ private suspend fun ApplicationTestBuilder.createModelClient (): ModelClientV2 {
65
+ val url = " http://localhost/v2"
66
+ val modelClient = ModelClientV2 .builder().url(url).client(client).build().also { it.init () }
67
+ return modelClient
68
+ }
69
+
64
70
@Test
65
71
fun test_t1 () = runTest {
66
- val url = " http://localhost/v2"
67
- val client = ModelClientV2 .builder().url(url).client(client).build().also { it.init () }
72
+ val client = createModelClient()
68
73
69
74
val repositoryId = RepositoryId (" repo1" )
70
75
val initialVersion = client.initRepository(repositoryId)
@@ -101,9 +106,7 @@ class ModelClientV2Test {
101
106
102
107
@Test
103
108
fun modelqlSmokeTest () = runTest {
104
- val url = " http://localhost/v2"
105
- val client = ModelClientV2 .builder().url(url).client(client).build().also { it.init () }
106
-
109
+ val client = createModelClient()
107
110
val repositoryId = RepositoryId (" repo1" )
108
111
val branchRef = repositoryId.getBranchReference()
109
112
val initialVersion = client.initRepository(repositoryId)
@@ -116,9 +119,7 @@ class ModelClientV2Test {
116
119
117
120
@Test
118
121
fun testSlashesInPathSegmentsFromRepositoryIdAndBranchId () = runTest {
119
- val url = " http://localhost/v2"
120
- val client = ModelClientV2 .builder().url(url).client(client).build()
121
- client.init ()
122
+ val client = createModelClient()
122
123
val repositoryId = RepositoryId (" repo/v1" )
123
124
val initialVersion = client.initRepository(repositoryId)
124
125
val branchId = repositoryId.getBranchReference(" my-branch/v1" )
@@ -131,14 +132,7 @@ class ModelClientV2Test {
131
132
132
133
@Test
133
134
fun `user id can be provided to client after creation` () = runTest {
134
- val url = " http://localhost/v2"
135
- val modelClient = ModelClientV2
136
- .builder()
137
- .url(url)
138
- .client(client)
139
- .build()
140
- .also { it.init () }
141
-
135
+ val modelClient = createModelClient()
142
136
val userId = " a_user_id"
143
137
modelClient.setClientProvideUserId(userId)
144
138
@@ -148,23 +142,24 @@ class ModelClientV2Test {
148
142
@Test
149
143
fun `user id provided by client can be removed` () = runTest {
150
144
val url = " http://localhost/v2"
145
+ val userId = " a_user_id"
151
146
val modelClient = ModelClientV2
152
147
.builder()
153
148
.url(url)
154
149
.client(client)
155
- .userId(" a_user_id " )
150
+ .userId(userId )
156
151
.build()
157
- . also { it. init () }
152
+ modelClient. init ()
158
153
154
+ assertEquals(userId, modelClient.getUserId())
159
155
modelClient.setClientProvideUserId(null )
160
156
161
157
assertEquals(" localhost" , modelClient.getUserId())
162
158
}
163
159
164
160
@Test
165
161
fun `newly created repository can be removed` () = runTest {
166
- val url = " http://localhost/v2"
167
- val client = ModelClientV2 .builder().url(url).client(client).build().also { it.init () }
162
+ val client = createModelClient()
168
163
val repositoryId = RepositoryId (UUID .randomUUID().toString())
169
164
client.initRepository(repositoryId)
170
165
@@ -177,8 +172,7 @@ class ModelClientV2Test {
177
172
178
173
@Test
179
174
fun `non-existing repository cannot be removed` () = runTest {
180
- val url = " http://localhost/v2"
181
- val client = ModelClientV2 .builder().url(url).client(client).build().also { it.init () }
175
+ val client = createModelClient()
182
176
val repositoryId = RepositoryId (UUID .randomUUID().toString())
183
177
184
178
val success = client.deleteRepository(repositoryId)
@@ -191,9 +185,8 @@ class ModelClientV2Test {
191
185
@Test
192
186
fun `pulling existing versions pulls all referenced objects` () = runTest {
193
187
// Arrange
194
- val url = " http://localhost/v2"
195
- val modelClientForArrange = ModelClientV2 .builder().url(url).client(client).build().also { it.init () }
196
- val modelClientForAssert = ModelClientV2 .builder().url(url).client(client).build().also { it.init () }
188
+ val modelClientForArrange = createModelClient()
189
+ val modelClientForAssert = createModelClient()
197
190
val repositoryId = RepositoryId (" repo1" )
198
191
val branchId = repositoryId.getBranchReference(" my-branch" )
199
192
modelClientForArrange.runWrite(branchId) { root ->
@@ -221,8 +214,7 @@ class ModelClientV2Test {
221
214
@Test
222
215
fun `writing no data does not create empty versions` () = runTest {
223
216
// Arrange
224
- val url = " http://localhost/v2"
225
- val modelClient = ModelClientV2 .builder().url(url).client(client).build().also { it.init () }
217
+ val modelClient = createModelClient()
226
218
val repositoryId = RepositoryId (" repo1" )
227
219
val branchId = repositoryId.getBranchReference(" master" )
228
220
modelClient.initRepository(repositoryId)
@@ -237,4 +229,26 @@ class ModelClientV2Test {
237
229
val versionAfterRunWrite = modelClient.pullIfExists(branchId)!!
238
230
assertEquals(versionAfterBeforeWrite.getContentHash(), versionAfterRunWrite.getContentHash())
239
231
}
232
+
233
+ @Test
234
+ fun `client can load version` () = runTest {
235
+ val modelClient = createModelClient()
236
+ val repositoryId = RepositoryId (" aRepo" )
237
+ val initialVersion = modelClient.initRepository(repositoryId)
238
+
239
+ val loadedVersion = modelClient.loadVersion(repositoryId, initialVersion.getContentHash(), initialVersion)
240
+
241
+ assertEquals(initialVersion.getContentHash(), loadedVersion.getContentHash())
242
+ }
243
+
244
+ @Test
245
+ fun `client can load version (deprecated endpoint without repository)` () = runTest {
246
+ val modelClient = createModelClient()
247
+ val repositoryId = RepositoryId (" aRepo" )
248
+ val initialVersion = modelClient.initRepository(repositoryId)
249
+
250
+ val loadedVersion = modelClient.loadVersion(initialVersion.getContentHash(), initialVersion)
251
+
252
+ assertEquals(initialVersion.getContentHash(), loadedVersion.getContentHash())
253
+ }
240
254
}
0 commit comments