gitlab.com/sparetimecoders/build-tools@v0.1.0/pkg/ci/teamcity_test.go (about)

     1  package ci
     2  
     3  import (
     4  	"github.com/stretchr/testify/assert"
     5  	"gitlab.com/sparetimecoders/build-tools/pkg/vcs"
     6  	"io/ioutil"
     7  	"os"
     8  	"path/filepath"
     9  	"testing"
    10  )
    11  
    12  func TestTeamCityCI_Name(t *testing.T) {
    13  	ci := &TeamCity{}
    14  
    15  	assert.Equal(t, "TeamCity", ci.Name())
    16  }
    17  
    18  func TestTeamCityCI_BranchReplaceSlash(t *testing.T) {
    19  	ci := &TeamCity{CIBranchName: "refs/heads/feature1"}
    20  
    21  	assert.Equal(t, "refs_heads_feature1", ci.BranchReplaceSlash())
    22  }
    23  
    24  func TestTeamCityCI_BranchReplaceSlash_VCS_Fallback(t *testing.T) {
    25  	ci := &TeamCity{Common: &Common{VCS: vcs.NewMockVcsWithBranch("refs/heads/feature1")}}
    26  
    27  	assert.Equal(t, "refs_heads_feature1", ci.BranchReplaceSlash())
    28  }
    29  
    30  func TestTeamCityCI_BuildName(t *testing.T) {
    31  	ci := &TeamCity{CIBuildName: "project"}
    32  
    33  	assert.Equal(t, "project", ci.BuildName())
    34  }
    35  
    36  func TestTeamCityCI_BuildName_VCS_Fallback(t *testing.T) {
    37  	oldpwd, _ := os.Getwd()
    38  	name, _ := ioutil.TempDir(os.TempDir(), "build-tools")
    39  	defer func() { _ = os.RemoveAll(name) }()
    40  	_ = os.Chdir(name)
    41  	defer func() { _ = os.Chdir(oldpwd) }()
    42  
    43  	ci := &TeamCity{Common: &Common{VCS: vcs.NewMockVcs()}}
    44  
    45  	assert.Equal(t, filepath.Base(name), ci.BuildName())
    46  }
    47  
    48  func TestTeamCityCI_Commit(t *testing.T) {
    49  	ci := &TeamCity{CICommit: "abc123"}
    50  
    51  	assert.Equal(t, "abc123", ci.Commit())
    52  }
    53  
    54  func TestTeamCityCI_Commit_VCS_Fallback(t *testing.T) {
    55  	ci := &TeamCity{Common: &Common{VCS: vcs.NewMockVcs()}}
    56  
    57  	assert.Equal(t, "fallback-sha", ci.Commit())
    58  }
    59  
    60  func TestTeamCityCI_Configured(t *testing.T) {
    61  	ci := &TeamCity{CIBuildName: "project"}
    62  
    63  	assert.True(t, ci.Configured())
    64  }