Skip to content

Commit

Permalink
Merge pull request #2 from dkyanakiev/feature/testing
Browse files Browse the repository at this point in the history
 Adding testing to core components
  • Loading branch information
dkyanakiev authored Nov 29, 2023
2 parents f217fb5 + 03b385c commit e1b67eb
Show file tree
Hide file tree
Showing 46 changed files with 4,808 additions and 78 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ build:

.PHONY: run
run:
./bin/vaul7y
./bin/vaul7y

.PHONY: test
test:
go test ./...
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ If anyone decides to use this and wants to request a specific feature or even fi

## Short term TODO list:
1. [x] Change the logger (current one is a mess)
2. [ ] Finish adding tests (wip in another branch)
2. [x] Finish adding tests (initial batch of tests)
3. [ ] Finish implementing Update to existing secrets
- [ ] Bonus: Create net new ones.
4. [ ] Support for namespace changes.
50 changes: 50 additions & 0 deletions component/commands_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package component_test

import (
"errors"
"testing"

"github.com/dkyanakiev/vaulty/component"
"github.com/dkyanakiev/vaulty/component/componentfakes"
"github.com/rivo/tview"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestCommands_Update(t *testing.T) {
commands := component.NewCommands()

newCommands := []string{"new command 1", "new command 2"}
commands.Update(newCommands)

assert.Equal(t, newCommands, commands.Props.ViewCommands)
}

func TestCommands_OK(t *testing.T) {
r := require.New(t)
textView := &componentfakes.FakeTextView{}
cmds := component.NewCommands()
cmds.TextView = textView

cmds.Props.MainCommands = []string{"command1", "command2"}
cmds.Props.ViewCommands = []string{"subCmd1", "subCmd2"}

cmds.Bind(tview.NewFlex())
err := cmds.Render()
r.NoError(err)

text := textView.SetTextArgsForCall(0)
r.Equal(text, "command1\ncommand2\nsubCmd1\nsubCmd2")
}

func TestCommands_Fail(t *testing.T) {
r := require.New(t)
textView := &componentfakes.FakeTextView{}
cmds := component.NewCommands()
cmds.TextView = textView
err := cmds.Render()
r.Error(err)

r.True(errors.Is(err, component.ErrComponentNotBound))
r.EqualError(err, "component not bound")
}
77 changes: 77 additions & 0 deletions component/componentfakes/fake_done_modal_func.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

227 changes: 227 additions & 0 deletions component/componentfakes/fake_drop_down.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e1b67eb

Please sign in to comment.