1package git23import (4 "bytes"5 "flag"6 "os"7 "testing"89 "github.com/stretchr/testify/assert"10)1112var testrepo *Repository1314func TestMain(m *testing.M) {15 flag.Parse()1617 if testing.Verbose() {18 SetOutput(os.Stdout)19 }2021 initTestRepo()2223 os.Exit(m.Run())24}2526func TestSetPrefix(t *testing.T) {27 old := logPrefix28 new := "[custom] "29 SetPrefix(new)30 defer SetPrefix(old)3132 assert.Equal(t, new, logPrefix)33}3435func Test_log(t *testing.T) {36 old := logOutput37 defer SetOutput(old)3839 tests := []struct {40 format string41 args []interface{}42 expOutput string43 }{44 {45 format: "",46 expOutput: "[git-module] \n",47 },48 {49 format: "something",50 expOutput: "[git-module] something\n",51 },52 {53 format: "val: %v",54 args: []interface{}{123},55 expOutput: "[git-module] val: 123\n",56 },57 }58 for _, test := range tests {59 t.Run("", func(t *testing.T) {60 var buf bytes.Buffer61 SetOutput(&buf)6263 logf(test.format, test.args...)64 assert.Equal(t, test.expOutput, buf.String())65 })66 }67}