Skip to content

Commit

Permalink
Merge pull request #42 from izumin5210/izumin5210/e2e
Browse files Browse the repository at this point in the history
Add test for specifying tool versions
  • Loading branch information
izumin5210 authored Oct 23, 2019
2 parents 90a039d + 010715d commit c7a85d8
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 23 deletions.
4 changes: 2 additions & 2 deletions tests/e2e/.snapshots/TestGex_Dep-add_2_tools-tools.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/e2e/.snapshots/TestGex_Mod-add_2_tools-tools.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 15 additions & 5 deletions tests/e2e/main_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package main

import (
"bytes"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"testing"
)

Expand Down Expand Up @@ -57,7 +59,7 @@ func invokeE2ETest(t *testing.T, tm TestMode) {
})

t.Run("add 2 tools", func(t *testing.T) {
tc.ExecCmd(t, gexCmd, "--add", "github.com/srvc/wraperr/cmd/wraperr", "--add", "golang.org/x/lint/golint")
tc.ExecCmd(t, gexCmd, "--add", "github.com/golang/mock/mockgen", "--add", "golang.org/x/lint/golint")
tc.SnapshotManifest(t)
})

Expand All @@ -76,18 +78,26 @@ func invokeE2ETest(t *testing.T, tm TestMode) {
tc.SnapshotManifest(t)
})

t.Run("add tools that its root proejct has been added", func(t *testing.T) {
tc.ExecCmd(t, gexCmd, "--add", "github.com/golang/mock/mockgen")
t.Run("add tools with version specification", func(t *testing.T) {
const gexVersion = "0.5.1"
tc.ExecCmd(t, gexCmd, "--add", "github.com/izumin5210/gex/cmd/gex@v"+gexVersion)
tc.SnapshotManifest(t)

var outW, errW bytes.Buffer
tc.ExecCmdWithOut(t, tc.Bin("gex"), []string{"--version"}, &outW, &errW)

if got, want := outW.String(), gexVersion; !strings.Contains(got, want) {
t.Errorf("`bin/gex --version` prints %q, want to contain %q", got, want)
}
})

t.Run("generated binaries with `gex --add`", func(t *testing.T) {
tc.CheckBinaries(t, []string{"protoc-gen-grpc-gateway", "wraperr", "golint", "protoc-gen-swagger", "protoc-gen-gogo", "protoc-gen-gogofast", "mockgen"})
tc.CheckBinaries(t, []string{"protoc-gen-grpc-gateway", "mockgen", "golint", "protoc-gen-swagger", "protoc-gen-gogo", "protoc-gen-gogofast", "gex"})
})

t.Run("generated binaries with `go generate`", func(t *testing.T) {
tc.RemoveBinaries(t)
tc.ExecCmd(t, "go", "generate", "tools.go")
tc.CheckBinaries(t, []string{"protoc-gen-grpc-gateway", "wraperr", "golint", "protoc-gen-swagger", "protoc-gen-gogo", "protoc-gen-gogofast", "mockgen"})
tc.CheckBinaries(t, []string{"protoc-gen-grpc-gateway", "mockgen", "golint", "protoc-gen-swagger", "protoc-gen-gogo", "protoc-gen-gogofast", "gex"})
})
}
13 changes: 11 additions & 2 deletions tests/e2e/test_context.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"io"
"io/ioutil"
"os"
"os/exec"
Expand Down Expand Up @@ -117,12 +118,20 @@ func (tc *TestContext) RemoveBinaries(t *testing.T) {
tc.checkErr(t, os.RemoveAll(tc.binDir()))
}

func (tc *TestContext) Bin(name string) string {
return filepath.Join(tc.binDir(), name)
}

func (tc *TestContext) ExecCmd(t *testing.T, name string, args ...string) {
tc.ExecCmdWithOut(t, name, args, NewTestWriter(t), NewTestWriter(t))
}

func (tc *TestContext) ExecCmdWithOut(t *testing.T, name string, args []string, outW, errW io.Writer) {
cmd := exec.Command(name, args...)
cmd.Dir = tc.rootDir()
cmd.Env = tc.environ()
cmd.Stdout = NewTestWriter(t)
cmd.Stderr = NewTestWriter(t)
cmd.Stdout = outW
cmd.Stderr = errW
tc.checkErr(t, cmd.Run())
}

Expand Down

0 comments on commit c7a85d8

Please sign in to comment.