github.com/jenkins-x/jx/v2@v2.1.155/pkg/prow/config/branch_protection_test.go (about)

     1  // +build unit
     2  
     3  package config
     4  
     5  import (
     6  	"testing"
     7  
     8  	"github.com/jenkins-x/lighthouse/pkg/config/branchprotection"
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func newBranchProtection() branchprotection.Config {
    13  	return branchprotection.Config{
    14  		Orgs: map[string]branchprotection.Org{
    15  			"org": {
    16  				Repos: map[string]branchprotection.Repo{
    17  					"repo": {
    18  						Policy: branchprotection.Policy{},
    19  						Branches: map[string]branchprotection.Branch{
    20  							"master": {},
    21  						}}}}},
    22  	}
    23  }
    24  
    25  func TestRemoveRepoFromBranchProtection_HappyPath(t *testing.T) {
    26  	t.Parallel()
    27  	bp := newBranchProtection()
    28  
    29  	assert.Contains(t, bp.Orgs["org"].Repos, "repo")
    30  
    31  	err := RemoveRepoFromBranchProtection(&bp, "org/repo")
    32  
    33  	assert.NoError(t, err)
    34  	assert.NotContains(t, bp.Orgs["org"].Repos, "repo")
    35  }
    36  
    37  func TestRemoveRepoFromBranchProtection_NoOrg(t *testing.T) {
    38  	t.Parallel()
    39  	bp := newBranchProtection()
    40  
    41  	err := RemoveRepoFromBranchProtection(&bp, "wrong-org/repo")
    42  
    43  	assert.EqualError(t, err, "no repos found for org wrong-org")
    44  	assert.Contains(t, bp.Orgs["org"].Repos, "repo")
    45  }
    46  
    47  func TestRemoveRepoFromBranchProtection_NoRepo(t *testing.T) {
    48  	t.Parallel()
    49  	bp := newBranchProtection()
    50  
    51  	err := RemoveRepoFromBranchProtection(&bp, "org/wrong-repo")
    52  
    53  	assert.EqualError(t, err, "repo wrong-repo not found in org org")
    54  	assert.Contains(t, bp.Orgs["org"].Repos, "repo")
    55  }