<p>i've been trying to get this mock going, can anybody help out? thanks so much in advance</p>
<p><a href="https://play.golang.org/p/D7--qc--U1F" rel="nofollow">https://play.golang.org/p/D7--qc--U1F</a></p>
<p>test output:</p>
<pre><code>Error Trace: websocket_test.go:89
Error: Not equal:
expected: "expected"
actual : "websocket mock implementation"
Test: TestWebsocket_ReadMessage
Process finished with exit code 1
</code></pre>
<p>edit: so this turned out to be a problem with the basic implementation of nested mocks. in order to return anything the <code>Mock.On(...)</code> function returns, the mock implementation has to first get those arguments from the receiver. After changing the <code>ReadMessage</code> function <a href="https://play.golang.org/p/Afp45gkG7rS" rel="nofollow">like so</a>, it worked properly.</p>
<hr/>**评论:**<br/><br/>SeerUD: <pre><p>It looks like you just need to change your expected value to <code>"websocket mock implementation"</code>. Here:</p>
<pre><code>assert.EqualValues(t, "websocket mock implementation", string(received))
</code></pre>
<p>The second argument to assert.EqualValues appears to be the expected value, so you should put what you expect back in there. </p></pre>Vinshati: <pre><p>hey, thanks for trying to help. thats not where the problem was though. i updated my original post with the answer</p></pre>SeerUD: <pre><p>It still doesn't work for me when I try run it. Are you sure you linked the right snippet in your edit?</p>
<pre><code>$ go test .
--- FAIL: TestWebsocket_ReadMessage (0.00s)
Error Trace: foo_test.go:25
Error: Not equal:
expected: "expected"
actual: "from ws method"
FAIL
FAIL github.com/foo 0.002s
</code></pre>
<p>From the code, this is the result I would expect though. The mock is being told to return <code>[]byte("from ws method")</code>, and it converted to a string is being compared against <code>"expected"</code>.</p></pre>hell_0n_wheel: <pre><blockquote>
<p>can anybody help out?</p>
</blockquote>
<p>You're just throwing code at the community, why should we help you out if you can't be bothered to give us any context, or even do the most basic research on your own?</p></pre>Vinshati: <pre><p>pretty rude.</p>
<p>i actually figured 10 contextless lines of code would be quicker to grasp. "basic research" was obviously done, and i ended up having to sift through the source code of testify to figure out what the problem is.</p></pre>hell_0n_wheel: <pre><p>Yup, it is pretty rude of you. Here's a guide for your next "help" thread: <a href="http://www.catb.org/esr/faqs/smart-questions.html" rel="nofollow">http://www.catb.org/esr/faqs/smart-questions.html</a></p>
<blockquote>
<p>i ended up having to sift through the source code of testify to figure out what the problem is.</p>
</blockquote>
<p>I "end up" doing that as my first line of research. Before I even think to engage another, let alone an entire community.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传