-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2882424
commit 1f548a8
Showing
14 changed files
with
1,077 additions
and
17 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 |
---|---|---|
|
@@ -23,4 +23,8 @@ build: | |
|
||
.PHONY: run | ||
run: | ||
./bin/vaul7y | ||
./bin/vaul7y | ||
|
||
.PHONY: test | ||
test: | ||
go test ./... |
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,72 @@ | ||
package component_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/dkyanakiev/vaulty/component" | ||
"github.com/dkyanakiev/vaulty/component/componentfakes" | ||
"github.com/dkyanakiev/vaulty/styles" | ||
"github.com/rivo/tview" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestPolicyACLTable_Pass(t *testing.T) { | ||
r := require.New(t) | ||
t.Run("Data to be rendered", func(t *testing.T) { | ||
// fakeTable := &componentfakes.FakeTable{} | ||
fakeTextView := &componentfakes.FakeTextView{} | ||
pt := component.NewPolicyAclTable() | ||
|
||
pt.TextView = fakeTextView | ||
pt.Props.SelectedPolicyName = "policy-one" | ||
pt.Props.SelectedPolicyACL = "path \"secret/data/path\" { capabilities = [\"read\", \"list\"] }" | ||
|
||
pt.Props.SelectPath = func(id string) {} | ||
pt.Props.HandleNoResources = func(format string, args ...interface{}) {} | ||
|
||
slot := tview.NewFlex() | ||
pt.Bind(slot) | ||
|
||
err := pt.Render() | ||
r.NoError(err) | ||
|
||
// It renders the correct text | ||
fakeTextView.GetTextReturns(pt.Props.SelectedPolicyACL) | ||
fakeTextView.GetTextReturnsOnCall(0, pt.Props.SelectedPolicyACL) | ||
renderedText := fakeTextView.GetText(true) | ||
|
||
r.Equal("path \"secret/data/path\" { capabilities = [\"read\", \"list\"] }", renderedText) | ||
|
||
}) | ||
|
||
t.Run("No data to be rendered", func(t *testing.T) { | ||
fakeTextView := &componentfakes.FakeTextView{} | ||
pt := component.NewPolicyAclTable() | ||
|
||
pt.TextView = fakeTextView | ||
pt.Props.SelectedPolicyName = "policy-one" | ||
pt.Props.SelectedPolicyACL = "" | ||
|
||
var handleNoResourcesCalled bool | ||
pt.Props.HandleNoResources = func(format string, args ...interface{}) { | ||
handleNoResourcesCalled = true | ||
|
||
r.Equal("%sCant read ACL policy \n%s\\(╯°□°)╯︵ ┻━┻", format) | ||
r.Len(args, 2) | ||
r.Equal(args[0], styles.HighlightPrimaryTag) | ||
r.Equal(args[1], styles.HighlightSecondaryTag) | ||
} | ||
|
||
slot := tview.NewFlex() | ||
pt.Bind(slot) | ||
|
||
err := pt.Render() | ||
r.NoError(err) | ||
|
||
r.True(handleNoResourcesCalled) | ||
|
||
}) | ||
} | ||
|
||
func TestPolicyACLTable_Fail(t *testing.T) { | ||
} |
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,98 @@ | ||
package component_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/dkyanakiev/vaulty/component" | ||
"github.com/dkyanakiev/vaulty/component/componentfakes" | ||
"github.com/dkyanakiev/vaulty/styles" | ||
"github.com/gdamore/tcell/v2" | ||
"github.com/rivo/tview" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestPolicyTable_Pass(t *testing.T) { | ||
r := require.New(t) | ||
t.Run("When the component is bound", func(t *testing.T) { | ||
|
||
fakeTable := &componentfakes.FakeTable{} | ||
pt := component.NewPolicyTable() | ||
|
||
pt.Table = fakeTable | ||
pt.Props.Data = []string{"policy1", "policy2", "policy3"} | ||
|
||
pt.Props.SelectPath = func(id string) {} | ||
pt.Props.HandleNoResources = func(format string, args ...interface{}) {} | ||
slot := tview.NewFlex() | ||
pt.Bind(slot) | ||
// It doesn't error | ||
err := pt.Render() | ||
r.NoError(err) | ||
|
||
// Render header rows | ||
renderHeaderCount := fakeTable.RenderHeaderCallCount() | ||
r.Equal(renderHeaderCount, 1) | ||
|
||
// Correct headers | ||
header := fakeTable.RenderHeaderArgsForCall(0) | ||
r.Equal(component.PolicyTableHeaderJobs, header) | ||
|
||
// It renders the correct number of rows | ||
renderRowCallCount := fakeTable.RenderRowCallCount() | ||
r.Equal(renderRowCallCount, 3) | ||
|
||
row1, index1, c1 := fakeTable.RenderRowArgsForCall(0) | ||
row2, index2, c2 := fakeTable.RenderRowArgsForCall(1) | ||
row3, index3, c3 := fakeTable.RenderRowArgsForCall(2) | ||
|
||
expectedRow1 := []string{"policy1"} | ||
expectedRow2 := []string{"policy2"} | ||
expectedRow3 := []string{"policy3"} | ||
|
||
r.Equal(expectedRow1, row1) | ||
r.Equal(expectedRow2, row2) | ||
r.Equal(expectedRow3, row3) | ||
r.Equal(index1, 1) | ||
r.Equal(index2, 2) | ||
r.Equal(index3, 3) | ||
|
||
r.Equal(c1, tcell.ColorYellow) | ||
r.Equal(c2, tcell.ColorYellow) | ||
r.Equal(c3, tcell.ColorYellow) | ||
|
||
}) | ||
|
||
t.Run("No data to render", func(t *testing.T) { | ||
fakeTable := &componentfakes.FakeTable{} | ||
pt := component.NewPolicyTable() | ||
|
||
pt.Table = fakeTable | ||
pt.Props.Data = []string{} | ||
|
||
pt.Props.HandleNoResources = func(format string, args ...interface{}) {} | ||
var NoResourcesCalled bool | ||
pt.Props.HandleNoResources = func(format string, args ...interface{}) { | ||
NoResourcesCalled = true | ||
|
||
r.Equal("%sNo policy found\n%s\\(╯°□°)╯︵ ┻━┻", format) | ||
r.Len(args, 2) | ||
r.Equal(args[0], styles.HighlightPrimaryTag) | ||
r.Equal(args[1], styles.HighlightSecondaryTag) | ||
} | ||
|
||
slot := tview.NewFlex() | ||
pt.Bind(slot) | ||
// It doesn't error | ||
err := pt.Render() | ||
r.NoError(err) | ||
|
||
// It handled the case that there are no resources | ||
r.True(NoResourcesCalled) | ||
|
||
// It didn't returned after handling no resources | ||
r.Equal(fakeTable.RenderHeaderCallCount(), 0) | ||
r.Equal(fakeTable.RenderRowCallCount(), 0) | ||
|
||
}) | ||
|
||
} |
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,49 @@ | ||
package layout_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/dkyanakiev/vaulty/layout" | ||
"github.com/rivo/tview" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDefaultLayout(t *testing.T) { | ||
r := require.New(t) | ||
|
||
l := layout.New(layout.Default) | ||
|
||
r.NotNil(l.Container) | ||
r.IsType(l.Container, &tview.Application{}) | ||
|
||
r.NotNil(l.Pages) | ||
r.IsType(l.Pages, &tview.Pages{}) | ||
r.Equal(l.Pages.GetPageCount(), 1) | ||
r.True(l.Pages.HasPage("main")) | ||
|
||
r.NotNil(l.Header) | ||
r.NotNil(l.Header.SlotInfo) | ||
r.IsType(l.Header.SlotInfo, &tview.Flex{}) | ||
|
||
r.NotNil(l.Header.SlotCmd) | ||
r.IsType(l.Header.SlotCmd, &tview.Flex{}) | ||
|
||
r.NotNil(l.Header.SlotLogo) | ||
r.IsType(l.Header.SlotLogo, &tview.Flex{}) | ||
|
||
r.NotNil(l.Elements) | ||
r.NotNil(l.Elements.ClusterInfo) | ||
r.IsType(l.Elements.ClusterInfo, &tview.Flex{}) | ||
|
||
r.NotNil(l.Elements.Dropdowns) | ||
r.IsType(l.Elements.Dropdowns, &tview.Flex{}) | ||
|
||
r.NotNil(l.Body) | ||
r.IsType(l.Body, &tview.Flex{}) | ||
|
||
r.NotNil(l.Footer) | ||
r.IsType(l.Footer, &tview.Flex{}) | ||
|
||
r.NotNil(l.MainPage) | ||
r.IsType(l.MainPage, &tview.Flex{}) | ||
} |
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
Oops, something went wrong.