gitlab.com/jfprevost/gitlab-runner-notlscheck@v11.11.4+incompatible/common/network_test.go (about)

     1  package common
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestCacheCheckPolicy(t *testing.T) {
    10  	for num, tc := range []struct {
    11  		object      CachePolicy
    12  		subject     CachePolicy
    13  		expected    bool
    14  		expectErr   bool
    15  		description string
    16  	}{
    17  		{CachePolicyPullPush, CachePolicyPull, true, false, "pull-push allows pull"},
    18  		{CachePolicyPullPush, CachePolicyPush, true, false, "pull-push allows push"},
    19  		{CachePolicyUndefined, CachePolicyPull, true, false, "undefined allows pull"},
    20  		{CachePolicyUndefined, CachePolicyPush, true, false, "undefined allows push"},
    21  		{CachePolicyPull, CachePolicyPull, true, false, "pull allows pull"},
    22  		{CachePolicyPull, CachePolicyPush, false, false, "pull forbids push"},
    23  		{CachePolicyPush, CachePolicyPull, false, false, "push forbids pull"},
    24  		{CachePolicyPush, CachePolicyPush, true, false, "push allows push"},
    25  		{"unknown", CachePolicyPull, false, true, "unknown raises error on pull"},
    26  		{"unknown", CachePolicyPush, false, true, "unknown raises error on push"},
    27  	} {
    28  		cache := Cache{Policy: tc.object}
    29  
    30  		result, err := cache.CheckPolicy(tc.subject)
    31  		if tc.expectErr {
    32  			assert.Errorf(t, err, "case %d: %s", num, tc.description)
    33  		} else {
    34  			assert.NoErrorf(t, err, "case %d: %s", num, tc.description)
    35  		}
    36  
    37  		assert.Equal(t, tc.expected, result, "case %d: %s", num, tc.description)
    38  	}
    39  }