mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 17:18:52 -06:00
Apply ktlint to uhabits-server
This commit is contained in:
@@ -23,9 +23,9 @@ plugins {
|
||||
application
|
||||
id("kotlin")
|
||||
id("com.github.johnrengelman.shadow") version "7.1.0"
|
||||
id("org.jlleitschuh.gradle.ktlint")
|
||||
}
|
||||
|
||||
|
||||
application {
|
||||
group = "org.isoron.uhabits"
|
||||
version = "0.0.1"
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
package org.isoron.uhabits.sync
|
||||
|
||||
import com.fasterxml.jackson.databind.*
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
|
||||
data class SyncData(
|
||||
val version: Long,
|
||||
|
||||
@@ -19,15 +19,15 @@
|
||||
|
||||
package org.isoron.uhabits.sync.app
|
||||
|
||||
import io.ktor.application.*
|
||||
import io.ktor.http.*
|
||||
import io.ktor.response.*
|
||||
import io.ktor.routing.*
|
||||
import io.prometheus.client.*
|
||||
import io.prometheus.client.exporter.common.*
|
||||
import io.prometheus.client.hotspot.*
|
||||
import java.io.*
|
||||
|
||||
import io.ktor.application.call
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.response.respond
|
||||
import io.ktor.routing.Routing
|
||||
import io.ktor.routing.get
|
||||
import io.prometheus.client.CollectorRegistry
|
||||
import io.prometheus.client.exporter.common.TextFormat
|
||||
import io.prometheus.client.hotspot.DefaultExports
|
||||
import java.io.StringWriter
|
||||
|
||||
fun Routing.metrics(app: SyncApplication) {
|
||||
// Register JVM metrics
|
||||
|
||||
@@ -19,11 +19,13 @@
|
||||
|
||||
package org.isoron.uhabits.sync.app
|
||||
|
||||
import io.ktor.application.*
|
||||
import io.ktor.http.*
|
||||
import io.ktor.response.*
|
||||
import io.ktor.routing.*
|
||||
import org.isoron.uhabits.sync.*
|
||||
import io.ktor.application.call
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.response.respond
|
||||
import io.ktor.routing.Routing
|
||||
import io.ktor.routing.post
|
||||
import org.isoron.uhabits.sync.RegisterReponse
|
||||
import org.isoron.uhabits.sync.ServiceUnavailable
|
||||
|
||||
fun Routing.registration(app: SyncApplication) {
|
||||
post("/register") {
|
||||
|
||||
@@ -19,12 +19,18 @@
|
||||
|
||||
package org.isoron.uhabits.sync.app
|
||||
|
||||
import io.ktor.application.*
|
||||
import io.ktor.http.*
|
||||
import io.ktor.request.*
|
||||
import io.ktor.response.*
|
||||
import io.ktor.routing.*
|
||||
import org.isoron.uhabits.sync.*
|
||||
import io.ktor.application.call
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.request.receive
|
||||
import io.ktor.response.respond
|
||||
import io.ktor.routing.Routing
|
||||
import io.ktor.routing.get
|
||||
import io.ktor.routing.put
|
||||
import io.ktor.routing.route
|
||||
import org.isoron.uhabits.sync.EditConflictException
|
||||
import org.isoron.uhabits.sync.GetDataVersionResponse
|
||||
import org.isoron.uhabits.sync.KeyNotFoundException
|
||||
import org.isoron.uhabits.sync.SyncData
|
||||
|
||||
fun Routing.storage(app: SyncApplication) {
|
||||
route("/db/{key}") {
|
||||
|
||||
@@ -19,13 +19,18 @@
|
||||
|
||||
package org.isoron.uhabits.sync.app
|
||||
|
||||
import io.ktor.application.*
|
||||
import io.ktor.features.*
|
||||
import io.ktor.jackson.*
|
||||
import io.ktor.routing.*
|
||||
import org.isoron.uhabits.sync.repository.*
|
||||
import org.isoron.uhabits.sync.server.*
|
||||
import java.nio.file.*
|
||||
import io.ktor.application.Application
|
||||
import io.ktor.application.install
|
||||
import io.ktor.features.CallLogging
|
||||
import io.ktor.features.ContentNegotiation
|
||||
import io.ktor.features.DefaultHeaders
|
||||
import io.ktor.jackson.jackson
|
||||
import io.ktor.routing.routing
|
||||
import org.isoron.uhabits.sync.repository.FileRepository
|
||||
import org.isoron.uhabits.sync.server.AbstractSyncServer
|
||||
import org.isoron.uhabits.sync.server.RepositorySyncServer
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
|
||||
fun Application.main() = SyncApplication().apply { main() }
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
|
||||
package org.isoron.uhabits.sync.links
|
||||
|
||||
import org.isoron.uhabits.sync.*
|
||||
import org.isoron.uhabits.sync.utils.*
|
||||
import org.isoron.uhabits.sync.KeyNotFoundException
|
||||
import org.isoron.uhabits.sync.utils.randomString
|
||||
|
||||
class LinkManager(
|
||||
private val timeoutInMillis: Long = 900_000,
|
||||
|
||||
@@ -19,9 +19,10 @@
|
||||
|
||||
package org.isoron.uhabits.sync.repository
|
||||
|
||||
import org.isoron.uhabits.sync.*
|
||||
import java.io.*
|
||||
import java.nio.file.*
|
||||
import org.isoron.uhabits.sync.KeyNotFoundException
|
||||
import org.isoron.uhabits.sync.SyncData
|
||||
import java.io.PrintWriter
|
||||
import java.nio.file.Path
|
||||
|
||||
class FileRepository(
|
||||
private val basepath: Path,
|
||||
|
||||
@@ -43,4 +43,3 @@ interface Repository {
|
||||
*/
|
||||
suspend fun contains(key: String): Boolean
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,11 @@
|
||||
|
||||
package org.isoron.uhabits.sync.server
|
||||
|
||||
import org.isoron.uhabits.sync.*
|
||||
import org.isoron.uhabits.sync.links.*
|
||||
import org.isoron.uhabits.sync.EditConflictException
|
||||
import org.isoron.uhabits.sync.KeyNotFoundException
|
||||
import org.isoron.uhabits.sync.ServiceUnavailable
|
||||
import org.isoron.uhabits.sync.SyncData
|
||||
import org.isoron.uhabits.sync.links.Link
|
||||
|
||||
interface AbstractSyncServer {
|
||||
/**
|
||||
|
||||
@@ -19,11 +19,14 @@
|
||||
|
||||
package org.isoron.uhabits.sync.server
|
||||
|
||||
import io.prometheus.client.*
|
||||
import org.isoron.uhabits.sync.*
|
||||
import org.isoron.uhabits.sync.links.*
|
||||
import org.isoron.uhabits.sync.repository.*
|
||||
import org.isoron.uhabits.sync.utils.*
|
||||
import io.prometheus.client.Counter
|
||||
import org.isoron.uhabits.sync.EditConflictException
|
||||
import org.isoron.uhabits.sync.KeyNotFoundException
|
||||
import org.isoron.uhabits.sync.SyncData
|
||||
import org.isoron.uhabits.sync.links.Link
|
||||
import org.isoron.uhabits.sync.links.LinkManager
|
||||
import org.isoron.uhabits.sync.repository.Repository
|
||||
import org.isoron.uhabits.sync.utils.randomString
|
||||
|
||||
/**
|
||||
* An AbstractSyncServer that stores all data in a [Repository].
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
|
||||
package org.isoron.uhabits.sync.utils
|
||||
|
||||
import java.util.*
|
||||
import kotlin.streams.*
|
||||
import java.util.Random
|
||||
import kotlin.streams.asSequence
|
||||
|
||||
fun randomString(length: Long): String {
|
||||
val chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
package org.isoron.uhabits.sync.app
|
||||
|
||||
import com.nhaarman.mockitokotlin2.mock
|
||||
import io.ktor.application.*
|
||||
import org.isoron.uhabits.sync.server.*
|
||||
import io.ktor.application.Application
|
||||
import org.isoron.uhabits.sync.server.AbstractSyncServer
|
||||
|
||||
open class BaseApplicationTest {
|
||||
|
||||
|
||||
@@ -21,12 +21,23 @@ package org.isoron.uhabits.sync.app
|
||||
|
||||
import com.nhaarman.mockitokotlin2.verify
|
||||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import io.ktor.http.*
|
||||
import io.ktor.server.testing.*
|
||||
import kotlinx.coroutines.*
|
||||
import org.isoron.uhabits.sync.*
|
||||
import io.ktor.http.ContentType
|
||||
import io.ktor.http.HttpHeaders
|
||||
import io.ktor.http.HttpMethod
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.server.testing.TestApplicationCall
|
||||
import io.ktor.server.testing.TestApplicationEngine
|
||||
import io.ktor.server.testing.handleRequest
|
||||
import io.ktor.server.testing.setBody
|
||||
import io.ktor.server.testing.withTestApplication
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.isoron.uhabits.sync.EditConflictException
|
||||
import org.isoron.uhabits.sync.GetDataVersionResponse
|
||||
import org.isoron.uhabits.sync.KeyNotFoundException
|
||||
import org.isoron.uhabits.sync.SyncData
|
||||
import org.isoron.uhabits.sync.toJson
|
||||
import org.junit.Test
|
||||
import kotlin.test.*
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class StorageModuleTest : BaseApplicationTest() {
|
||||
private val data1 = SyncData(1, "Hello world")
|
||||
@@ -64,7 +75,6 @@ class StorageModuleTest : BaseApplicationTest() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun `when put succeeds should return OK`(): Unit = runBlocking {
|
||||
withTestApplication(app()) {
|
||||
|
||||
@@ -17,17 +17,18 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
@file:Suppress("BlockingMethodInNonBlockingContext")
|
||||
|
||||
package org.isoron.uhabits.sync.repository
|
||||
|
||||
import kotlinx.coroutines.*
|
||||
import org.hamcrest.CoreMatchers.*
|
||||
import org.isoron.uhabits.sync.*
|
||||
import org.junit.*
|
||||
import org.junit.Assert.*
|
||||
import java.nio.file.*
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.hamcrest.CoreMatchers.equalTo
|
||||
import org.isoron.uhabits.sync.SyncData
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertThat
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import java.nio.file.Files
|
||||
|
||||
class FileRepositoryTest {
|
||||
|
||||
|
||||
@@ -19,12 +19,15 @@
|
||||
|
||||
package org.isoron.uhabits.sync.server
|
||||
|
||||
import kotlinx.coroutines.*
|
||||
import org.isoron.uhabits.sync.*
|
||||
import org.isoron.uhabits.sync.repository.*
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.isoron.uhabits.sync.EditConflictException
|
||||
import org.isoron.uhabits.sync.KeyNotFoundException
|
||||
import org.isoron.uhabits.sync.SyncData
|
||||
import org.isoron.uhabits.sync.repository.FileRepository
|
||||
import org.junit.Test
|
||||
import java.nio.file.*
|
||||
import kotlin.test.*
|
||||
import java.nio.file.Files
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
|
||||
class RepositorySyncServerTest {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user