-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* core-common and sdk-common: Add `Hash` and `Show` instances * Use cats-discipline to test `Hash` laws * Add more tests * Use `import cats.syntax.all._`
- Loading branch information
Showing
19 changed files
with
354 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
core/trace/src/test/scala/org/typelevel/otel4s/trace/SpanKindSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2022 Typelevel | ||
* | ||
* 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 org.typelevel.otel4s.trace | ||
|
||
import cats.Show | ||
import cats.kernel.laws.discipline.HashTests | ||
import munit._ | ||
import org.scalacheck.Arbitrary | ||
import org.scalacheck.Cogen | ||
import org.scalacheck.Gen | ||
import org.scalacheck.Prop | ||
|
||
class SpanKindSuite extends DisciplineSuite { | ||
|
||
private val spanKindGen: Gen[SpanKind] = | ||
Gen.oneOf( | ||
SpanKind.Internal, | ||
SpanKind.Server, | ||
SpanKind.Client, | ||
SpanKind.Producer, | ||
SpanKind.Consumer | ||
) | ||
|
||
private implicit val spanKindArbitrary: Arbitrary[SpanKind] = | ||
Arbitrary(spanKindGen) | ||
|
||
private implicit val spanKindCogen: Cogen[SpanKind] = | ||
Cogen[String].contramap(_.toString) | ||
|
||
checkAll("SpanKind.HashLaws", HashTests[SpanKind].hash) | ||
|
||
property("Show[SpanKind]") { | ||
Prop.forAll(spanKindGen) { spanKind => | ||
val expected = spanKind match { | ||
case SpanKind.Internal => "Internal" | ||
case SpanKind.Server => "Server" | ||
case SpanKind.Client => "Client" | ||
case SpanKind.Producer => "Producer" | ||
case SpanKind.Consumer => "Consumer" | ||
} | ||
|
||
assertEquals(Show[SpanKind].show(spanKind), expected) | ||
} | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
core/trace/src/test/scala/org/typelevel/otel4s/trace/StatusSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright 2022 Typelevel | ||
* | ||
* 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 org.typelevel.otel4s.trace | ||
|
||
import cats.Show | ||
import cats.kernel.laws.discipline.HashTests | ||
import munit._ | ||
import org.scalacheck.Arbitrary | ||
import org.scalacheck.Cogen | ||
import org.scalacheck.Gen | ||
import org.scalacheck.Prop | ||
|
||
class StatusSuite extends DisciplineSuite { | ||
|
||
private val statusGen: Gen[Status] = | ||
Gen.oneOf(Status.Unset, Status.Ok, Status.Error) | ||
|
||
private implicit val statusArbitrary: Arbitrary[Status] = | ||
Arbitrary(statusGen) | ||
|
||
private implicit val statusCogen: Cogen[Status] = | ||
Cogen[String].contramap(_.toString) | ||
|
||
checkAll("Status.HashLaws", HashTests[Status].hash) | ||
|
||
property("Show[Status]") { | ||
Prop.forAll(statusGen) { status => | ||
val expected = status match { | ||
case Status.Unset => "Unset" | ||
case Status.Ok => "Ok" | ||
case Status.Error => "Error" | ||
} | ||
|
||
assertEquals(Show[Status].show(status), expected) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.