From 49772341cee31f99edb67e1acae3bc7c2cc87cf8 Mon Sep 17 00:00:00 2001 From: Juliano Solanho Date: Wed, 20 Aug 2025 15:50:33 -0300 Subject: [PATCH 1/3] add nri-http test command --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 369b45e3..dae70968 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,9 @@ nri-http/nri-http.cabal: nri-http/package.yaml ghcid-nri-http: nri-http/nri-http.cabal cd nri-http && ghcid +ghcid-nri-http-test: nri-http/nri-http.cabal + cd nri-http && ghcid --command "cabal repl nri-http:test:spec" --test Main.main + nri-kafka/nri-kafka.cabal: nri-kafka/package.yaml hpack nri-kafka From cd2d85cba1dfb0b1a79a881184221c137aa4498a Mon Sep 17 00:00:00 2001 From: Juliano Solanho Date: Wed, 20 Aug 2025 15:52:22 -0300 Subject: [PATCH 2/3] print the full type `ExpectBytesResponse` and `ExpectTextResponse` can have different error types in their `HttpRequest' e a` Printing the full type helps us consider that when inspecting our mocks --- nri-http/src/Http/Mock.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nri-http/src/Http/Mock.hs b/nri-http/src/Http/Mock.hs index 09dcec0a..f3e4aba9 100644 --- a/nri-http/src/Http/Mock.hs +++ b/nri-http/src/Http/Mock.hs @@ -178,7 +178,7 @@ tryRespond (Stub respond : rest) req = |> Maybe.andThen Dynamic.fromDynamic |> Maybe.withDefault (tryRespond rest req) -printType :: (Dynamic.Typeable expect) => proxy expect -> Text +printType :: (Dynamic.Typeable expect) => expect -> Text printType expect = - Type.Reflection.someTypeRep expect + Type.Reflection.typeOf expect |> Debug.toString From 2de22ed30e95b72c7032fb673ed0a26333d13854 Mon Sep 17 00:00:00 2001 From: Juliano Solanho Date: Wed, 20 Aug 2025 15:57:09 -0300 Subject: [PATCH 3/3] demonstrate type mismatch behavior Debug.todo is firing here. It shouldn't, but I don't see a way to fix it, since `ExpectText` and `ExpectBytesResponse` can both pack anything as their error type. --- nri-http/src/Http/Mock.hs | 2 +- nri-http/test/Main.hs | 26 +++++++++++++++++++ .../golden-results-9.8/expected-http-span | 4 +-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/nri-http/src/Http/Mock.hs b/nri-http/src/Http/Mock.hs index f3e4aba9..bab99422 100644 --- a/nri-http/src/Http/Mock.hs +++ b/nri-http/src/Http/Mock.hs @@ -161,7 +161,7 @@ tryRespond [] req = handleCustomResponse :: (Internal.Response s -> Result e expect) -> Task e (a, expect) handleCustomResponse f = case f (Internal.NetworkError_ msg) of Err err -> Task.fail err - Ok _ -> Debug.todo "Since we manually craft the Response as an Error, this case will not run." + Ok _ -> Debug.todo msg in case Internal.expect req of Internal.ExpectJson -> Task.fail (Internal.NetworkError msg) diff --git a/nri-http/test/Main.hs b/nri-http/test/Main.hs index 8453b0d4..7920f8a9 100644 --- a/nri-http/test/Main.hs +++ b/nri-http/test/Main.hs @@ -124,6 +124,32 @@ tests = ) urlsAccessed |> Expect.equal ["example.com/one", "example.com/two"], + test "Http.Mock.stub binary" <| \_ -> do + urlsAccessed <- + Http.Mock.stub + [ Http.Mock.mkStub + ( \(req :: Http.Request Text) -> + -- Note the error type here 👇 + -- doesn't match the code under test + Task.succeed (Http.url req, "dsa") :: Task Http.Error (Text, Text) + ) + ] + ( \http -> + Expect.succeeds <| do + _ <- + Http.get + http + "example.com/one" + ( Http.expectBytesResponse + ( \_ -> + -- see? a different error type 👇 + (Ok ("asd" :: Text)) :: Result () Text + ) + ) + Task.succeed () + ) + urlsAccessed + |> Expect.equal ["example.com/one"], test "Using expectTextResponse, metadata returns the correct status" <| \() -> withServer (constant "Some text" Status.ok200) diff --git a/nri-http/test/golden-results-9.8/expected-http-span b/nri-http/test/golden-results-9.8/expected-http-span index f0edbe99..96d4a1a3 100644 --- a/nri-http/test/golden-results-9.8/expected-http-span +++ b/nri-http/test/golden-results-9.8/expected-http-span @@ -9,9 +9,9 @@ TracingSpan { srcLocPackage = "nri-http-0.6.0.0-inplace-spec" , srcLocModule = "Main" , srcLocFile = "test/Main.hs" - , srcLocStartLine = 234 + , srcLocStartLine = 247 , srcLocStartCol = 7 - , srcLocEndLine = 234 + , srcLocEndLine = 247 , srcLocEndCol = 33 } )