-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added new source set for integration tests * Implemented database integration tests * Fixed issues related to undocumented API updates * Minor upgrades and improvements
- Loading branch information
Showing
9 changed files
with
670 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
package com.jeliuc.turso.sdk | ||
|
||
import com.jeliuc.turso.sdk.model.ConfigurationResponse | ||
import com.jeliuc.turso.sdk.model.CreateDatabase | ||
import com.jeliuc.turso.sdk.model.CreateDatabaseResponse | ||
import com.jeliuc.turso.sdk.model.DatabaseUsageResponse | ||
import com.jeliuc.turso.sdk.model.DeleteDatabaseResponse | ||
import com.jeliuc.turso.sdk.model.InstanceResponse | ||
import com.jeliuc.turso.sdk.model.ListDatabasesResponse | ||
import com.jeliuc.turso.sdk.model.ListInstancesResponse | ||
import com.jeliuc.turso.sdk.model.RetrieveDatabaseResponse | ||
import com.jeliuc.turso.sdk.model.StatsResponse | ||
import com.jeliuc.turso.sdk.model.UpdateConfigurationRequest | ||
import com.jeliuc.turso.sdk.resource.databases | ||
import io.ktor.client.engine.cio.CIO | ||
import kotlinx.coroutines.runBlocking | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertIs | ||
import kotlin.test.assertNotNull | ||
import kotlin.test.assertTrue | ||
|
||
class DatabasesIntegrationTest { | ||
val token by lazy { | ||
System.getenv("TURSO_TOKEN") | ||
} | ||
|
||
val organization by lazy { | ||
System.getenv("TURSO_ORGANIZATION") | ||
} | ||
|
||
val group = "default" | ||
|
||
val newDatabaseName = "integration-test-db" | ||
|
||
/** | ||
* Manipulate Databases suite | ||
* | ||
* * Creates new database | ||
* * List databases and find in list newly created database | ||
* * Retrieve database by name | ||
* * Retrieve configuration | ||
* * Update configuration | ||
* * Retrieve usage | ||
* * Stats | ||
* * List instances | ||
* * Retrieve instance | ||
* * Delete database | ||
* | ||
*/ | ||
@Test | ||
fun `can manipulate database`() { | ||
val client = TursoClient.using(CIO.create(), token) | ||
|
||
val newDatabase = | ||
CreateDatabase( | ||
name = newDatabaseName, | ||
group = group, | ||
isSchema = false, | ||
sizeLimit = "2M", | ||
) | ||
|
||
val createDatabaseResponse = | ||
runBlocking { | ||
client.databases.create( | ||
organization, | ||
newDatabase, | ||
) | ||
} | ||
|
||
assertIs<CreateDatabaseResponse>(createDatabaseResponse, "Not create database response") | ||
|
||
val listOfAvailableDatabases = | ||
runBlocking { | ||
client.databases.list(organization) | ||
} | ||
|
||
assertIs<ListDatabasesResponse>(listOfAvailableDatabases, "Not list databases response") | ||
assertNotNull(listOfAvailableDatabases.databases.firstOrNull { it.name == newDatabaseName }, "New database is not in the list") | ||
|
||
val retrievedResponse = | ||
runBlocking { | ||
client.databases.retrieve( | ||
organization, | ||
newDatabaseName, | ||
) | ||
} | ||
|
||
assertIs<RetrieveDatabaseResponse>(retrievedResponse, "Not retrieve database response") | ||
assertEquals(newDatabaseName, retrievedResponse.database.name, "Incorrect db name retrieved") | ||
|
||
val configuration = | ||
runBlocking { | ||
client.databases.retrieveConfiguration(organization, newDatabaseName) | ||
} | ||
|
||
assertIs<ConfigurationResponse>(configuration, "Not a configuration response") | ||
|
||
val configurationUpdate = | ||
UpdateConfigurationRequest( | ||
blockReads = false, | ||
blockWrites = false, | ||
sizeLimit = "1M", | ||
allowAttach = false, | ||
) | ||
|
||
val updateConfigurationResponse = | ||
runBlocking { | ||
client.databases.updateConfiguration(organization, newDatabaseName, configurationUpdate) | ||
} | ||
|
||
assertIs<ConfigurationResponse>(updateConfigurationResponse, "Not a configuration update response") | ||
|
||
val retrievedConfiguration = | ||
runBlocking { | ||
client.databases.retrieveConfiguration( | ||
organization, | ||
newDatabaseName, | ||
) | ||
} | ||
|
||
assertIs<ConfigurationResponse>(retrievedConfiguration, "No a configuration response") | ||
|
||
val retrievedUsage = | ||
runBlocking { | ||
client.databases.usage( | ||
organization, | ||
newDatabaseName, | ||
) | ||
} | ||
|
||
assertIs<DatabaseUsageResponse>(retrievedUsage, "Not a usage response") | ||
|
||
val statsResponse = | ||
runBlocking { | ||
client.databases.stats(organization, newDatabaseName) | ||
} | ||
|
||
assertIs<StatsResponse>(statsResponse, "Not a stats response") | ||
|
||
val instances = | ||
runBlocking { | ||
client.databases.listInstances( | ||
organization, | ||
newDatabaseName, | ||
) | ||
} | ||
|
||
assertIs<ListInstancesResponse>(instances, "Can't deserialize list instances response") | ||
assertTrue(instances.instances.size > 0, "Zero instances") | ||
|
||
val instanceName = instances.instances.first()!!.name | ||
val retrievedInstance = | ||
runBlocking { | ||
client.databases.retrieveInstance( | ||
organization, | ||
newDatabaseName, | ||
instanceName, | ||
) | ||
} | ||
|
||
assertIs<InstanceResponse>(retrievedInstance, "Not an instance response") | ||
|
||
val deleteResponse = | ||
runBlocking { | ||
client.databases.delete( | ||
organization, | ||
newDatabaseName, | ||
) | ||
} | ||
|
||
assertIs<DeleteDatabaseResponse>(deleteResponse, "Not a delete response") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1 @@ | ||
{ | ||
"database": { | ||
"uuid": "0eb771dd-6906-11ee-8553-eaa7715aeaf2", | ||
"instances": [ | ||
{ | ||
"uuid": "cd831986-94e5-11ee-a6fe-7a52e1f7759a", | ||
"usage": { | ||
"rows_read": 0, | ||
"rows_written": 0, | ||
"storage_bytes": 4096 | ||
} | ||
}, | ||
{ | ||
"uuid": "0be90471-6906-11ee-8553-eaa7715aeaf2", | ||
"usage": { | ||
"rows_read": 0, | ||
"rows_written": 0, | ||
"storage_bytes": 4096 | ||
} | ||
} | ||
], | ||
"total": { | ||
"rows_read": 0, | ||
"rows_written": 0, | ||
"storage_bytes": 8192 | ||
} | ||
} | ||
} | ||
{"database":{"uuid":"4f0d8f65-e2e8-4ce8-8af5-6da211188b35","instances":[{"uuid":"9f182703-bfd7-11ee-897f-822b15a0bd8c","usage":{"rows_read":0,"rows_written":0,"storage_bytes":4096,"bytes_synced":0}}],"usage":{"rows_read":0,"rows_written":0,"storage_bytes":4096,"bytes_synced":0}},"instances":{"9f182703-bfd7-11ee-897f-822b15a0bd8c":{"rows_read":0,"rows_written":0,"storage_bytes":4096,"bytes_synced":0}},"total":{"rows_read":0,"rows_written":0,"storage_bytes":4096,"bytes_synced":0}} |
Oops, something went wrong.