rybalkinsd / kohttp

Kotlin DSL http client
https://kohttp.gitbook.io
Apache License 2.0
478 stars 42 forks source link

CFC: Feature/mockk integration #188

Open rybalkinsd opened 4 years ago

rybalkinsd commented 4 years ago
    every {
        httpPost(init = matching {
            url("https://github.com")
            body {
                json {
                    "abc" to 123
                }
            }
        })
    } returns Response {
        request(mockk())
        protocol(mockk())
        code(101)
        message("...")
    }
rybalkinsd commented 4 years ago

cc @neisip

codecov[bot] commented 4 years ago

Codecov Report

Merging #188 into master will decrease coverage by 5.49%. The diff coverage is 27.50%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #188      +/-   ##
============================================
- Coverage     90.59%   85.10%   -5.50%     
- Complexity      127      131       +4     
============================================
  Files            42       44       +2     
  Lines           404      443      +39     
  Branches         49       63      +14     
============================================
+ Hits            366      377      +11     
- Misses           13       26      +13     
- Partials         25       40      +15     
Impacted Files Coverage Δ Complexity Δ
...ithub/rybalkinsd/kohttp/dsl/context/HttpContext.kt 66.12% <10.00%> (-24.57%) 15.00 <1.00> (+1.00) :arrow_down:
...hub/rybalkinsd/kohttp/dsl/context/HeaderContext.kt 63.63% <33.33%> (-36.37%) 5.00 <1.00> (+1.00) :arrow_down:
...thub/rybalkinsd/kohttp/dsl/context/ParamContext.kt 71.42% <33.33%> (-28.58%) 6.00 <1.00> (+1.00) :arrow_down:
...tlin/io/github/rybalkinsd/kohttp/mockk/Matchers.kt 57.14% <57.14%> (ø) 1.00 <1.00> (?)
...tlin/io/github/rybalkinsd/kohttp/mockk/Response.kt 100.00% <100.00%> (ø) 0.00 <0.00> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update ccf2994...7bd0ac7. Read the comment docs.

rybalkinsd commented 4 years ago

Codcov tests are expected to fail now. Will bring more when we will discuss the API

rybalkinsd commented 4 years ago

Moved further with mocks. I found other possible declarations for returns statements

every {
    httpGet(init = matching {
       ...
    })
} returns ...

Option 2:

returns mockk {
    every { code() } returns 42
    every { message() } returns ""
}

Pros:

Cons:

Option 1 was:

returns Response {
    request(mockk())
    protocol(mockk())
    code(101)
    message("...")
}

Will be great to here your thoughts @IVSivak @gokulchandra @DeviantBadge

IVSivak commented 4 years ago

The first option looks like more commonly used. The second option may be confusing for someone, but it looks concise.