Testing cli tool with logging

This page summarizes the projects mentioned and recommended in the original post on dev.to

Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
  • cobra

    A Commander for modern Go CLI interactions

    and probably something else will be added in the future. The final kind of launch command would like to see such djob [options] - command. Command is the command (with arguments to run). -- should separate the arguments of the utility from the arguments of the program to run. There are several excellent solutions for working with command-line arguments, such as spf13/cobra or urfave/cli. But they’re good for building an interface out of a lot of commands, and for one (as in my example) they’re redundant. So I used the flag library. I have defined the following structure with arguments:

  • urfave/cli

    A simple, fast, and fun package for building command line apps in Go (by urfave)

    and probably something else will be added in the future. The final kind of launch command would like to see such djob [options] - command. Command is the command (with arguments to run). -- should separate the arguments of the utility from the arguments of the program to run. There are several excellent solutions for working with command-line arguments, such as spf13/cobra or urfave/cli. But they’re good for building an interface out of a lot of commands, and for one (as in my example) they’re redundant. So I used the flag library. I have defined the following structure with arguments:

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

  • logrus

    Structured, pluggable logging for Go.

    Before moving to testing I will talk about logging. Logging is another component that matters for testing implementation. In any case, it is required in almost any program, including the utility I describe. I used the library logrus, because it has the ability to intercept logs with hooks. And I used this feature to read logs during testing. At the same time, the code of the main function itself does not have to adapt to tests.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts