aboutsummaryrefslogtreecommitdiff
path: root/kamon-core-tests/src/test/scala/kamon/EnvironmentSpec.scala
blob: 2dee46ab30b512663de9504db7708658afbb0914 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package kamon

import com.typesafe.config.ConfigFactory
import org.scalatest.{Matchers, WordSpec}

class EnvironmentSpec extends WordSpec with Matchers {
  private val baseConfig = ConfigFactory.parseString(
    """
      |kamon.environment {
      |  service = environment-spec
      |  host = auto
      |  instance = auto
      |}
    """.stripMargin
  )

  "the Kamon environment" should {
    "assign a host and instance name when they are set to 'auto'" in {
      val env = Environment.fromConfig(baseConfig)

      env.host shouldNot be("auto")
      env.instance shouldNot be("auto")
      env.instance shouldBe s"environment-spec@${env.host}"
    }

    "use the configured host and instance, if provided" in {
      val customConfig = ConfigFactory.parseString(
        """
          |kamon.environment {
          |  host = spec-host
          |  instance = spec-instance
          |}
        """.stripMargin)

      val env = Environment.fromConfig(customConfig.withFallback(baseConfig))

      env.host should be("spec-host")
      env.instance should be("spec-instance")
    }

    "always return the same incarnation name" in {
      val envOne = Environment.fromConfig(baseConfig)
      val envTwo = Environment.fromConfig(baseConfig)

      envOne.incarnation shouldBe envTwo.incarnation
    }
  }
}