diff --git a/modules/newrelic/widget.go b/modules/newrelic/widget.go index 21bb0f59..c35b1d69 100644 --- a/modules/newrelic/widget.go +++ b/modules/newrelic/widget.go @@ -64,7 +64,7 @@ func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string { revisions := []string{} for _, deploy := range deploys { - if (deploy.Revision != "") && utils.Exclude(revisions, deploy.Revision) { + if (deploy.Revision != "") && utils.DoesNotInclude(revisions, deploy.Revision) { lineColor := "white" if wtf.IsToday(deploy.Timestamp) { lineColor = "lightblue" diff --git a/utils/text.go b/utils/text.go index 1e986e77..acf882a7 100644 --- a/utils/text.go +++ b/utils/text.go @@ -30,15 +30,15 @@ func HighlightableHelper(view *tview.TextView, input string, idx, offset int) st fmtStr := fmt.Sprintf(`["%d"][""]`, idx) _, _, w, _ := view.GetInnerRect() fmtStr += input - fmtStr += PadRow(offset, w+1) + fmtStr += RowPadding(offset, w+1) fmtStr += `[""]` + "\n" return fmtStr } -// PadRow returns a padding for a row to make it the full width of the containing widget. +// RowPadding returns a padding for a row to make it the full width of the containing widget. // Useful for ensurig row highlighting spans the full width (I suspect tcell has a better // way to do this, but I haven't yet found it) -func PadRow(offset int, max int) string { +func RowPadding(offset int, max int) string { padSize := max - offset if padSize < 0 { padSize = 0 diff --git a/utils/text_test.go b/utils/text_test.go index e26baeec..5bd3fb2f 100644 --- a/utils/text_test.go +++ b/utils/text_test.go @@ -12,8 +12,13 @@ func Test_CenterText(t *testing.T) { Equal(t, " cat ", CenterText("cat", 9)) } -func Test_PadRow(t *testing.T) { - Equal(t, "", PadRow(0, 0)) - Equal(t, "", PadRow(5, 2)) - Equal(t, " ", PadRow(1, 2)) +func Test_HighlightableHelper(t *testing.T) { + +} + +func Test_RowPadding(t *testing.T) { + Equal(t, "", RowPadding(0, 0)) + Equal(t, "", RowPadding(5, 2)) + Equal(t, " ", RowPadding(1, 2)) + Equal(t, " ", RowPadding(0, 5)) } diff --git a/utils/utils.go b/utils/utils.go index 52969c70..3bd4fe71 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -21,6 +21,26 @@ const ( TimestampFormat = "2006-01-02T15:04:05-0700" ) +// DoesNotInclude takes a slice of strings and a target string and returns +// TRUE if the slice does not include the target, FALSE if it does +// +// Example: +// +// x := DoesNotInclude([]string{"cat", "dog", "rat"}, "dog") +// > false +// +// x := DoesNotInclude([]string{"cat", "dog", "rat"}, "pig") +// > true +// +func DoesNotInclude(strs []string, val string) bool { + for _, str := range strs { + if val == str { + return false + } + } + return true +} + // ExecuteCommand executes an external command on the local machine as the current user func ExecuteCommand(cmd *exec.Cmd) string { if cmd == nil { @@ -49,23 +69,6 @@ func ExecuteCommand(cmd *exec.Cmd) string { return str } -// Exclude takes a slice of strings and a target string and returns the contents of the original -// slice of strings without the target string in it -// -// Example: -// -// x := Exclude([]string{"cat", "dog", "rat"}, "dog") -// > []string{"cat", "rat"} -// -func Exclude(strs []string, val string) bool { - for _, str := range strs { - if val == str { - return false - } - } - return true -} - // FindMatch takes a regex pattern and a string of data and returns back all the matches // in that string func FindMatch(pattern string, data string) [][]string { diff --git a/utils/utils_test.go b/utils/utils_test.go index 50446827..06191de8 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -2,11 +2,17 @@ package utils import ( "os/exec" + "reflect" "testing" . "github.com/stretchr/testify/assert" ) +func Test_DoesNotInclude(t *testing.T) { + Equal(t, true, DoesNotInclude([]string{"cat", "dog", "rat"}, "bat")) + Equal(t, false, DoesNotInclude([]string{"cat", "dog", "rat"}, "dog")) +} + func Test_ExecuteCommand(t *testing.T) { tests := []struct { name string @@ -44,7 +50,26 @@ func Test_FindMatch(t *testing.T) { Equal(t, expected, result) } -func Test_ExcludeWhenTrue(t *testing.T) { - Equal(t, true, Exclude([]string{"cat", "dog", "rat"}, "bat")) - Equal(t, false, Exclude([]string{"cat", "dog", "rat"}, "dog")) +func Test_ReadFileBytes(t *testing.T) { + tests := []struct { + name string + file string + expected []byte + }{ + { + name: "with non-existant file", + file: "/tmp/junk-daa6bf613f4c.md", + expected: []byte{}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + actual, _ := ReadFileBytes(tt.file) + + if reflect.DeepEqual(tt.expected, actual) == false { + t.Errorf("\nexpected: %q\n got: %q", tt.expected, actual) + } + }) + } }