Skip to content

Commit

Permalink
add --tls flag by default for redis client & add unit test (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
markdboyd authored Jul 13, 2023
1 parent ef1b939 commit 092a812
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
9 changes: 7 additions & 2 deletions service/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ func (p redis) Match(si models.ServiceInstance) bool {
}

func (p redis) Launch(localPort int, creds models.Credentials) error {
return launcher.StartShell("redis-cli", []string{
return launcher.StartShell("redis-cli", getRedisLaunchFlags(localPort, creds))
}

func getRedisLaunchFlags(localPort int, creds models.Credentials) []string {
return []string{
"--tls",
"-p", strconv.Itoa(localPort),
"-a", creds.GetPassword(),
})
}
}

// Redis is the service singleton.
Expand Down
41 changes: 41 additions & 0 deletions service/redis_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package service

import (
"reflect"
"strconv"
"testing"

"github.com/18F/cf-service-connect/models"
Expand All @@ -13,6 +15,30 @@ type redisMatchTest struct {
expected bool
}

type mockCredentials struct {
mockPassword string
}

func (m mockCredentials) GetPassword() string {
return m.mockPassword
}

func (m mockCredentials) GetDBName() string {
return ""
}

func (m mockCredentials) GetUsername() string {
return ""
}

func (m mockCredentials) GetHost() string {
return ""
}

func (m mockCredentials) GetPort() string {
return ""
}

func TestRedisMatch(t *testing.T) {
tests := []redisMatchTest{
{
Expand Down Expand Up @@ -46,3 +72,18 @@ func TestRedisMatch(t *testing.T) {
assert.Equal(t, result, test.expected)
}
}

func TestGetRedisLaunchFlags(t *testing.T) {
mockCredentialsClient := &mockCredentials{
mockPassword: "fake-password",
}
flags := getRedisLaunchFlags(53839, mockCredentialsClient)
expectedFlags := []string{
"--tls",
"-p", strconv.Itoa(53839),
"-a", "fake-password",
}
if !reflect.DeepEqual(flags, expectedFlags) {
t.Fatalf("expected: %s, got: %s", expectedFlags, flags)
}
}

0 comments on commit 092a812

Please sign in to comment.