lepffm / issuance

Blogging with Github Issues.
https://github.com/lepffm/issuance/issues
MIT License
1 stars 0 forks source link

[TEST] mocking-kubernetes #131

Open lepffm opened 8 months ago

lepffm commented 8 months ago

// https://github.com/fabric8io/kubernetes-client/tree/master#mocking-kubernetes // reference: https://github.com/fabric8io/kubernetes-client/blob/master/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/NamespaceTest.java

import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer
import org.slf4j.bridge.SLF4JBridgeHandler

    private val server = KubernetesMockServer(false)

    @BeforeEach
    fun setup(){
        SLF4JBridgeHandler.removeHandlersForRootLogger() // remove for okhttp3 mock server logging. see https://sylhare.github.io/2020/04/24/Java-logging.html
    }
   @Test fun `given A, when B, then C`(){
        givenResponseK8s("$PATH1/$PATH2", HttpStatus.OK, "test-content")
        ... when.. 
        ... then..
  }
    private fun givenResponseK8s(path:String = "/api/v1/test", status:HttpStatus = HttpStatus.OK, content:Any?=null, times:Int=2){
        server.expect().any().withPath(path).andReturn(
            status.value(),
            content ?: ""
        ).times(times)
    }