Skip to content

Commit

Permalink
Merge pull request #613 from jhaals/moretests
Browse files Browse the repository at this point in the history
Add test cases for errors
  • Loading branch information
jhaals committed Sep 29, 2020
2 parents 00f1056 + cc137d2 commit fe52ed4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/yopass/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ func TestFetch(t *testing.T) {
}
}

func TestFetchInvalidServer(t *testing.T) {
_, err := yopass.Fetch("127.0.0.1:9999/invalid", "1337")
if err == nil {
t.Error("expected error, got none")
}
}
func TestStore(t *testing.T) {
db := testDB(map[string]string{})
y := server.New(&db, 1024, prometheus.NewRegistry())
Expand Down
16 changes: 16 additions & 0 deletions pkg/yopass/yopass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package yopass_test
import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"regexp"
"strings"
Expand Down Expand Up @@ -147,6 +148,21 @@ func TestEncrypt(t *testing.T) {
}
}

type invalidFile struct{}

func (invalidFile) Read(p []byte) (n int, err error) { return 0, fmt.Errorf("Broken I/O") }

func TestEncryptWithInvalidFile(t *testing.T) {
_, err := yopass.Encrypt(invalidFile{}, "somekey")
if err == nil {
t.Fatal("expected error, got none")
}
want := "could not copy data: Broken I/O"
if err.Error() != want {
t.Fatalf("expected %s, got %v", want, err)
}
}

func TestGenerateKey(t *testing.T) {
format := regexp.MustCompile("^[a-zA-Z0-9-_]{22}$")

Expand Down

0 comments on commit fe52ed4

Please sign in to comment.