diff options
author | Ethan Koenig <ethantkoenig@gmail.com> | 2017-12-15 13:11:02 -0800 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2017-12-15 23:11:02 +0200 |
commit | befa7445d254cc88662015222c85ccd4c96b9a10 (patch) | |
tree | d9d7bc81d0eb05c026e8b6688871b38695d5af00 /models | |
parent | bde0409433531b024e30cf1a4d3e44051631ed85 (diff) | |
download | gitea-befa7445d254cc88662015222c85ccd4c96b9a10.tar.gz gitea-befa7445d254cc88662015222c85ccd4c96b9a10.zip |
Unit tests for routers/repo/issue_label (#3198)
Diffstat (limited to 'models')
-rw-r--r-- | models/unit_tests.go | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/models/unit_tests.go b/models/unit_tests.go index ff7a87da30..25808a9486 100644 --- a/models/unit_tests.go +++ b/models/unit_tests.go @@ -17,6 +17,7 @@ import ( "github.com/go-xorm/xorm" "github.com/stretchr/testify/assert" "gopkg.in/testfixtures.v2" + "net/url" ) // NonexistentID an ID that will never exist @@ -28,9 +29,10 @@ var giteaRoot string // MainTest a reusable TestMain(..) function for unit tests that need to use a // test database. Creates the test database, and sets necessary settings. func MainTest(m *testing.M, pathToGiteaRoot string) { + var err error giteaRoot = pathToGiteaRoot fixturesDir := filepath.Join(pathToGiteaRoot, "models", "fixtures") - if err := createTestEngine(fixturesDir); err != nil { + if err = createTestEngine(fixturesDir); err != nil { fmt.Fprintf(os.Stderr, "Error creating test engine: %v\n", err) os.Exit(1) } @@ -41,6 +43,13 @@ func MainTest(m *testing.M, pathToGiteaRoot string) { setting.SSH.Domain = "try.gitea.io" setting.RepoRootPath = filepath.Join(os.TempDir(), "repos") setting.AppDataPath = filepath.Join(os.TempDir(), "appdata") + setting.AppWorkPath = pathToGiteaRoot + setting.StaticRootPath = pathToGiteaRoot + setting.GravatarSourceURL, err = url.Parse("https://secure.gravatar.com/avatar/") + if err != nil { + fmt.Fprintf(os.Stderr, "Error url.Parse: %v\n", err) + os.Exit(1) + } os.Exit(m.Run()) } @@ -140,6 +149,14 @@ func AssertNotExistsBean(t *testing.T, bean interface{}, conditions ...interface assert.False(t, exists) } +// AssertExistsIf asserts that a bean exists or does not exist, depending on +// what is expected. +func AssertExistsIf(t *testing.T, expected bool, bean interface{}, conditions ...interface{}) { + exists, err := loadBeanIfExists(bean, conditions...) + assert.NoError(t, err) + assert.Equal(t, expected, exists) +} + // AssertSuccessfulInsert assert that beans is successfully inserted func AssertSuccessfulInsert(t *testing.T, beans ...interface{}) { _, err := x.Insert(beans...) |