github.com/gohugoio/hugo@v0.88.1/releaser/git_test.go (about)

     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  
    50  func TestGitVersionTagBefore(t *testing.T) {
    51  	skipIfCI(t)
    52  	c := qt.New(t)
    53  	v1, err := gitVersionTagBefore("v0.18")
    54  	c.Assert(err, qt.IsNil)
    55  	c.Assert(v1, qt.Equals, "v0.17")
    56  }
    57  
    58  func TestTagExists(t *testing.T) {
    59  	skipIfCI(t)
    60  	c := qt.New(t)
    61  	b1, err := tagExists("v0.18")
    62  	c.Assert(err, qt.IsNil)
    63  	c.Assert(b1, qt.Equals, true)
    64  
    65  	b2, err := tagExists("adfagdsfg")
    66  	c.Assert(err, qt.IsNil)
    67  	c.Assert(b2, qt.Equals, false)
    68  }
    69  
    70  func skipIfCI(t *testing.T) {
    71  	if isCI() {
    72  		// Travis has an ancient git with no --invert-grep: https://github.com/travis-ci/travis-ci/issues/6328
    73  		// Also Travis clones very shallowly, making some of the tests above shaky.
    74  		t.Skip("Skip git test on Linux to make Travis happy.")
    75  	}
    76  }