Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Coverage for client defs (Second Round) #58

Merged
merged 2 commits into from
Oct 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rpc/src/main/scala/client/ChannelConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import freestyle.rpc.client._
import io.grpc._

sealed trait ManagedChannelFor extends Product with Serializable
case class ManagedChannelForAddress(name: String, port: Int) extends ManagedChannelFor
case class ManagedChannelForAddress(host: String, port: Int) extends ManagedChannelFor
case class ManagedChannelForTarget(target: String) extends ManagedChannelFor

sealed trait ManagedChannelConfig extends Product with Serializable
Expand Down
60 changes: 0 additions & 60 deletions rpc/src/main/scala/client/ClientCallsM.scala

This file was deleted.

74 changes: 0 additions & 74 deletions rpc/src/main/scala/client/handlers/ClientCallsMHandler.scala

This file was deleted.

47 changes: 47 additions & 0 deletions rpc/src/test/scala/client/ChannelConfigTests.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2017 47 Degrees, LLC. <http://www.47deg.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package freestyle.rpc
package client

import cats.instances.try_._
import freestyle._
import freestyle.implicits._
import freestyle.config.implicits._

import scala.util.{Success, Try}

class ChannelConfigTests extends RpcClientTestSuite {

import implicits._

"ChannelConfig" should {

"for Address [host, port] work as expected" in {

ConfigForAddress[ChannelConfig.Op](host, port.toString)
.interpret[Try] shouldBe a[Success[_]]
}

"for Target work as expected" in {

ConfigForTarget[ChannelConfig.Op](host)
.interpret[Try] shouldBe a[Success[_]]
}

}

}
77 changes: 77 additions & 0 deletions rpc/src/test/scala/client/ManagedChannelInterpreterTests.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright 2017 47 Degrees, LLC. <http://www.47deg.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package freestyle.rpc
package client

import cats.data.Kleisli
import io.grpc.ManagedChannel

import scala.concurrent.duration.Duration
import scala.concurrent.{Await, Future}

class ManagedChannelInterpreterTests extends RpcClientTestSuite {

import implicits._

"ManagedChannelInterpreter" should {

"build a io.grpc.ManagedChannel based on the specified configuration, for an address" in {

val channelFor: ManagedChannelFor = ManagedChannelForAddress(host, port)

val channelConfigList: List[ManagedChannelConfig] = List(UsePlaintext(true))

val managedChannelInterpreter =
new ManagedChannelInterpreter[Future](channelFor, channelConfigList)

val mc: ManagedChannel = managedChannelInterpreter.build(channelFor, channelConfigList)

mc shouldBe an[ManagedChannel]
}

"build a io.grpc.ManagedChannel based on the specified configuration, for an target" in {

val channelFor: ManagedChannelFor = ManagedChannelForTarget(host)

val channelConfigList: List[ManagedChannelConfig] = List(UsePlaintext(true))

val managedChannelInterpreter =
new ManagedChannelInterpreter[Future](channelFor, channelConfigList)

val mc: ManagedChannel = managedChannelInterpreter.build(channelFor, channelConfigList)

mc shouldBe an[ManagedChannel]
}

"apply should work as expected" in {

val channelFor: ManagedChannelFor = ManagedChannelForTarget(host)

val channelConfigList: List[ManagedChannelConfig] = List(UsePlaintext(true))

val managedChannelInterpreter =
new ManagedChannelInterpreter[Future](channelFor, channelConfigList)

val kleisli: ManagedChannelOps[Future, String] =
Kleisli[Future, ManagedChannel, String]((_: ManagedChannel) => Future.successful(foo))

Await.result(managedChannelInterpreter[String](kleisli), Duration.Inf) shouldBe foo
}

}

}
4 changes: 3 additions & 1 deletion rpc/src/test/scala/client/RpcClientTestSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ trait RpcClientTestSuite extends RpcBaseTestSuite {
new StringMarshaller()
)

val authority: String = "localhost:8696"
val host: String = "localhost"
val port: Int = 8696
val authority: String = s"$host:$port"
val foo = "Bar"
val failureMessage: String = "❗"

Expand Down