Writing End-to-End Tests

We will continue to use Ginkgo and Gomega as our testing framework, but we will invoke multi-git as a command-line program and will not test at the Go-program level.

There are several interesting parts to test such as the environment, the happy path, and error handling. We will tackle all of them.

Testing the environment

A big part of interacting with multi-git is telling it where the root directory of all the git repos it should operate on is as well as the names of these repos (the sub-directories). As you recall, this is done by setting two environment variables: MG_ROOT and MG_REPOS. The unit tests for the repo_manager package tested the input to the NewRepoManager() function, but it didn’t check the reading and parsing of environment variables themselves. Let’s write some tests at this level. As you recall, RunMultiGit sets the MG_ROOT and MG_REPOS environment variables for us. The two tests are pretty simple. The first test passes a non-existent directory as the root directory. The second test passes an empty repository list. Both tests verify that RunMultiGit() returns an error and also checks the output to ensure the correct error message was returned.

    Context("Tests for empty/undefined environment failure cases", func() {
        It("Should fail with invalid base dir", func() {
            output, err := RunMultiGit("status", false, "/no-such-dir", repoList)
            Ω(err).ShouldNot(BeNil())
            suffix := "base dir: '/no-such-dir/' doesn't exist\n"
            Ω(output).Should(HaveSuffix(suffix))
        })

        It("Should fail with empty repo list", func() {
            output, err := RunMultiGit("status", false, baseDir, repoList)
            Ω(err).ShouldNot(BeNil())
            Ω(output).Should(ContainSubstring("repo list can't be
...