hugo

Fork of github.com/gohugoio/hugo with reverse pagination support

git clone git://git.shimmy1996.com/hugo.git

git_test.go (2102B)

    1 // Copyright 2017-present The Hugo Authors. All rights reserved.
    2 //
    3 // Licensed under the Apache License, Version 2.0 (the "License");
    4 // you may not use this file except in compliance with the License.
    5 // You may obtain a copy of the License at
    6 // http://www.apache.org/licenses/LICENSE-2.0
    7 //
    8 // Unless required by applicable law or agreed to in writing, software
    9 // distributed under the License is distributed on an "AS IS" BASIS,
   10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   11 // See the License for the specific language governing permissions and
   12 // limitations under the License.
   13 
   14 package releaser
   15 
   16 import (
   17 	"testing"
   18 
   19 	qt "github.com/frankban/quicktest"
   20 )
   21 
   22 func TestGitInfos(t *testing.T) {
   23 	c := qt.New(t)
   24 	skipIfCI(t)
   25 	infos, err := getGitInfos("v0.20", "hugo", "", false)
   26 
   27 	c.Assert(err, qt.IsNil)
   28 	c.Assert(len(infos) > 0, qt.Equals, true)
   29 }
   30 
   31 func TestIssuesRe(t *testing.T) {
   32 	c := qt.New(t)
   33 
   34 	body := `
   35 This is a commit message.
   36 
   37 Updates #123
   38 Fix #345
   39 closes #543
   40 See #456
   41 	`
   42 
   43 	issues := extractIssues(body)
   44 
   45 	c.Assert(len(issues), qt.Equals, 4)
   46 	c.Assert(issues[0], qt.Equals, 123)
   47 	c.Assert(issues[2], qt.Equals, 543)
   48 
   49 	bodyNoIssues := `
   50 This is a commit message without issue refs.
   51 
   52 But it has e #10 to make old regexp confused.
   53 Streets #20.
   54 	`
   55 
   56 	emptyIssuesList := extractIssues(bodyNoIssues)
   57 	c.Assert(len(emptyIssuesList), qt.Equals, 0)
   58 }
   59 
   60 func TestGitVersionTagBefore(t *testing.T) {
   61 	skipIfCI(t)
   62 	c := qt.New(t)
   63 	v1, err := gitVersionTagBefore("v0.18")
   64 	c.Assert(err, qt.IsNil)
   65 	c.Assert(v1, qt.Equals, "v0.17")
   66 }
   67 
   68 func TestTagExists(t *testing.T) {
   69 	skipIfCI(t)
   70 	c := qt.New(t)
   71 	b1, err := tagExists("v0.18")
   72 	c.Assert(err, qt.IsNil)
   73 	c.Assert(b1, qt.Equals, true)
   74 
   75 	b2, err := tagExists("adfagdsfg")
   76 	c.Assert(err, qt.IsNil)
   77 	c.Assert(b2, qt.Equals, false)
   78 }
   79 
   80 func skipIfCI(t *testing.T) {
   81 	if isCI() {
   82 		// Travis has an ancient git with no --invert-grep: https://github.com/travis-ci/travis-ci/issues/6328
   83 		// Also Travis clones very shallowly, making some of the tests above shaky.
   84 		t.Skip("Skip git test on Linux to make Travis happy.")
   85 	}
   86 }