Help with testify/mock

xuanbao · · 909 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>i&#39;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: &#34;expected&#34; actual : &#34;websocket mock implementation&#34; 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>&#34;websocket mock implementation&#34;</code>. Here:</p> <pre><code>assert.EqualValues(t, &#34;websocket mock implementation&#34;, 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&#39;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: &#34;expected&#34; actual: &#34;from ws method&#34; 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(&#34;from ws method&#34;)</code>, and it converted to a string is being compared against <code>&#34;expected&#34;</code>.</p></pre>hell_0n_wheel: <pre><blockquote> <p>can anybody help out?</p> </blockquote> <p>You&#39;re just throwing code at the community, why should we help you out if you can&#39;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. &#34;basic research&#34; 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&#39;s a guide for your next &#34;help&#34; 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 &#34;end up&#34; 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

909 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传