github.com/willabides/benchdiff@v0.9.1/cmd/benchdiff/internal/testutil_test.go (about)

     1  package internal
     2  
     3  import (
     4  	"os"
     5  	"os/exec"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func mustSetEnv(t *testing.T, env map[string]string) {
    12  	t.Helper()
    13  	for k, v := range env {
    14  		assert.NoError(t, os.Setenv(k, v))
    15  	}
    16  }
    17  
    18  func mustGit(t *testing.T, repoPath string, args ...string) []byte {
    19  	t.Helper()
    20  	mustSetEnv(t, map[string]string{
    21  		"GIT_AUTHOR_NAME":     "author",
    22  		"GIT_AUTHOR_EMAIL":    "author@localhost",
    23  		"GIT_COMMITTER_NAME":  "committer",
    24  		"GIT_COMMITTER_EMAIL": "committer@localhost",
    25  	})
    26  	got, err := runGitCmd(nil, "git", repoPath, args...)
    27  	assert.NoErrorf(t, err, "error running git:\noutput: %v", string(got))
    28  	return got
    29  }
    30  
    31  func mustGo(t *testing.T, path string, args ...string) []byte {
    32  	t.Helper()
    33  	cmd := exec.Command("go", args...)
    34  	cmd.Dir = path
    35  	got, err := cmd.Output()
    36  	assert.NoErrorf(t, err, "error running go:\noutput: %v", string(got))
    37  	return got
    38  }