<p>My libraries do a lot on the file system, so I want to make sure that it's done right. To do so I basically keep a "good" filesystem tree and create an exactly the same side-by-side during tests. Are there any libraries doing the following:</p>
<ol>
<li>Fancy printing of structs and maps (tree-like representation);</li>
<li>Comparing structs and maps, corresponding diffs;</li>
<li>Comparing files on the file system;</li>
<li>Comparing directories (recursively) on the file system;</li>
<li>Fancy diffs on mismatched files/directories.</li>
</ol>
<p>Cheers</p>
<hr/>**评论:**<br/><br/>jmank88: <pre><p>I've used <a href="https://github.com/kr/pretty" rel="nofollow">https://github.com/kr/pretty</a> before for pretty printing structs and diffs.</p></pre>tucnak: <pre><p>Looks decent, still fails on printing big structs with branchy structure: no indentation.</p></pre>jmank88: <pre><p>Doesn't Formatter provide line breaks and tabs? </p></pre>jeffrallen: <pre><p>The best unit tests are so self-contained that they don't touch outside stuff, only their own RAM. Since you are doing filesystem operations, your first step should be to switch to Afero for your FS ops.</p>
<p><a href="https://blog.gopheracademy.com/advent-2015/afero-a-universal-filesystem-library/" rel="nofollow">https://blog.gopheracademy.com/advent-2015/afero-a-universal-filesystem-library/</a></p></pre>tucnak: <pre><blockquote>
<p>The best unit tests are so self-contained that they don't touch outside stuff, only their own RAM.</p>
</blockquote>
<p>Who said that? Using a filesystem for filesystem tests sounds way more reasonable to me.</p></pre>pievendor: <pre><p>Having file system unit tests in memory is the common pattern in a lot languages. There are two distinct advantages: </p>
<p>1) cleanup is easy.
2) increasing your test concurrency is a lot safer so you can run your tests faster.</p>
<p>It's the same principle that people discourage use of a real database in integration tests. It's slow and can cause test pollution if you're not careful or don't successfully tear down your suite.</p></pre>Manbeardo: <pre><p>For structure/map comparison, reflect.DeepEqual might be useful for you.</p></pre>tucnak: <pre><p>Well, it won't. It just tells whether structs equal or not. What you really wanna know for tests is what's the actual difference between the compared objects.</p></pre>lapingvino: <pre><p>you can still use it to check if you need to iterate more or not... reflect also provides everything to do that :)</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传