Skip to content

Commit

Permalink
Merge pull request #183 from davenverse/addSystemCalls
Browse files Browse the repository at this point in the history
Add System Calls
  • Loading branch information
ChristopherDavenport authored Dec 24, 2021
2 parents d2c5281 + d95ed8e commit 18116f0
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
9 changes: 6 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sbtcrossproject.CrossPlugin.autoImport.{crossProject, CrossType}

val catsV = "2.1.1"
val catsV = "2.7.0"
val catsEffectV = "3.3.1"
val fs2V = "3.2.3"
val http4sV = "0.23.7"
Expand Down Expand Up @@ -32,9 +32,9 @@ lazy val examples = project.in(file("examples"))
name := "whale-tail-examples",
libraryDependencies ++= Seq(
"org.typelevel" %% "log4cats-slf4j" % log4catsV,
"ch.qos.logback" % "logback-classic" % "1.2.3",
"ch.qos.logback" % "logback-classic" % "1.2.10",
"org.http4s" %% "http4s-ember-server" % http4sV,
"com.github.jnr" % "jnr-unixsocket" % "0.38.11",
"com.github.jnr" % "jnr-unixsocket" % "0.38.15",
)
)

Expand Down Expand Up @@ -74,6 +74,9 @@ lazy val commonSettings = Seq(

"org.typelevel" %% "log4cats-core" % log4catsV,
"org.typelevel" %% "log4cats-testing" % log4catsV % Test,
"com.github.jnr" % "jnr-unixsocket" % "0.38.15" % Test,

"org.typelevel" %% "cats-effect-testing-specs2" % "1.4.0" % Test,

"org.specs2" %% "specs2-core" % specs2V % Test,
"org.specs2" %% "specs2-scalacheck" % specs2V % Test
Expand Down
20 changes: 20 additions & 0 deletions core/src/main/scala/io/chrisdavenport/whaletail/System.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.chrisdavenport.whaletail

import cats.effect._
import org.http4s._
import org.http4s.client.Client
import io.circe._
import org.http4s.circe._

object System {
object Operations {
def info[F[_]: Concurrent](client: Client[F]): F[Json] =
client.expect[Json](Request[F](Method.GET, Docker.versionPrefix / "info"))

def version[F[_]: Concurrent](client: Client[F]): F[Json] =
client.expect[Json](Request[F](Method.GET, Docker.versionPrefix / "version"))

def ping[F[_]: Concurrent](client: Client[F]): F[Boolean] =
client.successful(Request[F](Method.HEAD, Docker.versionPrefix / "_ping"))
}
}
32 changes: 32 additions & 0 deletions core/src/test/scala/io/chrisdavenport/whaletail/SystemSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.chrisdavenport.whaletail

import org.specs2._
import cats.effect._
import cats.effect.testing.specs2.CatsEffect

object SystemSpec extends mutable.Specification with CatsEffect {

"System" should {
"be able to get info" in {
Docker.client[IO].use(c =>
System.Operations.info(c).attempt
.map(e => e must beRight)
)
}

"be able to get version" in {
Docker.client[IO].use(c =>
System.Operations.version(c).attempt
.map(e => e must beRight)
)
}

"be able to ping" in {
Docker.client[IO].use(c =>
System.Operations.ping(c).attempt
.map(e => e must beRight)
)
}
}

}

0 comments on commit 18116f0

Please sign in to comment.