Skip to content

Commit

Permalink
Optimize tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GGP1 authored and GGP1 committed Jan 22, 2023
1 parent 7b2bde5 commit fb50a52
Show file tree
Hide file tree
Showing 43 changed files with 126 additions and 125 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ install:
@go install -ldflags="-s -w" .

test:
go test ./... -p 1
go test ./...

test-race:
go test ./... -p 1 -race
go test ./... -race

proto:
@cd pb && for type in card entry file totp ; do \
Expand Down
2 changes: 1 addition & 1 deletion auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

func TestLogin(t *testing.T) {
db := cmdutil.SetContext(t, "../db/testdata/database")
db := cmdutil.SetContext(t)

// This mock is used to execute Login as PreRunE
mock := func(db *bolt.DB) *cobra.Command {
Expand Down
4 changes: 2 additions & 2 deletions commands/2fa/2fa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func Test2FA(t *testing.T) {
if clipboard.Unsupported {
t.Skip("No clipboard utilities available")
}
db := cmdutil.SetContext(t, "../../db/testdata/database")
db := cmdutil.SetContext(t)
createElements(t, db)

cases := []struct {
Expand Down Expand Up @@ -73,7 +73,7 @@ func Test2FA(t *testing.T) {
}

func Test2FAErrors(t *testing.T) {
db := cmdutil.SetContext(t, "../../db/testdata/database")
db := cmdutil.SetContext(t)

cases := []struct {
desc string
Expand Down
6 changes: 3 additions & 3 deletions commands/2fa/add/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func TestAdd(t *testing.T) {
db := cmdutil.SetContext(t, "../../../db/testdata/database")
db := cmdutil.SetContext(t)

cases := []struct {
desc string
Expand Down Expand Up @@ -64,7 +64,7 @@ func TestAdd(t *testing.T) {
}

func TestAddErrors(t *testing.T) {
db := cmdutil.SetContext(t, "../../../db/testdata/database")
db := cmdutil.SetContext(t)

name := "test"
err := createTOTP(db, name, "", 0)
Expand Down Expand Up @@ -130,7 +130,7 @@ func TestAddErrors(t *testing.T) {
}

func TestCreateTOTP(t *testing.T) {
db := cmdutil.SetContext(t, "../../../db/testdata/database")
db := cmdutil.SetContext(t)

t.Run("Success", func(t *testing.T) {
name := "test"
Expand Down
4 changes: 2 additions & 2 deletions commands/2fa/rm/rm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func TestRm(t *testing.T) {
db := cmdutil.SetContext(t, "../../../db/testdata/database")
db := cmdutil.SetContext(t)

err := totp.Create(db, &pb.TOTP{Name: "test"})
assert.NoError(t, err)
Expand Down Expand Up @@ -47,7 +47,7 @@ func TestRm(t *testing.T) {
}

func TestRmErrors(t *testing.T) {
db := cmdutil.SetContext(t, "../../../db/testdata/database")
db := cmdutil.SetContext(t)

cases := []struct {
desc string
Expand Down
4 changes: 2 additions & 2 deletions commands/add/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func TestAdd(t *testing.T) {
db := cmdutil.SetContext(t, "../../db/testdata/database")
db := cmdutil.SetContext(t)

cases := []struct {
desc string
Expand Down Expand Up @@ -45,7 +45,7 @@ func TestAdd(t *testing.T) {
}

func TestAddErrors(t *testing.T) {
db := cmdutil.SetContext(t, "../../db/testdata/database")
db := cmdutil.SetContext(t)

err := entry.Create(db, &pb.Entry{Name: "test"})
assert.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions commands/add/phrase/phrase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func TestPhrase(t *testing.T) {
db := cmdutil.SetContext(t, "../../../db/testdata/database")
db := cmdutil.SetContext(t)

cases := []struct {
desc string
Expand Down Expand Up @@ -61,7 +61,7 @@ func TestPhrase(t *testing.T) {
}

func TestPhraseErrors(t *testing.T) {
db := cmdutil.SetContext(t, "../../../db/testdata/database")
db := cmdutil.SetContext(t)

err := entry.Create(db, &pb.Entry{Name: "test"})
assert.NoError(t, err)
Expand Down
8 changes: 4 additions & 4 deletions commands/backup/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func TestBackupFile(t *testing.T) {
db := cmdutil.SetContext(t, "../../db/testdata/database")
db := cmdutil.SetContext(t)
filename := "backup-test"

cmd := NewCmd(db)
Expand All @@ -28,7 +28,7 @@ func TestBackupFile(t *testing.T) {
}

func TestBackupServer(t *testing.T) {
db := cmdutil.SetContext(t, "../../db/testdata/database")
db := cmdutil.SetContext(t)

rec := httptest.NewRecorder()
req, err := http.NewRequest("GET", "localhost:4000/", nil)
Expand All @@ -46,7 +46,7 @@ func TestBackupServer(t *testing.T) {
}

func TestBackupErrors(t *testing.T) {
db := cmdutil.SetContext(t, "../../db/testdata/database")
db := cmdutil.SetContext(t)

cases := []struct {
desc string
Expand Down Expand Up @@ -85,7 +85,7 @@ func TestBackupErrors(t *testing.T) {
}

func TestWriteTo(t *testing.T) {
db := cmdutil.SetContext(t, "../../db/testdata/database")
db := cmdutil.SetContext(t)

var buf bytes.Buffer
err := writeTo(db, &buf)
Expand Down
6 changes: 3 additions & 3 deletions commands/card/add/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func TestAdd(t *testing.T) {
db := cmdutil.SetContext(t, "../../../db/testdata/database")
db := cmdutil.SetContext(t)

cases := []struct {
desc string
Expand Down Expand Up @@ -44,7 +44,7 @@ func TestAdd(t *testing.T) {
}

func TestAddErrors(t *testing.T) {
db := cmdutil.SetContext(t, "../../../db/testdata/database")
db := cmdutil.SetContext(t)

err := card.Create(db, &pb.Card{Name: "test"})
assert.NoError(t, err)
Expand Down Expand Up @@ -76,7 +76,7 @@ func TestAddErrors(t *testing.T) {
}

func TestInput(t *testing.T) {
db := cmdutil.SetContext(t, "../../../db/testdata/database")
db := cmdutil.SetContext(t)

expected := &pb.Card{
Name: "test",
Expand Down
4 changes: 2 additions & 2 deletions commands/card/copy/copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestCopy(t *testing.T) {
if clipboard.Unsupported {
t.Skip("No clipboard utilities available")
}
db := cmdutil.SetContext(t, "../../../db/testdata/database")
db := cmdutil.SetContext(t)

c := &pb.Card{
Name: "test",
Expand Down Expand Up @@ -69,7 +69,7 @@ func TestCopy(t *testing.T) {
}

func TestCopyErrors(t *testing.T) {
db := cmdutil.SetContext(t, "../../../db/testdata/database")
db := cmdutil.SetContext(t)

cases := []struct {
desc string
Expand Down
6 changes: 3 additions & 3 deletions commands/card/edit/edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

func TestEditErrors(t *testing.T) {
db := cmdutil.SetContext(t, "../../../db/testdata/database")
db := cmdutil.SetContext(t)
createCard(t, db, "test")

cases := []struct {
Expand Down Expand Up @@ -109,7 +109,7 @@ func TestReadTmpFile(t *testing.T) {
}

func TestUpdateCard(t *testing.T) {
db := cmdutil.SetContext(t, "../../../db/testdata/database")
db := cmdutil.SetContext(t)
name := "test_update"
createCard(t, db, name)

Expand Down Expand Up @@ -139,7 +139,7 @@ func TestUpdateCard(t *testing.T) {
}

func TestUseStdin(t *testing.T) {
db := cmdutil.SetContext(t, "../../../db/testdata/database")
db := cmdutil.SetContext(t)

oldCard := &pb.Card{
Name: "test",
Expand Down
4 changes: 2 additions & 2 deletions commands/card/ls/ls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func TestLs(t *testing.T) {
db := cmdutil.SetContext(t, "../../../db/testdata/database")
db := cmdutil.SetContext(t)

err := card.Create(db, &pb.Card{
Name: "test",
Expand Down Expand Up @@ -68,7 +68,7 @@ func TestLs(t *testing.T) {
}

func TestLsErrors(t *testing.T) {
db := cmdutil.SetContext(t, "../../../db/testdata/database")
db := cmdutil.SetContext(t)

err := card.Create(db, &pb.Card{Name: "test"})
assert.NoError(t, err, "Failed creating the card")
Expand Down
4 changes: 2 additions & 2 deletions commands/card/rm/rm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func TestRm(t *testing.T) {
db := cmdutil.SetContext(t, "../../../db/testdata/database")
db := cmdutil.SetContext(t)

names := []string{"test", "directory/test"}
for _, name := range names {
Expand Down Expand Up @@ -56,7 +56,7 @@ func TestRm(t *testing.T) {
}

func TestRmErrors(t *testing.T) {
db := cmdutil.SetContext(t, "../../../db/testdata/database")
db := cmdutil.SetContext(t)

cases := []struct {
desc string
Expand Down
2 changes: 1 addition & 1 deletion commands/config/argon2/argon2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func TestArgon2(t *testing.T) {
db := cmdutil.SetContext(t, "../../../db/testdata/database")
db := cmdutil.SetContext(t)

err := db.Update(func(tx *bolt.Tx) error {
b, err := tx.CreateBucketIfNotExists([]byte("kure_auth"))
Expand Down
4 changes: 2 additions & 2 deletions commands/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func TestRead(t *testing.T) {
db := cmdutil.SetContext(t, "../../db/testdata/database")
db := cmdutil.SetContext(t)
config.SetFilename("./testdata/mock_config.yaml")

cmd := NewCmd(db, nil)
Expand All @@ -19,7 +19,7 @@ func TestRead(t *testing.T) {
}

func TestReadError(t *testing.T) {
db := cmdutil.SetContext(t, "../../db/testdata/database")
db := cmdutil.SetContext(t)
config.SetFilename("")

cmd := NewCmd(db, nil)
Expand Down
2 changes: 1 addition & 1 deletion commands/config/edit/edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func TestEditErrors(t *testing.T) {
db := cmdutil.SetContext(t, "../../../db/testdata/database")
db := cmdutil.SetContext(t)

cases := []struct {
desc string
Expand Down
6 changes: 3 additions & 3 deletions commands/copy/copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestCopy(t *testing.T) {
t.Skip("No clipboard utilities available")
}

db := cmdutil.SetContext(t, "../../db/testdata/database")
db := cmdutil.SetContext(t)
e := createEntry(t, db)

cases := []struct {
Expand Down Expand Up @@ -68,7 +68,7 @@ func TestCopyWithConfigTimeout(t *testing.T) {
if clipboard.Unsupported {
t.Skip("No clipboard utilities available")
}
db := cmdutil.SetContext(t, "../../db/testdata/database")
db := cmdutil.SetContext(t)
e := createEntry(t, db)

config.Set("clipboard.timeout", "1ns")
Expand All @@ -85,7 +85,7 @@ func TestCopyWithConfigTimeout(t *testing.T) {
}

func TestCopyErrors(t *testing.T) {
db := cmdutil.SetContext(t, "../../db/testdata/database")
db := cmdutil.SetContext(t)

cases := []struct {
desc string
Expand Down
4 changes: 2 additions & 2 deletions commands/edit/edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

func TestEditErrors(t *testing.T) {
db := cmdutil.SetContext(t, "../../db/testdata/database")
db := cmdutil.SetContext(t)
createEntry(t, db, "test")

cases := []struct {
Expand Down Expand Up @@ -111,7 +111,7 @@ func TestReadTmpFile(t *testing.T) {
}

func TestUpdateEntry(t *testing.T) {
db := cmdutil.SetContext(t, "../../db/testdata/database")
db := cmdutil.SetContext(t)
name := "test_update"
createEntry(t, db, name)

Expand Down
8 changes: 4 additions & 4 deletions commands/export/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

func TestExport(t *testing.T) {
db := cmdutil.SetContext(t, "../../db/testdata/database")
db := cmdutil.SetContext(t)
createEntry(t, db)

cases := []struct {
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestExport(t *testing.T) {
}

func TestInvalidExport(t *testing.T) {
db := cmdutil.SetContext(t, "../../db/testdata/database")
db := cmdutil.SetContext(t)

cases := []struct {
desc string
Expand All @@ -119,7 +119,7 @@ func TestInvalidExport(t *testing.T) {
}

func TestArgs(t *testing.T) {
db := cmdutil.SetContext(t, "../../db/testdata/database")
db := cmdutil.SetContext(t)
cmd := NewCmd(db)

t.Run("Supported", func(t *testing.T) {
Expand All @@ -143,7 +143,7 @@ func TestArgs(t *testing.T) {
}

func TestGetTOTP(t *testing.T) {
db := cmdutil.SetContext(t, "../../db/testdata/database")
db := cmdutil.SetContext(t)

tp := &pb.TOTP{
Name: "test",
Expand Down
4 changes: 2 additions & 2 deletions commands/file/add/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func TestAdd(t *testing.T) {
db := cmdutil.SetContext(t, "../../../db/testdata/database")
db := cmdutil.SetContext(t)

cases := []struct {
desc string
Expand Down Expand Up @@ -89,7 +89,7 @@ func TestAdd(t *testing.T) {
}

func TestAddErrors(t *testing.T) {
db := cmdutil.SetContext(t, "../../../db/testdata/database")
db := cmdutil.SetContext(t)

err := file.Create(db, &pb.File{Name: "already exists.txt"})
assert.NoError(t, err, "Failed creating the file")
Expand Down
Loading

0 comments on commit fb50a52

Please sign in to comment.