Skip to content

Commit

Permalink
Patch surreal id with regex
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
pditommaso committed Oct 2, 2024
1 parent 5589965 commit 8778c95
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,15 @@ class SurrealPersistenceService implements PersistenceService {
final json = surrealDb.getContainerRequest(getAuthorization(), token)
log.trace "Container request with token '$token' loaded: ${json}"
final type = new TypeReference<ArrayList<SurrealResult<WaveContainerRecord>>>() {}
final data= json ? JacksonHelper.fromJson(json, type) : null
final data= json ? JacksonHelper.fromJson(patchSurrealId(json,"wave_request"), type) : null
final result = data && data[0].result ? data[0].result[0] : null
return result
}

static protected String patchSurrealId(String json, String table) {
json.replaceFirst(/"id":\s*"${table}:(\w*)"/) { List<String> it-> /"id":"${it[1]}"/ }
}

void createScanRecord(WaveScanRecord scanRecord) {
final result = surrealDb.insertScanRecord(authorization, scanRecord)
log.trace "Scan create result=$result"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ class ViewControllerTest extends Specification {
def token = '12345'
def container = new WaveContainerRecord(req, data, token, wave, addr, exp)


when:
persistenceService.saveContainerRequest(container)
and:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,29 +263,8 @@ class SurrealPersistenceServiceTest extends Specification implements SurrealDBTe

when:
def loaded = persistence.loadContainerRequest(TOKEN)

then:
verifyAll(loaded) {
loaded.id == "wave_request:$request.id" //surrealdb will add table name in front of id
loaded.user == request.user
loaded.workspaceId == request.workspaceId
loaded.containerImage == request.containerImage
loaded.containerConfig == request.containerConfig
loaded.platform == request.platform
loaded.towerEndpoint == request.towerEndpoint
loaded.buildRepository == request.buildRepository
loaded.cacheRepository == request.cacheRepository
loaded.fingerprint == request.fingerprint
loaded.sourceImage == request.sourceImage
loaded.sourceDigest == request.sourceDigest
loaded.waveImage == request.waveImage
loaded.waveDigest == request.waveDigest
loaded.expiration == request.expiration
loaded.buildId == request.buildId
loaded.buildNew == request.buildNew
loaded.freeze == request.freeze
loaded.fusionVersion == request.fusionVersion
}
loaded == request

// should update the record
when:
Expand Down Expand Up @@ -386,5 +365,12 @@ class SurrealPersistenceServiceTest extends Specification implements SurrealDBTe
stored == result
}

def 'should remove surreal table from json' () {
given:
def json = /{"id":"wave_request:1234abc", "this":"one", "that":123 }/
expect:
SurrealPersistenceService.patchSurrealId(json, "wave_request")
== /{"id":"1234abc", "this":"one", "that":123 }/
}

}

0 comments on commit 8778c95

Please sign in to comment.