diff options
author | ᴜɴᴋɴᴡᴏɴ <u@gogs.io> | 2020-02-29 22:24:20 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-29 22:24:20 +0800 |
commit | 8796df8218aa306f1431c17233fbcc3e0811cc4e (patch) | |
tree | 07ba5f0e62ed68064143f029217c82c80f9b652c /internal/testutil/golden_test.go | |
parent | 17ae0ed3eef54d96bd179ff7fec0540cf3024748 (diff) |
conf: add unit tests (#5954)
* conf: add tests for utils.go
* conf: add tests for static.go
* mock os/exec
* Run tests on Windows
* appveyor: fix gcc not found
* computed: add unit tests
* log: add unit tests
* log: fix tests on Windows
* conf: add some tests
* Finish adding tests
* Cover more cases
* Add tests for testutil
* Add more tests
Diffstat (limited to 'internal/testutil/golden_test.go')
-rw-r--r-- | internal/testutil/golden_test.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/internal/testutil/golden_test.go b/internal/testutil/golden_test.go new file mode 100644 index 00000000..05f31399 --- /dev/null +++ b/internal/testutil/golden_test.go @@ -0,0 +1,52 @@ +// Copyright 2020 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package testutil + +import ( + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestUpdate(t *testing.T) { + before := updateRegex + defer func() { + updateRegex = before + }() + + t.Run("no flag", func(t *testing.T) { + updateRegex = nil + assert.False(t, Update("TestUpdate")) + }) + + tests := []struct { + regex string + name string + want bool + }{ + {regex: "", name: "TestUpdate", want: false}, + {regex: "TestNotFound", name: "TestUpdate", want: false}, + + {regex: ".*", name: "TestUpdate", want: true}, + } + for _, test := range tests { + t.Run("", func(t *testing.T) { + updateRegex = &test.regex + assert.Equal(t, test.want, Update(test.name)) + }) + } +} + +func TestAssertGolden(t *testing.T) { + // Make sure it does not blow up + AssertGolden(t, filepath.Join("testdata", "golden"), false, "{\n \"Message\": \"This is a golden file.\"\n}") + AssertGolden(t, filepath.Join("testdata", "golden"), false, []byte("{\n \"Message\": \"This is a golden file.\"\n}")) + + type T struct { + Message string + } + AssertGolden(t, filepath.Join("testdata", "golden"), false, T{"This is a golden file."}) +} |