Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
build: add code coverage (#2163)
* Update plugins.sbt

* build: add coverage, imports fixing

* chore: apply fixes

* chore: apply fixes

* chore: apply fixes

* chore: apply fixes

* remove private

* chore: tune down scalafix

* fix UserHandlerSpec warnings

* fix naming

* fix some get methods warnings in admin groups

* complier config changes

* review + formatting fixes

* add few more warn fixes

* revert non-satisfying changes

* update compiler config + some fixes

* silenced twirl templates warnings

* get rid of warnings

* undo two nowarns

Co-authored-by: irinaschubert <irina.schubert@dasch.swiss>
Co-authored-by: Marcin Procyk <marcin.procyk@dasch.swiss>
  • Loading branch information
3 people committed Aug 25, 2022
1 parent 468df8f commit b026442
Show file tree
Hide file tree
Showing 383 changed files with 1,996 additions and 2,383 deletions.
29 changes: 29 additions & 0 deletions .scalafix.conf
@@ -0,0 +1,29 @@
rules = [
OrganizeImports,
RemoveUnused
]

OrganizeImports {
blankLines = Auto
coalesceToWildcardImportThreshold = null
expandRelative = false
groupExplicitlyImportedImplicitsSeparately = false
groupedImports = Explode
groups = [
"*"
"re:(javax?|scala)\\."
"re:(dsp|org.knora)\\."
]
importSelectorsOrder = Ascii
importsOrder = Ascii
preset = DEFAULT
removeUnused = true
}

RemoveUnused {
imports = false
privates = false
locals = false
patternvars = false
params = false
}
5 changes: 5 additions & 0 deletions Makefile
Expand Up @@ -333,6 +333,11 @@ info: ## print out all variables
check: # Run code formating check
@sbt "check"

.PHONY: fmt
fmt: # Run code formating fix
@sbt "fmt"


.PHONY: help
help: ## this help
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort
Expand Down
107 changes: 35 additions & 72 deletions build.sbt
Expand Up @@ -15,7 +15,13 @@ import scala.sys.process.Process
//////////////////////////////////////

// when true enables run cancellation w/o exiting sbt
cancelable in Global := true
// use Ctrl-c to stop current task but not quit SBT
Global / cancelable := true

Global / scalaVersion := Dependencies.ScalaVersion
Global / semanticdbEnabled := true
Global / semanticdbVersion := scalafixSemanticdb.revision
Global / scalafixDependencies += "com.github.liancheng" %% "organize-imports" % "0.6.0"

lazy val aggregatedProjects: Seq[ProjectReference] = Seq(webapi, sipi)

Expand Down Expand Up @@ -51,18 +57,25 @@ lazy val root: Project = Project(id = "root", file("."))
ThisBuild / scmInfo := Some(
ScmInfo(url("https://github.com/dasch-swiss/dsp-api"), "scm:git:git@github.com:dasch-swiss/dsp-api.git")
),
Global / scalaVersion := Dependencies.scalaVersion,
Global / scalaVersion := Dependencies.ScalaVersion,
// use 'git describe' for deriving the version
git.useGitDescribe := true,
// override generated version string because docker hub rejects '+' in tags
ThisBuild / version ~= (_.replace('+', '-')),
// use Ctrl-c to stop current task but not quit SBT
Global / cancelable := true,
publish / skip := true
publish / skip := true
)

addCommandAlias("fmt", "all root/scalafmtSbt root/scalafmtAll")
addCommandAlias("check", "all root/scalafmtSbtCheck root/scalafmtCheckAll")
addCommandAlias("fmt", "; all root/scalafmtSbt root/scalafmtAll; root/scalafixAll")
addCommandAlias("check", "; all root/scalafmtSbtCheck root/scalafmtCheckAll; root/scalafixAll --check")

lazy val customScalacOptions = Seq(
"-feature",
"-unchecked",
"-deprecation",
"-Yresolve-term-conflict:package",
"-Ymacro-annotations",
"-Wunused"
)

//////////////////////////////////////
// DSP's custom SIPI
Expand Down Expand Up @@ -151,7 +164,10 @@ lazy val webapi: Project = Project(id = "webapi", base = file("webapi"))
"-unchecked",
"-deprecation",
"-Yresolve-term-conflict:package",
"-Ymacro-annotations"
"-Ymacro-annotations",
// silence twirl templates unused imports warnings
"-Wconf:src=target/.*:s",
"-Wunused:imports"
),
logLevel := Level.Info,
run / javaOptions := webapiJavaRunOptions,
Expand Down Expand Up @@ -208,7 +224,7 @@ lazy val webapi: Project = Project(id = "webapi", base = file("webapi"))
buildInfoKeys ++= Seq[BuildInfoKey](
name,
version,
"akkaHttp" -> Dependencies.akkaHttpVersion,
"akkaHttp" -> Dependencies.AkkaHttpVersion,
"sipi" -> Dependencies.sipiImage,
"fuseki" -> Dependencies.fusekiImage
),
Expand Down Expand Up @@ -249,13 +265,7 @@ lazy val webapiJavaTestOptions = Seq(
lazy val roleInterface = project
.in(file("dsp-role/interface"))
.settings(
scalacOptions ++= Seq(
"-feature",
"-unchecked",
"-deprecation",
"-Yresolve-term-conflict:package",
"-Ymacro-annotations"
),
scalacOptions ++= customScalacOptions,
name := "roleInterface",
libraryDependencies ++= Dependencies.roleInterfaceLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
Expand All @@ -265,13 +275,7 @@ lazy val roleInterface = project
lazy val roleHandler = project
.in(file("dsp-role/handler"))
.settings(
scalacOptions ++= Seq(
"-feature",
"-unchecked",
"-deprecation",
"-Yresolve-term-conflict:package",
"-Ymacro-annotations"
),
scalacOptions ++= customScalacOptions,
name := "roleHandler",
libraryDependencies ++= Dependencies.roleHandlerLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
Expand All @@ -285,13 +289,7 @@ lazy val roleHandler = project
lazy val roleRepo = project
.in(file("dsp-role/repo"))
.settings(
scalacOptions ++= Seq(
"-feature",
"-unchecked",
"-deprecation",
"-Yresolve-term-conflict:package",
"-Ymacro-annotations"
),
scalacOptions ++= customScalacOptions,
name := "roleRepo",
libraryDependencies ++= Dependencies.roleRepoLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
Expand All @@ -301,13 +299,7 @@ lazy val roleRepo = project
lazy val roleCore = project
.in(file("dsp-role/core"))
.settings(
scalacOptions ++= Seq(
"-feature",
"-unchecked",
"-deprecation",
"-Yresolve-term-conflict:package",
"-Ymacro-annotations"
),
scalacOptions ++= customScalacOptions,
name := "roleCore",
libraryDependencies ++= Dependencies.roleCoreLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
Expand All @@ -319,13 +311,7 @@ lazy val roleCore = project
lazy val userInterface = project
.in(file("dsp-user/interface"))
.settings(
scalacOptions ++= Seq(
"-feature",
"-unchecked",
"-deprecation",
"-Yresolve-term-conflict:package",
"-Ymacro-annotations"
),
scalacOptions ++= customScalacOptions,
name := "userInterface",
libraryDependencies ++= Dependencies.userInterfaceLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
Expand All @@ -335,13 +321,7 @@ lazy val userInterface = project
lazy val userHandler = project
.in(file("dsp-user/handler"))
.settings(
scalacOptions ++= Seq(
"-feature",
"-unchecked",
"-deprecation",
"-Yresolve-term-conflict:package",
"-Ymacro-annotations"
),
scalacOptions ++= customScalacOptions,
name := "userHandler",
libraryDependencies ++= Dependencies.userHandlerLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
Expand All @@ -355,13 +335,7 @@ lazy val userHandler = project
lazy val userRepo = project
.in(file("dsp-user/repo"))
.settings(
scalacOptions ++= Seq(
"-feature",
"-unchecked",
"-deprecation",
"-Yresolve-term-conflict:package",
"-Ymacro-annotations"
),
scalacOptions ++= customScalacOptions,
name := "userRepo",
libraryDependencies ++= Dependencies.userRepoLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
Expand All @@ -371,13 +345,7 @@ lazy val userRepo = project
lazy val userCore = project
.in(file("dsp-user/core"))
.settings(
scalacOptions ++= Seq(
"-feature",
"-unchecked",
"-deprecation",
"-Yresolve-term-conflict:package",
"-Ymacro-annotations"
),
scalacOptions ++= customScalacOptions,
name := "userCore",
libraryDependencies ++= Dependencies.userCoreLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
Expand All @@ -389,13 +357,7 @@ lazy val userCore = project
lazy val schemaCore = project
.in(file("dsp-schema/core"))
.settings(
scalacOptions ++= Seq(
"-feature",
"-unchecked",
"-deprecation",
"-Yresolve-term-conflict:package",
"-Ymacro-annotations"
),
scalacOptions ++= customScalacOptions,
name := "schemaCore",
libraryDependencies ++= Dependencies.schemaCoreLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
Expand All @@ -407,6 +369,7 @@ lazy val schemaCore = project
lazy val shared = project
.in(file("dsp-shared"))
.settings(
scalacOptions ++= customScalacOptions,
name := "shared",
libraryDependencies ++= Dependencies.sharedLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
Expand Down
5 changes: 3 additions & 2 deletions dsp-role/core/src/main/scala/dsp/role/api/RoleRepo.scala
Expand Up @@ -5,11 +5,12 @@

package dsp.role.api

import dsp.role.domain.Role
import dsp.valueobjects.Id.RoleId
import zio._
import zio.macros.accessible

import dsp.role.domain.Role
import dsp.valueobjects.Id.RoleId

/**
* The trait (interface) for the role repository.
* The role repository is responsible for storing and retrieving roles.
Expand Down
Expand Up @@ -5,12 +5,13 @@

package dsp.role.domain

import zio.prelude.Validation

import dsp.errors.BadRequestException
import dsp.valueobjects.Id.RoleId
import dsp.valueobjects.Id.UserId
import dsp.valueobjects.Permission
import dsp.valueobjects.Role._
import zio.prelude.Validation

case class RoleUser(
id: UserId
Expand Down
Expand Up @@ -5,11 +5,12 @@

package dsp.role.domain

import zio.test._

import dsp.role.sharedtestdata.RoleTestData
import dsp.valueobjects.Id
import dsp.valueobjects.Permission
import dsp.valueobjects.Role._
import zio.test._

/**
* This spec is used to test [[RoleDomain]].
Expand Down
Expand Up @@ -5,6 +5,9 @@

package dsp.role.handler

import zio.ZIO
import zio._

import dsp.errors.NotFoundException
import dsp.errors.RequestRejectedException
import dsp.role.api.RoleRepo
Expand All @@ -13,8 +16,6 @@ import dsp.role.domain.RoleUser
import dsp.valueobjects.Id.RoleId
import dsp.valueobjects.Permission
import dsp.valueobjects.Role._
import zio.ZIO
import zio._

/**
* The role handler.
Expand Down
Expand Up @@ -5,19 +5,13 @@

package dsp.role.handler

import dsp.errors.NotFoundException
import dsp.errors.RequestRejectedException
import dsp.role.api.RoleRepo
import dsp.role.domain.Role
import dsp.role.domain.RoleUser
import zio.ZIO
import zio.test._

import dsp.role.repo.impl.RoleRepoMock
import dsp.role.sharedtestdata.RoleTestData
import dsp.valueobjects.Id.RoleId
import dsp.valueobjects.Permission
import dsp.valueobjects.Role._
import zio.ZIO
import zio._
import zio.test._

/**
* This spec is used to test [[RoleHandler]]
Expand Down Expand Up @@ -185,8 +179,8 @@ object RoleHandlerSpec extends ZIOSpecDefault {
permission1
)

deletedRoleId <- handler.deleteRole(roleId)
roles <- handler.getRoles()
_ <- handler.deleteRole(roleId)
roles <- handler.getRoles()
} yield assertTrue(roles.size == 0)
}
}.provide(RoleRepoMock.layer, RoleHandler.layer)
Expand Down
Expand Up @@ -5,14 +5,15 @@

package dsp.role.repo.impl

import dsp.role.api.RoleRepo
import dsp.role.domain.Role
import dsp.valueobjects.Id.RoleId
import zio._
import zio.stm.TMap

import java.util.UUID

import dsp.role.api.RoleRepo
import dsp.role.domain.Role
import dsp.valueobjects.Id.RoleId

/**
* Role repo live implementation.
*
Expand Down Expand Up @@ -54,8 +55,8 @@ final case class RoleRepoLive(
*/
override def deleteRole(id: RoleId): IO[Option[Nothing], RoleId] =
(for {
role <- roles.get(id.uuid).some
_ <- roles.delete(id.uuid)
_ <- roles.get(id.uuid).some
_ <- roles.delete(id.uuid)
} yield id).commit.tap(_ => ZIO.logInfo(s"Deleted role: ${id.uuid}"))
}

Expand Down
Expand Up @@ -5,13 +5,13 @@

package dsp.role.repo.impl

import zio.test.Assertion._
import zio.test._

import dsp.role.api.RoleRepo
import dsp.role.repo.impl.RoleRepoLive
import dsp.role.repo.impl.RoleRepoMock
import dsp.role.sharedtestdata.RoleTestData
import zio._
import zio.test.Assertion._
import zio.test._

/**
* This spec is used to test all [[RoleRepo]] implementations.
Expand Down

0 comments on commit b026442

Please sign in to comment.