git-module

fork of https://git.lin.moe/gogs/git-module

git clone git://git.lin.moe/fork/git-module.git

 1package git
 2
 3import (
 4	"bytes"
 5	"flag"
 6	"os"
 7	"testing"
 8
 9	"github.com/stretchr/testify/assert"
10)
11
12var testrepo *Repository
13
14func TestMain(m *testing.M) {
15	flag.Parse()
16
17	if testing.Verbose() {
18		SetOutput(os.Stdout)
19	}
20
21	initTestRepo()
22
23	os.Exit(m.Run())
24}
25
26func TestSetPrefix(t *testing.T) {
27	old := logPrefix
28	new := "[custom] "
29	SetPrefix(new)
30	defer SetPrefix(old)
31
32	assert.Equal(t, new, logPrefix)
33}
34
35func Test_log(t *testing.T) {
36	old := logOutput
37	defer SetOutput(old)
38
39	tests := []struct {
40		format    string
41		args      []interface{}
42		expOutput string
43	}{
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.Buffer
61			SetOutput(&buf)
62
63			logf(test.format, test.args...)
64			assert.Equal(t, test.expOutput, buf.String())
65		})
66	}
67}