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

BREAKING | Simplify classes #295

Merged
merged 105 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
6ea3c2f
This is already provided by `DocumentationPlugin` from `sbt-ci`
alejandrohdezma Apr 24, 2023
9cb6d7a
This file isn't being used
alejandrohdezma Apr 24, 2023
48db770
Remove type param from `Http4sSuite`
alejandrohdezma Apr 24, 2023
3f8d98e
Deprecate `->` in favour of `context`
alejandrohdezma Apr 24, 2023
bdc296f
Use attributes to get context on `http4sMUnitNameCreator`
alejandrohdezma Apr 24, 2023
e8ee69b
`http4sMUnitNameCreator` can now be provided in `Http4sSuite`
alejandrohdezma Apr 24, 2023
9f171c4
Move `http4sMUnitFunFixture` to `Http4sSuite`
alejandrohdezma Apr 24, 2023
1590877
Move `test` to `Http4sSuite`
alejandrohdezma May 4, 2023
2d4c790
Add `http4sMUnitClientFixture` to `Http4sSuite` and deprecate `http4s…
alejandrohdezma May 4, 2023
6ce4c7c
Move `HttpSuite` utilities to `Http4sSuite`
alejandrohdezma May 4, 2023
8fdbc5a
Add extension method to prepend a `Client`'s requests with a specific…
alejandrohdezma May 4, 2023
a8c5c27
Deprecate `HttpSuite` in favour of `Http4sSuite` with overridden client
alejandrohdezma May 4, 2023
df244df
Extract every alias and extension method to a common file
alejandrohdezma Apr 25, 2023
ce01957
Create class representing a test-name creator
alejandrohdezma May 4, 2023
2caea1a
Add method to provide new `Http4sMunitTestNameCreator` and deprecate …
alejandrohdezma May 4, 2023
70c4e5d
Use `Stream.range` instead of `Stream.emits`
alejandrohdezma Apr 25, 2023
a114168
Decouple `Http4sMUnitTestCreator` from `Http4sSuite` members
alejandrohdezma May 4, 2023
e063808
Extract `Http4sMUnitTestCreator` to its own file
alejandrohdezma Apr 25, 2023
ad0400a
Add `test` extension method for `SyncIO[FunFixture[Client[IO]]]`
alejandrohdezma May 4, 2023
e81ba69
Add method for updating every `Client` requests' `Uri`
alejandrohdezma May 4, 2023
1811196
Add documentation on how to run an effect before a test
alejandrohdezma May 4, 2023
3b310b2
Move context-related methods to `Http4sMUnitSyntax`
alejandrohdezma May 4, 2023
e766b3c
Add extension methods to transform `HttpRoutes`/`AuthedRoutes`/`HttpA…
alejandrohdezma May 4, 2023
067d73a
Move `withRoutes` methods to `Http4sSuite`
alejandrohdezma May 4, 2023
d14e7cd
Add extension method for creating a failing `Client`
alejandrohdezma May 4, 2023
b5efe30
Add extension method to convert an http4s` `Client` into a fixture
alejandrohdezma May 4, 2023
1e78db6
Deprecate `Http4sHttpRoutesSuite` & `Http4sAuthedRoutesSuite` in favo…
alejandrohdezma May 4, 2023
e2edbe1
Rename implicit classes in `Http4sMUnitSyntax` to avoid possible clashes
alejandrohdezma May 4, 2023
6eb3afd
Change this to `fix --check` to also run Scalafix
alejandrohdezma May 4, 2023
bb8ef7a
Add `orFail` extension method for `HttpRoutes`/`AuthedRoutes`
alejandrohdezma May 5, 2023
ddcc31d
Change `getContext`/`context` to work with an implicit key instead of…
alejandrohdezma May 5, 2023
345d262
Remove `RequestContext` class
alejandrohdezma May 5, 2023
ac3f7da
Remove `HttpRoutes.asFixture`/`AuthedRoutes.asFixture` extension methods
alejandrohdezma May 5, 2023
3c7d104
Remove `withRoutes`/`withAuthedRoutes` methods and use `withHttpApp` …
alejandrohdezma May 5, 2023
467c68f
Move replacements in `Http4sMUnitTestNameCreator` to separated method
alejandrohdezma May 5, 2023
f03da60
Create method for composing a method to the result of an `Http4sMUnit…
alejandrohdezma May 5, 2023
ee05afd
Simplify how to work with `AuthedRoutes`
alejandrohdezma May 5, 2023
8d467ce
Update sbt-ci to 2.13.4
alejandrohdezma-steward[bot] Sep 1, 2023
7c21a26
Run `sbt generateCiFiles`
alejandrohdezma-steward[bot] Sep 1, 2023
99d806d
Update circe-parser to 0.14.6
alejandrohdezma-steward[bot] Sep 1, 2023
d407f53
Update sbt-scalafmt to 2.5.2
alejandrohdezma-steward[bot] Sep 1, 2023
5f5ccb9
Merge pull request #307 from alejandrohdezma/update/all
github-actions[bot] Sep 1, 2023
d424cc7
Update sbt-scalafix to 0.11.1
alejandrohdezma-steward[bot] Sep 15, 2023
1f695fe
Update scala-library to 2.13.12
alejandrohdezma-steward[bot] Sep 15, 2023
38dca1d
Merge pull request #308 from alejandrohdezma/update/all
github-actions[bot] Sep 15, 2023
9737478
Update sbt to 1.9.6
alejandrohdezma-steward[bot] Oct 1, 2023
e24e0fb
Merge pull request #309 from alejandrohdezma/update/all
github-actions[bot] Oct 1, 2023
56b31d5
Update sbt-ci to 2.13.5
alejandrohdezma-steward[bot] Oct 15, 2023
a37353c
Run `sbt generateCiFiles`
alejandrohdezma-steward[bot] Oct 15, 2023
12745e9
Update sbt-mdoc to 2.3.8
alejandrohdezma-steward[bot] Oct 15, 2023
1612cb9
Merge pull request #310 from alejandrohdezma/update/all
github-actions[bot] Oct 15, 2023
2c081a4
Update sbt to 1.9.7
alejandrohdezma-steward[bot] Nov 1, 2023
8334d9a
Update sbt-mdoc to 2.4.0
alejandrohdezma-steward[bot] Nov 1, 2023
9bb60a3
Merge pull request #311 from alejandrohdezma/update/all
github-actions[bot] Nov 1, 2023
61ba23a
Update http4s-circe to 0.23.24
alejandrohdezma-steward[bot] Nov 15, 2023
7a5ddb2
Update http4s-client to 0.23.24
alejandrohdezma-steward[bot] Nov 15, 2023
ce16845
Update http4s-dsl to 0.23.24
alejandrohdezma-steward[bot] Nov 15, 2023
f2bfdab
Update http4s-ember-client to 0.23.24
alejandrohdezma-steward[bot] Nov 15, 2023
23d5128
Update sbt-mdoc to 2.5.1
alejandrohdezma-steward[bot] Nov 15, 2023
835875f
Merge pull request #312 from alejandrohdezma/update/all
github-actions[bot] Nov 15, 2023
bc7839e
Update logback-classic to 1.4.13
alejandrohdezma-steward[bot] Dec 1, 2023
bc542da
Merge pull request #313 from alejandrohdezma/update/all
github-actions[bot] Dec 1, 2023
4767367
Update logback-classic to 1.4.14
alejandrohdezma-steward[bot] Dec 4, 2023
519330f
Merge pull request #314 from alejandrohdezma/update/all
github-actions[bot] Dec 4, 2023
4a1ce91
Update http4s-blaze-client to 0.23.16
alejandrohdezma-steward[bot] Jan 1, 2024
3a2b7db
Update sbt to 1.9.8
alejandrohdezma-steward[bot] Jan 1, 2024
a178b3f
Merge pull request #315 from alejandrohdezma/update/all
github-actions[bot] Jan 1, 2024
d966b9a
Update sbt-ci to 2.13.6
alejandrohdezma-steward[bot] Jan 15, 2024
9024bac
Run `sbt generateCiFiles`
alejandrohdezma-steward[bot] Jan 15, 2024
db83c64
Update sbt-github-header to 0.11.13
alejandrohdezma-steward[bot] Jan 15, 2024
610e671
Update sbt-github-mdoc to 0.11.13
alejandrohdezma-steward[bot] Jan 15, 2024
6c29171
Update sbt-scalafix-defaults to 0.12.0
alejandrohdezma-steward[bot] Jan 15, 2024
f4f4d8d
Run `sbt fix`
alejandrohdezma-steward[bot] Jan 15, 2024
4c0b044
Update http4s-circe to 0.23.25
alejandrohdezma-steward[bot] Jan 15, 2024
64023b2
Update http4s-client to 0.23.25
alejandrohdezma-steward[bot] Jan 15, 2024
a9af3c9
Update http4s-dsl to 0.23.25
alejandrohdezma-steward[bot] Jan 15, 2024
a846494
Update http4s-ember-client to 0.23.25
alejandrohdezma-steward[bot] Jan 15, 2024
977124d
Update sbt-mdoc to 2.5.2
alejandrohdezma-steward[bot] Jan 15, 2024
6cc5fe9
Merge pull request #316 from alejandrohdezma/update/all
github-actions[bot] Jan 15, 2024
f5885f3
Update sbt-ci to 2.15.0
alejandrohdezma-steward[bot] Feb 15, 2024
1457261
Update sbt-modules to 0.3.0
alejandrohdezma-steward[bot] Feb 15, 2024
bc4dcd4
Add `sbt-version-policy`
alejandrohdezma Feb 19, 2024
83a3cae
Merge pull request #317 from alejandrohdezma/update/all
github-actions[bot] Feb 19, 2024
698296c
Add version policy settings to CI
alejandrohdezma Feb 19, 2024
24ffa14
Update logback-classic to 1.5.1
alejandrohdezma-steward[bot] Feb 29, 2024
fbcb484
Update scala-library to 2.12.19
alejandrohdezma-steward[bot] Feb 29, 2024
6dc6331
Update scala-library to 2.13.13
alejandrohdezma-steward[bot] Feb 29, 2024
3462fc2
Update sbt to 1.9.9
alejandrohdezma-steward[bot] Feb 29, 2024
04d5598
Update kind-projector to 0.13.3
alejandrohdezma-steward[bot] Feb 29, 2024
e2b383c
Merge pull request #318 from alejandrohdezma/update/all
github-actions[bot] Feb 29, 2024
a150d63
Update sbt-scalafix to 0.12.0
alejandrohdezma-steward[bot] Mar 15, 2024
faefd72
Update logback-classic to 1.5.3
alejandrohdezma-steward[bot] Mar 15, 2024
7137200
Update http4s-circe to 0.23.26
alejandrohdezma-steward[bot] Mar 15, 2024
30aff0c
Update http4s-client to 0.23.26
alejandrohdezma-steward[bot] Mar 15, 2024
a4c3592
Update http4s-dsl to 0.23.26
alejandrohdezma-steward[bot] Mar 15, 2024
bc7fd32
Update http4s-ember-client to 0.23.26
alejandrohdezma-steward[bot] Mar 15, 2024
4f7c294
Merge pull request #319 from alejandrohdezma/update/all
github-actions[bot] Mar 15, 2024
79dd5d2
Update sbt-modules to 0.3.1
alejandrohdezma-steward[bot] Apr 1, 2024
16902e5
Merge pull request #321 from alejandrohdezma/update/all
github-actions[bot] Apr 1, 2024
6473d3c
Update logback-classic to 1.5.5
alejandrohdezma-steward[bot] Apr 15, 2024
8439cea
Update sbt-tpolecat to 0.5.1
alejandrohdezma-steward[bot] Apr 15, 2024
3e53928
Merge pull request #322 from alejandrohdezma/update/all
github-actions[bot] Apr 15, 2024
ce6fde9
Merge branch 'main' into feature/fixtures
alejandrohdezma Apr 23, 2024
44e875b
`ResourceFunFixture` is now called `ResourceFixture`
alejandrohdezma Apr 23, 2024
8a0a6a5
Update to latest Scala 3 and disable `versionPolicyIntention`
alejandrohdezma Apr 23, 2024
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
4 changes: 0 additions & 4 deletions .github/auto_assign.yml

This file was deleted.

187 changes: 128 additions & 59 deletions .github/docs/README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .github/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ changelog:
labels:
- ":chart_with_upwards_trend: dependency-update"
authors:
- alejandrohdezma-steward
- dependabot
categories:
- title: "⚠️ Breaking changes"
labels:
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
# Runs `sbt ci-test` on the project on differnt JDKs (this task should be added to the project as a command alias
# containing the necessary steps to compile, check formatters, launch tests...).
#
# An example of this `ci-test` alias can be found in https://github.com/alejandrohdezma/sbt-github/blob/main/build.sbt.
# Examples of this `ci-test` alias can be found [here](https://github.com/search?q=org%3Aalejandrohdezma+%22ci-test%22+path%3Abuild.sbt++NOT+is%3Aarchived&type=code).
#
# It will also do the following:
#
# - It will automatically label PRs based on head branch.
# - It will automatically enable auto-merge on `Scala Steward` PRs.
# - It will automatically enable auto-merge on `Scala Steward` PRs. You'll need to add a `STEWARD_BOT` repository or
# organization variable with the name of your scala-steward bot. See https://docs.github.com/en/actions/learn-github-actions/variables.

name: CI

Expand All @@ -34,7 +35,7 @@ jobs:
ci-steward:
if: |
github.event.pull_request.state == 'OPEN' && github.event.pull_request.head.repo.full_name == github.repository &&
github.event.pull_request.user.login == 'alejandrohdezma-steward[bot]'
github.event.pull_request.user.login == vars.STEWARD_BOT
name: (Scala Steward) Enable auto-merge
runs-on: ubuntu-latest
steps:
Expand All @@ -58,11 +59,11 @@ jobs:
- 17
steps:
- name: Checkout project
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
ref: ${{ github.head_ref }}

- uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0
- uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 # v4.0.0
with:
distribution: "liberica"
java-version: ${{ matrix.jdk }}
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
# This workflow performs two tasks:
#
# - Creates a release of the project by running `sbt ci-publish` (this task should be added to the project as a command
# alias containing the necessary steps to do a release). An example of the `ci-publish` alias can be found in
# https://github.com/alejandrohdezma/sbt-github/blob/main/build.sbt.
# alias containing the necessary steps to do a release). Examples of this `ci-publish` alias can be found
# [here](https://github.com/search?q=org%3Aalejandrohdezma+%22ci-publish%22+path%3Abuild.sbt++NOT+is%3Aarchived&type=code).
#
# - Runs `sbt ci-docs` on the project and pushes a commit with the changes (the `ci-docs` task should be added to the
# project as a command alias containing the necessary steps to update documentation: re-generate docs files,
# publish websites, update headers...). An example of the `ci-docs` alias can be found in
# https://github.com/alejandrohdezma/sbt-github/blob/main/build.sbt.
# publish websites, update headers...). Examples of this `ci-docs` alias can be found
# [here](https://github.com/search?q=org%3Aalejandrohdezma+%22ci-docs%22+path%3Abuild.sbt++NOT+is%3Aarchived&type=code).
#
# This workflow will launch on pushed tags. Alternatively one can launch it manually using a "workflow dispatch" to
# create a snapshot release (this won't trigger the documentation update).
Expand All @@ -29,15 +29,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout project
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0

- name: Check latest tag follows semantic versioning
if: github.event_name == 'push'
uses: alejandrohdezma/actions/check-semver-tag@v1

- uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0
- uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 # v4.0.0
with:
distribution: "liberica"
java-version: "11"
Expand All @@ -59,13 +59,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout project
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0
ref: main
token: ${{ secrets.ADMIN_GITHUB_TOKEN }}

- uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0
- uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 # v4.0.0
with:
distribution: "liberica"
java-version: "17"
Expand Down
43 changes: 19 additions & 24 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
val Scala3 = "3.3.0" // scala-steward:off
ThisBuild / scalaVersion := "2.13.11"
ThisBuild / crossScalaVersions := Seq("2.12.18", "2.13.11", Scala3)
ThisBuild / scalaVersion := "2.13.13"
ThisBuild / crossScalaVersions := Seq("2.12.19", "2.13.13", "3.3.3")
ThisBuild / versionPolicyIntention := Compatibility.None

ThisBuild / organization := "com.alejandrohdezma"

addCommandAlias("ci-test", "scalafmtCheckAll; mdoc; +test")
addCommandAlias("ci-test", "fix --check; versionPolicyCheck; mdoc; +test")
addCommandAlias("ci-docs", "github; headerCreateAll; mdoc")
addCommandAlias("ci-publish", "github; ci-release")
addCommandAlias("ci-publish", "versionCheck; github; ci-release")

lazy val documentation = project
.enablePlugins(MdocPlugin)
.settings(mdocOut := file("."))
.dependsOn(`http4s-munit` % "compile->test")
.settings(scalacOptions -= "-Wnonunit-statement")
.settings(libraryDependencies += "org.http4s" %% "http4s-blaze-client" % "0.23.15")
.settings(libraryDependencies += "org.http4s" %% "http4s-blaze-client" % "0.23.16")

lazy val `http4s-munit` = module
.settings(Test / fork := true)
.settings(libraryDependencies += "org.scalameta" %% "munit" % "1.0.0-M8")
.settings(libraryDependencies += "org.http4s" %% "http4s-client" % "0.23.23")
.settings(libraryDependencies += "org.http4s" %% "http4s-dsl" % "0.23.23")
.settings(libraryDependencies += "org.http4s" %% "http4s-ember-client" % "0.23.23" % Optional)
.settings(libraryDependencies += "org.typelevel" %% "munit-cats-effect" % "2.0.0-M3")
.settings(libraryDependencies += "io.circe" %% "circe-parser" % "0.14.5")
.settings(libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.4.11" % Test)
.settings(libraryDependencies += "org.http4s" %% "http4s-circe" % "0.23.23" % Test)
.settings(libraryDependencies += "com.dimafeng" %% "testcontainers-scala-munit" % "0.41.0" % Test)
.settings(libraryDependencies += "org.http4s" %% "http4s-ember-client" % "0.23.23" % Test)
.settings(
libraryDependencies ++= CrossVersion
.partialVersion(scalaVersion.value)
.collect { case (2, _) => compilerPlugin("org.typelevel" % "kind-projector" % "0.13.2").cross(CrossVersion.full) }
.toList
)
.settings(libraryDependencies += "org.scalameta" %% "munit" % "0.7.29")
.settings(libraryDependencies += "org.http4s" %% "http4s-client" % "0.23.26")
.settings(libraryDependencies += "org.http4s" %% "http4s-dsl" % "0.23.26")
.settings(libraryDependencies += "org.http4s" %% "http4s-ember-client" % "0.23.26" % Optional)
.settings(libraryDependencies += "org.typelevel" %% "munit-cats-effect-3" % "1.0.7")
.settings(libraryDependencies += "io.circe" %% "circe-parser" % "0.14.6")
.settings(libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.5.5" % Test)
.settings(libraryDependencies += "org.http4s" %% "http4s-circe" % "0.23.26" % Test)
.settings(libraryDependencies += "com.dimafeng" %% "testcontainers-scala-munit" % "0.40.16" % Test)
.settings(libraryDependencies += "org.http4s" %% "http4s-ember-client" % "0.23.26" % Test)
.settings(libraryDependencies ++= scalaVersion.value.on(2)(kindProjector))

def kindProjector = compilerPlugin("org.typelevel" % "kind-projector" % "0.13.3").cross(CrossVersion.full)
3 changes: 2 additions & 1 deletion modules/http4s-munit/src/main/scala/munit/ClientSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import org.http4s.dsl.Http4sDslBinCompat
* @author
* Alejandro Hernández
*/
@deprecated("Extend Http4sMUnitSyntax instead", since = "0.16.0")
trait ClientSuite extends CatsEffectSuite with Http4sDslBinCompat[IO] {

implicit class ClientTypeOps(t: Client.type) {
Expand Down Expand Up @@ -94,7 +95,7 @@ trait ClientSuite extends CatsEffectSuite with Http4sDslBinCompat[IO] {
def fixture[A](
f: Client[IO] => Resource[IO, A]
): PartialFunction[Request[IO], IO[Response[IO]]] => SyncIO[FunFixture[A]] =
pf => ResourceFunFixture(f(from(pf)))
pf => ResourceFixture(f(from(pf)))

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2023 Alejandro Hernández <https://github.com/alejandrohdezma>
* Copyright 2020-2022 Alejandro Hernández <https://github.com/alejandrohdezma>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,16 +16,14 @@

package munit

import cats.Show
import cats.effect.IO
import cats.effect.Resource
import cats.effect.SyncIO

import org.http4s.AuthedRequest
import org.http4s.AuthedRoutes
import org.http4s.ContextRequest
import org.http4s.Request
import org.http4s.Response
import org.http4s.client.Client
import org.typelevel.vault.Key

/** Base class for suites testing `AuthedRoutes`.
*
Expand Down Expand Up @@ -53,42 +51,20 @@ import org.http4s.Response
* }
* }}}
*/
abstract class Http4sAuthedRoutesSuite[A: Show] extends Http4sSuite[AuthedRequest[IO, A]] {
@deprecated("Use `Http4sSuite` overriding `http4sMUnitClientFixture` instead", since = "0.16.0")
abstract class Http4sAuthedRoutesSuite[A] extends Http4sSuite {

@SuppressWarnings(Array("scalafix:DisableSyntax.valInAbstract"))
implicit val key: Key[A] = Key.newKey[IO, A].unsafeRunSync()

/** The HTTP routes being tested */
val routes: AuthedRoutes[A, IO]

/** @inheritdoc */
override def http4sMUnitNameCreator(
request: AuthedRequest[IO, A],
followingRequests: List[String],
testOptions: TestOptions,
config: Http4sMUnitConfig
): String = Http4sMUnitDefaults.http4sMUnitNameCreator(
request,
followingRequests,
testOptions,
config,
http4sMUnitNameCreatorReplacements()
)

implicit class Request2AuthedRequest(request: Request[IO]) {

/** Converts an `IO[Request[IO]]` into an `IO[AuthedRequest[IO, A]]` by providing the `A` context. */
def context(context: A): AuthedRequest[IO, A] = AuthedRequest(context, request)

/** Converts an `IO[Request[IO]]` into an `IO[AuthedRequest[IO, A]]` by providing the `A` context. */
def ->(a: A): AuthedRequest[IO, A] = context(a)

}

implicit class Http4sMUnitTestCreatorOps(creator: Http4sMUnitTestCreator) {

/** Allows overriding the routes used when running this test. */
def withRoutes(newRoutes: AuthedRoutes[A, IO]): Http4sMUnitTestCreator = creator.copy(
http4sMUnitFunFixture =
SyncIO.pure(FunFixture(_ => req => newRoutes.orNotFound.run(req).to[Resource[IO, *]], _ => ()))
)
/** Alias for adding a request's context. */
@deprecated("Use `.context` instead", since = "0.16.0")
def ->(a: A): Request[IO] = request.context(a)

}

Expand All @@ -100,8 +76,9 @@ abstract class Http4sAuthedRoutesSuite[A: Show] extends Http4sSuite[AuthedReques

}

def http4sMUnitFunFixture: SyncIO[FunFixture[ContextRequest[IO, A] => Resource[IO, Response[IO]]]] =
SyncIO.pure(FunFixture(_ => routes.orNotFound.run(_).to[Resource[IO, *]], _ => ()))
/** @inheritdoc */
override def http4sMUnitClientFixture: SyncIO[FunFixture[Client[IO]]] =
AuthedRequest.fromContext[A].andThen(routes).orFail.asFixture

/** Declares a test for the provided request. That request will be executed using the routes provided in `routes`.
*
Expand All @@ -126,7 +103,11 @@ abstract class Http4sAuthedRoutesSuite[A: Show] extends Http4sSuite[AuthedReques
* }
* }}}
*/
def test(request: AuthedRequest[IO, A]): Http4sMUnitTestCreator =
Http4sMUnitTestCreator(request, http4sMUnitFunFixture)
override def test(request: Request[IO]): Http4sMUnitTestCreator = {
if (!request.attributes.contains(key))
fail("Auth context not found on request, remember to add one with `.context`", clues(request))

super.test(request)
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2023 Alejandro Hernández <https://github.com/alejandrohdezma>
* Copyright 2020-2022 Alejandro Hernández <https://github.com/alejandrohdezma>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,13 +17,10 @@
package munit

import cats.effect.IO
import cats.effect.Resource
import cats.effect.SyncIO

import org.http4s.ContextRequest
import org.http4s.HttpRoutes
import org.http4s.Request
import org.http4s.Response
import org.http4s.client.Client

/** Base class for suites testing `HttpRoutes`.
*
Expand Down Expand Up @@ -53,7 +50,8 @@ import org.http4s.Response
* @author
* José Gutiérrez
*/
trait Http4sHttpRoutesSuite extends Http4sSuite[Request[IO]] {
@deprecated("Use `Http4sSuite` overriding `http4sMUnitClientFixture` instead", since = "0.16.0")
trait Http4sHttpRoutesSuite extends Http4sSuite {

/** The HTTP routes being tested.
*
Expand All @@ -65,64 +63,14 @@ trait Http4sHttpRoutesSuite extends Http4sSuite[Request[IO]] {
*/
val routes: HttpRoutes[IO]

/** @inheritdoc */
override def http4sMUnitNameCreator(
request: Request[IO],
followingRequests: List[String],
testOptions: TestOptions,
config: Http4sMUnitConfig
): String =
Http4sMUnitDefaults.http4sMUnitNameCreator(
ContextRequest((), request),
followingRequests,
testOptions,
config,
http4sMUnitNameCreatorReplacements()
)

implicit class Http4sMUnitTestCreatorOps(creator: Http4sMUnitTestCreator) {

/** Allows overriding the routes used when running this test. */
def withRoutes(newRoutes: HttpRoutes[IO]): Http4sMUnitTestCreator = creator.copy(
http4sMUnitFunFixture =
SyncIO.pure(FunFixture(_ => req => newRoutes.orNotFound.run(req).to[Resource[IO, *]], _ => ()))
)

}

implicit class HttpRoutesCompanionOps(companion: HttpRoutes.type) {

/** An HttpRoutes instance that always fails */
val fail: HttpRoutes[IO] = HttpRoutes(request => Assertions.fail("This should not be called", clues(request)))

}

def http4sMUnitFunFixture: SyncIO[FunFixture[Request[IO] => Resource[IO, Response[IO]]]] =
SyncIO.pure(FunFixture(_ => req => routes.orNotFound.run(req).to[Resource[IO, *]], _ => ()))

/** Declares a test for the provided request. That request will be executed using the routes provided in `routes`.
*
* @example
* {{{
* test(GET(uri"users" / 42)) { response =>
* // test body
* }
* }}}
*
* @example
* {{{
* test(POST(json, uri"users")).alias("Create a new user") { response =>
* // test body
* }
* }}}
*
* @example
* {{{
* test(GET(uri"users" / 42)).flaky { response =>
* // test body
* }
* }}}
*/
def test(request: Request[IO]): Http4sMUnitTestCreator = Http4sMUnitTestCreator(request, http4sMUnitFunFixture)
/** @inheritdoc */
override def http4sMUnitClientFixture: SyncIO[FunFixture[Client[IO]]] = routes.orFail.asFixture

}
Loading