-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: everettraven <[email protected]>
- Loading branch information
1 parent
2c9996a
commit 8830ece
Showing
10 changed files
with
405 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
buoy | ||
dist/ | ||
dist/ | ||
|
||
cover.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package models | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/charmbracelet/bubbles/viewport" | ||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/everettraven/buoy/pkg/charm/models/panels" | ||
"github.com/everettraven/buoy/pkg/charm/styles" | ||
"github.com/everettraven/buoy/pkg/types" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDashboardUpdate(t *testing.T) { | ||
panels := []tea.Model{ | ||
panels.NewItem(types.Item{ | ||
PanelBase: types.PanelBase{ | ||
Name: "test", | ||
}, | ||
}, viewport.New(10, 10), styles.Theme{}), | ||
} | ||
|
||
d := NewDashboard(DefaultDashboardKeys, styles.Theme{}, panels...) | ||
|
||
t.Log("WindowSizeUpdate") | ||
d.Update(tea.WindowSizeMsg{Width: 50, Height: 50}) | ||
assert.Equal(t, 50, d.width) | ||
|
||
t.Log("toggle detailed help") | ||
d.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("ctrl+h")}) | ||
assert.True(t, d.help.ShowAll) | ||
|
||
t.Log("quit the program") | ||
_, cmd := d.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("q")}) | ||
assert.Equal(t, cmd(), tea.Quit()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package panels | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/charmbracelet/bubbles/viewport" | ||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/everettraven/buoy/pkg/charm/styles" | ||
"github.com/everettraven/buoy/pkg/types" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestItemUpdate(t *testing.T) { | ||
item := NewItem(types.Item{}, viewport.New(10, 10), styles.Theme{}) | ||
item.Update(tea.WindowSizeMsg{Width: 50, Height: 50}) | ||
assert.Equal(t, 50, item.viewport.Width) | ||
assert.Equal(t, 25, item.viewport.Height) | ||
} | ||
|
||
func TestItemViewWithError(t *testing.T) { | ||
item := NewItem(types.Item{}, viewport.New(10, 10), styles.Theme{}) | ||
err := errors.New("some error") | ||
item.SetError(err) | ||
assert.Equal(t, err.Error(), item.View()) | ||
} | ||
|
||
func TestViewWithContent(t *testing.T) { | ||
item := NewItem(types.Item{}, viewport.New(50, 50), styles.Theme{}) | ||
item.SetContent("some content") | ||
assert.Contains(t, item.View(), "some content") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package panels | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/everettraven/buoy/pkg/charm/styles" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestEnterSearchMode(t *testing.T) { | ||
logs := NewLogs(DefaultLogsKeys, nil, styles.Theme{}) | ||
logs.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("/")}) | ||
assert.Equal(t, logs.mode, modeSearching) | ||
} | ||
|
||
func TestExecuteSearch(t *testing.T) { | ||
logs := NewLogs(DefaultLogsKeys, nil, styles.Theme{}) | ||
logs.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("/")}) | ||
logs.Update(tea.KeyMsg{Type: tea.KeyEnter}) | ||
assert.Equal(t, logs.mode, modeSearched) | ||
} | ||
|
||
func TestExitSearchMode(t *testing.T) { | ||
logs := NewLogs(DefaultLogsKeys, nil, styles.Theme{}) | ||
logs.mode = modeSearching | ||
logs.searchbar.Focus() | ||
logs.Update(tea.KeyMsg{Type: tea.KeyEsc}) | ||
assert.Equal(t, logs.mode, modeLogs) | ||
assert.False(t, logs.searchbar.Focused()) | ||
|
||
logs.mode = modeSearched | ||
logs.searchbar.Focus() | ||
logs.Update(tea.KeyMsg{Type: tea.KeyEsc}) | ||
assert.Equal(t, logs.mode, modeLogs) | ||
assert.False(t, logs.searchbar.Focused()) | ||
} | ||
|
||
func TestSearchModeToggle(t *testing.T) { | ||
logs := NewLogs(DefaultLogsKeys, nil, styles.Theme{}) | ||
logs.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("/")}) | ||
logs.Update(tea.KeyMsg{Type: tea.KeyCtrlS}) | ||
assert.True(t, logs.strictSearch) | ||
logs.Update(tea.KeyMsg{Type: tea.KeyCtrlS}) | ||
assert.False(t, logs.strictSearch) | ||
} | ||
|
||
func TestSearchLogs(t *testing.T) { | ||
t.Log("strict search") | ||
logs := NewLogs(DefaultLogsKeys, nil, styles.Theme{}) | ||
logs.strictSearch = true | ||
logs.content = "some log line\nlog line with a search term\n" | ||
logs.viewport.Width = 50 | ||
logs.searchbar.SetValue("search") | ||
match := logs.searchLogs() | ||
assert.Equal(t, "log line with a search term\n", match) | ||
|
||
t.Log("fuzzy search") | ||
logs.searchbar.SetValue("sll") | ||
logs.strictSearch = false | ||
match = logs.searchLogs() | ||
assert.Equal(t, "some log line\n", match) | ||
} | ||
|
||
func TestLogsWindowSizeUpdate(t *testing.T) { | ||
logs := NewLogs(DefaultLogsKeys, nil, styles.Theme{}) | ||
logs.Update(tea.WindowSizeMsg{Width: 100, Height: 100}) | ||
assert.Equal(t, logs.viewport.Width, 100) | ||
assert.Equal(t, logs.viewport.Height, 50) | ||
} | ||
|
||
func TestLogsAddContent(t *testing.T) { | ||
logs := NewLogs(DefaultLogsKeys, nil, styles.Theme{}) | ||
logs.AddContent("some log line\n") | ||
assert.Equal(t, "\nsome log line\n", logs.content) | ||
assert.True(t, logs.contentUpdated) | ||
|
||
logs.Update(tea.KeyMsg{Type: tea.KeyDown}) | ||
assert.False(t, logs.contentUpdated) | ||
} | ||
|
||
func TestLogsViewWithError(t *testing.T) { | ||
logs := NewLogs(DefaultLogsKeys, nil, styles.Theme{}) | ||
err := errors.New("some error") | ||
logs.SetError(err) | ||
assert.Equal(t, err, logs.err) | ||
assert.Equal(t, err.Error(), logs.View()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package panels | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/everettraven/buoy/pkg/charm/styles" | ||
buoytypes "github.com/everettraven/buoy/pkg/types" | ||
"github.com/stretchr/testify/assert" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
"k8s.io/apimachinery/pkg/types" | ||
) | ||
|
||
func TestTableUpdate(t *testing.T) { | ||
t.Log("WindowSizeUpdate") | ||
table := NewTable(DefaultTableKeys, &buoytypes.Table{}, styles.Theme{}) | ||
table.Update(tea.WindowSizeMsg{Width: 50, Height: 50}) | ||
assert.Equal(t, 50, table.viewport.Width) | ||
assert.Equal(t, 25, table.viewport.Height) | ||
|
||
t.Log("toggle view mode on") | ||
table.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("v")}) | ||
assert.Equal(t, modeView, table.mode) | ||
|
||
t.Log("toggle view mode off") | ||
table.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("v")}) | ||
assert.Equal(t, modeTable, table.mode) | ||
} | ||
|
||
func TestAddOrUpdate(t *testing.T) { | ||
table := NewTable(DefaultTableKeys, &buoytypes.Table{ | ||
Columns: []buoytypes.Column{ | ||
{Header: "Name", Width: 10, Path: "metadata.name"}, | ||
}, | ||
}, styles.Theme{}) | ||
|
||
t.Log("add a row") | ||
u := &unstructured.Unstructured{} | ||
u.SetName("test") | ||
u.SetNamespace("test-ns") | ||
u.SetUID(types.UID("test")) | ||
table.AddOrUpdate(u) | ||
assert.Len(t, table.rows, 1) | ||
assert.NotNil(t, table.rows[types.UID("test")].Row) | ||
assert.Equal(t, &types.NamespacedName{Namespace: "test-ns", Name: "test"}, table.rows[types.UID("test")].Identifier) | ||
|
||
t.Log("update a row") | ||
u.SetName("test2") | ||
table.AddOrUpdate(u) | ||
assert.Len(t, table.rows, 1) | ||
assert.NotNil(t, table.rows[types.UID("test")].Row) | ||
assert.Equal(t, &types.NamespacedName{Namespace: "test-ns", Name: "test2"}, table.rows[types.UID("test")].Identifier) | ||
} | ||
|
||
func TestDeleteRow(t *testing.T) { | ||
table := NewTable(DefaultTableKeys, &buoytypes.Table{ | ||
Columns: []buoytypes.Column{ | ||
{Header: "Name", Width: 10, Path: "metadata.name"}, | ||
}, | ||
}, styles.Theme{}) | ||
|
||
t.Log("add a row") | ||
u := &unstructured.Unstructured{} | ||
u.SetName("test") | ||
u.SetNamespace("test-ns") | ||
u.SetUID(types.UID("test")) | ||
table.AddOrUpdate(u) | ||
assert.Len(t, table.rows, 1) | ||
|
||
t.Log("delete a row") | ||
table.DeleteRow(types.UID("test")) | ||
assert.Len(t, table.rows, 0) | ||
} | ||
|
||
func TestTableView(t *testing.T) { | ||
table := NewTable(DefaultTableKeys, &buoytypes.Table{}, styles.Theme{}) | ||
|
||
t.Log("view with error state") | ||
err := errors.New("some error") | ||
table.SetError(err) | ||
assert.Equal(t, err.Error(), table.View()) | ||
|
||
t.Log("view with table mode") | ||
table.SetError(nil) | ||
table.mode = modeTable | ||
assert.Equal(t, table.tableModel.View(), table.View()) | ||
|
||
t.Log("view with view mode toggled on") | ||
table.mode = modeView | ||
table.viewport.SetContent("floof") | ||
assert.Equal(t, table.viewport.View(), table.View()) | ||
} | ||
|
||
func TestGetDotNotationValueNonExistentValue(t *testing.T) { | ||
obj := map[string]interface{}{ | ||
"foo": map[string]interface{}{ | ||
"bar": "baz", | ||
}, | ||
} | ||
|
||
val, err := getDotNotationValue(obj, "foo.baz") | ||
assert.NoError(t, err) | ||
assert.Equal(t, "n/a", val) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package models | ||
|
||
import ( | ||
"testing" | ||
|
||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/everettraven/buoy/pkg/charm/styles" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestTabberUpdate(t *testing.T) { | ||
tabber := NewTabber(DefaultTabberKeys, styles.Theme{}, Tab{Name: "test", Model: nil}, Tab{Name: "test2", Model: nil}) | ||
|
||
t.Log("navigate to next tab") | ||
tabber.Update(tea.KeyMsg{Type: tea.KeyTab}) | ||
assert.Equal(t, 1, tabber.selected) | ||
|
||
t.Log("navigate to previous tab") | ||
tabber.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("shift+tab")}) | ||
assert.Equal(t, 0, tabber.selected) | ||
|
||
t.Log("navigate to previous tab (out of bounds -> last tab)") | ||
tabber.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("shift+tab")}) | ||
assert.Equal(t, 1, tabber.selected) | ||
|
||
t.Log("navigate to next tab (out of bounds -> first tab)") | ||
tabber.Update(tea.KeyMsg{Type: tea.KeyTab}) | ||
assert.Equal(t, 0, tabber.selected) | ||
} |
Oops, something went wrong.