<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Guiyomh</title>
    <description>The latest articles on Forem by Guiyomh (@guiyomh).</description>
    <link>https://forem.com/guiyomh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F817041%2F823a1050-21af-4902-9dde-aa0e9b058f2d.jpg</url>
      <title>Forem: Guiyomh</title>
      <link>https://forem.com/guiyomh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/guiyomh"/>
    <language>en</language>
    <item>
      <title>Tame Testing Chaos with Gotestsum</title>
      <dc:creator>Guiyomh</dc:creator>
      <pubDate>Tue, 31 Oct 2023 14:59:02 +0000</pubDate>
      <link>https://forem.com/guiyomh/tame-testing-chaos-with-gotestsum-1k1l</link>
      <guid>https://forem.com/guiyomh/tame-testing-chaos-with-gotestsum-1k1l</guid>
      <description>&lt;p&gt;Testing is now a crucial part of the software development process. However, managing results can rapidly become chaotic when you have a lot of tests. This is where the potent open-source utility &lt;strong&gt;Gotestsum&lt;/strong&gt; comes in, which is made to make managing test results in Go easier and better. By combining the outcomes of several tests into a single, understandable report, this developer companion helps you to improve the readability and comprehension of the status of your tests.&lt;/p&gt;

&lt;p&gt;Gotestsum is a useful tool that can help developers of all experience levels manage their tests more efficiently and identify possible problems more rapidly. Let's take a look!&lt;/p&gt;

&lt;h2&gt;
  
  
  Ready in a Blink
&lt;/h2&gt;

&lt;p&gt;To install Gotestsum, you can use the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;go &lt;span class="nb"&gt;install &lt;/span&gt;gotest.tools/gotestsum@latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Gotestsum is designed to be user-friendly and work without additional configuration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Gotestsum's Super Powers
&lt;/h2&gt;

&lt;p&gt;Gotestsum offers a set of powerful features to improve the management of your Go test results.&lt;/p&gt;

&lt;h3&gt;
  
  
  Personalize Your Tests
&lt;/h3&gt;

&lt;p&gt;It allows you to customize the output format of test results&lt;br&gt;
 with the option &lt;code&gt;--format&lt;/code&gt;. You can choose from different formats, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;dots&lt;/strong&gt; prints one character for each test&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;dots-v2&lt;/strong&gt; experimental dots format, one packet per line&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;pkgname&lt;/strong&gt; prints one line for each packet&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;pkgname-and-test-fails&lt;/strong&gt; prints one line for each packet and failed test results&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;testname&lt;/strong&gt; prints one line for each test and each packet&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;testdox&lt;/strong&gt; prints a sentence for each test using gotestdox&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;github-actions&lt;/strong&gt; test name format with github actions log grouping&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;standard-quiet&lt;/strong&gt; standard format go test&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;standard-verbose&lt;/strong&gt; standard format go test -v&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4jZcfGGL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qof1tk0vpvglmmwcxqb0.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4jZcfGGL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qof1tk0vpvglmmwcxqb0.gif" alt="A demonstration of --format option" width="800" height="448"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Technicolor tests
&lt;/h3&gt;

&lt;p&gt;The reports generated by Gotestsum are colored for better readability. Passed tests are displayed in green, failed tests in red, and unexecuted tests in yellow. This coloring makes the status of your tests immediately visible, which is particularly useful when running large tests.&lt;/p&gt;
&lt;h3&gt;
  
  
  The Ideal Companion for your CI/CD
&lt;/h3&gt;

&lt;p&gt;An important feature is the ability to produce results in Junit or Json format, which makes it a valuable tool for CIs such as Gitlab, Circle CI, Github-action,...&lt;/p&gt;

&lt;p&gt;When the &lt;code&gt;--junitfile&lt;/code&gt; option specifies a file path, gotestsum will write a test report, in JUnit XML format, to the file. This file can be used to integrate CI systems.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gotestsum &lt;span class="nt"&gt;--junitfile&lt;/span&gt; unit-tests.xml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Your Local Test Assistant
&lt;/h3&gt;

&lt;p&gt;When working on your local development project, Gotestsum offers features that simplify the testing process. The &lt;code&gt;--watch&lt;/code&gt; option allows you to automatically run tests of the package that has changed every time a .go file is saved. This ensures that your tests are always up to date and helps you quickly spot any issues introduced during your changes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gotestsum &lt;span class="nt"&gt;--watch&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Additionally, you can use the &lt;code&gt;--post-run-command&lt;/code&gt; option to run a command after running the tests. This can be particularly useful for displaying notifications on your desktop about test results. This way, you can stay informed in real time about the status of your tests during your development process.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gotestsum &lt;span class="nt"&gt;--post-run-command&lt;/span&gt; notify
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  A Powerful Ally
&lt;/h2&gt;

&lt;p&gt;These capabilities transform Gotestsum into a powerful tool for Go developers, streamlining the administration of test results, improving visibility of test status and accelerating the debugging process.&lt;/p&gt;

&lt;p&gt;Gotestsum adapts to your needs, whether you're working on a large team project or a small personal one. It can be tailored to your needs, including interaction with your favorite CI/CD systems, desktop notifications at the end of tests and customized output formats.&lt;/p&gt;

&lt;p&gt;I hope I've convinced you that Gotestsum is an effective tool that can help you move forward with your Go development projects.&lt;/p&gt;

</description>
      <category>go</category>
      <category>codequality</category>
      <category>productivity</category>
      <category>testing</category>
    </item>
    <item>
      <title>golangci-lint: a powerful and complete Go linter</title>
      <dc:creator>Guiyomh</dc:creator>
      <pubDate>Tue, 31 Oct 2023 10:48:59 +0000</pubDate>
      <link>https://forem.com/guiyomh/golangci-lint-a-powerful-and-complete-go-linter-5eb8</link>
      <guid>https://forem.com/guiyomh/golangci-lint-a-powerful-and-complete-go-linter-5eb8</guid>
      <description>&lt;p&gt;&lt;strong&gt;golangci-lint&lt;/strong&gt; is a Go linter tool that helps detect and fix style errors, convention errors, and potential vulnerabilities. It is based on a set of predefined rules, but you can also create your own rules.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation and configuration
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;go &lt;span class="nb"&gt;install &lt;/span&gt;github.com/golangci/golangci-lint/cmd/golangci-lint@latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Use
&lt;/h2&gt;

&lt;p&gt;To run golangci-lint on your project, use the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;golangci-lint run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;golangci-lint will display the list of errors and warnings found. You can also use the &lt;code&gt;--format&lt;/code&gt; option to display the results in a custom format.&lt;/p&gt;

&lt;p&gt;Here are some examples of issues that golangci-lint can detect:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Style errors&lt;/strong&gt;: golangci-lint can detect the most common Go style errors, such as using uninitialized variables, missing comments, and bad indentation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Convention errors&lt;/strong&gt;: golangci-lint can detect violations of Go coding conventions, such as using non-compliant variable names or missing unit tests.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Vulnerabilities&lt;/strong&gt;: golangci-lint can detect known vulnerabilities in Go code, such as the use of outdated encryption primitives or lack of input validation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Configuration
&lt;/h2&gt;

&lt;p&gt;golangci-lint is a very configurable tool. It supports several formats YAML, JSON, TOML. You can customize linter rules to meet your specific needs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Enable or disable linters
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;linters&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;enable-all&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;
  &lt;span class="na"&gt;disable&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;deadcode&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;exhaustivestruct&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;golint&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;ifshort&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;interfacer&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;maligned&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This configuration activates all linters except those listed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Apply specific rules
&lt;/h3&gt;

&lt;p&gt;For example, you can add custom rules to detect issues specific to your project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;rules&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="c1"&gt;# Name of a rule.&lt;/span&gt;
      &lt;span class="na"&gt;main&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;deny&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;pkg&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;github.com/sirupsen/logrus"&lt;/span&gt;
            &lt;span class="na"&gt;desc&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;not allowed&lt;/span&gt;
          &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;pkg&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;github.com/pkg/errors"&lt;/span&gt;
            &lt;span class="na"&gt;desc&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Should be replaced by standard lib errors package&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This configuration prohibits the use of certain packages (this is an example)&lt;/p&gt;

&lt;h2&gt;
  
  
  Linter included
&lt;/h2&gt;

&lt;p&gt;Golangci-lint includes over 30 linters, which cover a wide range of code quality issues. These linters are divided into several categories:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Style linters&lt;/strong&gt; check code for compliance with Go style conventions.

&lt;ul&gt;
&lt;li&gt;A variable declared without initialization.&lt;/li&gt;
&lt;li&gt;A function declared with an inappropriate name.&lt;/li&gt;
&lt;li&gt;A function that does not return a value.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security linters&lt;/strong&gt; detect potential security issues in code.

&lt;ul&gt;
&lt;li&gt;A function that uses an inappropriate data type for a parameter.&lt;/li&gt;
&lt;li&gt;A function that does not properly isolate errors.&lt;/li&gt;
&lt;li&gt;A function that uses an uninitialized variable.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Performance linters&lt;/strong&gt; detect potential performance issues in code.

&lt;ul&gt;
&lt;li&gt;A loop that could be replaced by an arithmetic expression.&lt;/li&gt;
&lt;li&gt;A function that could be simplified to improve performance.&lt;/li&gt;
&lt;li&gt;A function that uses an inefficient Go structure.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Quality linters&lt;/strong&gt; check the overall quality of code, including consistency, readability, and maintainability.

&lt;ul&gt;
&lt;li&gt;A variable that is used only once.&lt;/li&gt;
&lt;li&gt;A function that is too long.&lt;/li&gt;
&lt;li&gt;A function that is not well documented.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To get a list of supported linters and enabled/disabled linters, you can do the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;golangci-lint &lt;span class="nb"&gt;help &lt;/span&gt;linters
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Integration with IDEs
&lt;/h2&gt;

&lt;p&gt;Golangci-lint offers integrations with major Go IDEs, allowing you to run the linter directly from your IDE.&lt;/p&gt;

&lt;p&gt;To install the IDE extension for Visual Studio Code, open the VS Code Marketplace and search for "golangci-lint". Click on the extension to install it and add it to your configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"go.lintTool"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"golangci-lint"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"go.lintOnSave"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"workspace"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;You can adjust golangci-lint's behavior to suit your needs by configuring it. You can make sure your code is of the highest caliber by taking the effort to configure golangci-lint.&lt;/p&gt;

&lt;p&gt;The following advice will help you configure golangci-lint:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start with a simple setup and add options as you need them.&lt;/li&gt;
&lt;li&gt;Learn more about the various configuration choices by reading the golangci-lint manual.&lt;/li&gt;
&lt;li&gt;Take inspiration from the golangci-lint configuration samples.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I hope this piece clarifies the golangci-lint settings for you.&lt;/p&gt;

</description>
      <category>go</category>
      <category>productivity</category>
      <category>codequality</category>
      <category>cicd</category>
    </item>
  </channel>
</rss>
