github.com/spotahome/redis-operator@v1.2.4/api/redisfailover/v1/bootstrapping_test.go (about) 1 package v1 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 8 ) 9 10 func generateRedisFailover(name string, bootstrapNode *BootstrapSettings) *RedisFailover { 11 return &RedisFailover{ 12 ObjectMeta: metav1.ObjectMeta{ 13 Name: name, 14 Namespace: "namespace", 15 }, 16 Spec: RedisFailoverSpec{ 17 BootstrapNode: bootstrapNode, 18 }, 19 } 20 } 21 22 func TestBootstrapping(t *testing.T) { 23 tests := []struct { 24 name string 25 expectation bool 26 bootstrapSettings *BootstrapSettings 27 }{ 28 { 29 name: "without BootstrapSettings", 30 expectation: false, 31 }, 32 { 33 name: "with BootstrapSettings", 34 expectation: true, 35 bootstrapSettings: &BootstrapSettings{ 36 Host: "127.0.0.1", 37 Port: "6379", 38 }, 39 }, 40 } 41 42 for _, test := range tests { 43 t.Run(test.name, func(t *testing.T) { 44 rf := generateRedisFailover("test", test.bootstrapSettings) 45 assert.Equal(t, test.expectation, rf.Bootstrapping()) 46 }) 47 } 48 } 49 50 func TestSentinelsAllowed(t *testing.T) { 51 tests := []struct { 52 name string 53 expectation bool 54 bootstrapSettings *BootstrapSettings 55 }{ 56 { 57 name: "without BootstrapSettings", 58 expectation: true, 59 }, 60 { 61 name: "with BootstrapSettings", 62 expectation: false, 63 bootstrapSettings: &BootstrapSettings{ 64 Host: "127.0.0.1", 65 Port: "6379", 66 }, 67 }, 68 { 69 name: "with BootstrapSettings that allows sentinels", 70 expectation: true, 71 bootstrapSettings: &BootstrapSettings{ 72 Host: "127.0.0.1", 73 Port: "6379", 74 AllowSentinels: true, 75 }, 76 }, 77 } 78 79 for _, test := range tests { 80 t.Run(test.name, func(t *testing.T) { 81 rf := generateRedisFailover("test", test.bootstrapSettings) 82 assert.Equal(t, test.expectation, rf.SentinelsAllowed()) 83 }) 84 } 85 }