fabric8io / mockwebserver

An extension of okhttp's mockwebserver, that provides a DSL and is easier to use
Apache License 2.0
112 stars 38 forks source link

Add closing message to websocket #71

Open speedfl opened 2 years ago

speedfl commented 2 years ago

It could be nice to add to MockServer a close method for the andUpgradeToWebSocket.

Example: https://github.com/fabric8io/kubernetes-client/blob/master/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/PodTest.java#L318-L344

could become:

server.expect().withPath("/api/v1/namespaces/test/pods/pod1/exec?command=ls&stdout=true")
            .andUpgradeToWebSocket()
                .open()
        .waitFor(1000).andEmit(new OutputStreamMessage("first message"))
        .waitFor(2000).andEmit(new OutputStreamMessage("second message"))
                .waitFor(3000).andEmit(new CloseReason(1000, "Status v1 as string")) // this will close the session
                .done()
            .always();