github.com/databricks/cli@v0.203.0/bundle/config/mutator/validate_git_details_test.go (about)

     1  package mutator
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/databricks/cli/bundle"
     8  	"github.com/databricks/cli/bundle/config"
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestValidateGitDetailsMatchingBranches(t *testing.T) {
    13  	bundle := &bundle.Bundle{
    14  		Config: config.Root{
    15  			Bundle: config.Bundle{
    16  				Git: config.Git{
    17  					Branch:       "main",
    18  					ActualBranch: "main",
    19  				},
    20  			},
    21  		},
    22  	}
    23  
    24  	m := ValidateGitDetails()
    25  	err := m.Apply(context.Background(), bundle)
    26  
    27  	assert.NoError(t, err)
    28  }
    29  
    30  func TestValidateGitDetailsNonMatchingBranches(t *testing.T) {
    31  	bundle := &bundle.Bundle{
    32  		Config: config.Root{
    33  			Bundle: config.Bundle{
    34  				Git: config.Git{
    35  					Branch:       "main",
    36  					ActualBranch: "feature",
    37  				},
    38  			},
    39  		},
    40  	}
    41  
    42  	m := ValidateGitDetails()
    43  	err := m.Apply(context.Background(), bundle)
    44  
    45  	expectedError := "not on the right Git branch:\n  expected according to configuration: main\n  actual: feature\nuse --force to override"
    46  	assert.EqualError(t, err, expectedError)
    47  }
    48  
    49  func TestValidateGitDetailsNotUsingGit(t *testing.T) {
    50  	bundle := &bundle.Bundle{
    51  		Config: config.Root{
    52  			Bundle: config.Bundle{
    53  				Git: config.Git{
    54  					Branch:       "main",
    55  					ActualBranch: "",
    56  				},
    57  			},
    58  		},
    59  	}
    60  
    61  	m := ValidateGitDetails()
    62  	err := m.Apply(context.Background(), bundle)
    63  
    64  	assert.NoError(t, err)
    65  }