Skip to content

Commit

Permalink
feat(security): Address PR feedback
Browse files Browse the repository at this point in the history
Address Lenny's PR feedback about unit tests

Signed-off-by: Jim Wang <[email protected]>
  • Loading branch information
jim-wang-intel committed Feb 4, 2021
1 parent ad04278 commit 851e414
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions internal/security/bootstrapper/helper/redis_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,31 @@ func TestGenerateConfig(t *testing.T) {
confFile, err := os.OpenFile(testConfFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)
require.NoError(t, err)
defer func() {
err = confFile.Close()
require.NoError(t, err)
err = os.RemoveAll(testConfFile)
require.NoError(t, err)
_ = confFile.Close()
_ = os.RemoveAll(testConfFile)
}()

fw := bufio.NewWriter(confFile)
testFakePwd := "123456abcdefg!@#$%^&"

err = GenerateConfig(fw, &testFakePwd)
require.NoError(t, err)
require.NoError(t, fw.Flush())
err = fw.Flush()
require.NoError(t, err)

inputFile, err := os.Open(testConfFile)
require.NoError(t, err)
defer inputFile.Close()
inputScanner := bufio.NewScanner(inputFile)
inputScanner.Split(bufio.ScanLines)
lineCount := 0
var outputlines []string
// Read until a newline for each Scan
for inputScanner.Scan() {
lineCount++
line := inputScanner.Text()
require.Contains(t, line, testFakePwd)
outputlines = append(outputlines, line)
}
require.Equal(t, 2, lineCount)
require.Equal(t, 2, len(outputlines))
require.Equal(t, "user default on allkeys +@all -@dangerous >"+testFakePwd, outputlines[0])
require.Equal(t, "requirepass "+testFakePwd, outputlines[1])
}

0 comments on commit 851e414

Please sign in to comment.