Skip to content

Commit

Permalink
inclease test coverage blaskovicz#6
Browse files Browse the repository at this point in the history
  • Loading branch information
u5surf committed Sep 19, 2019
1 parent da618cd commit 003ea77
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cryptkeeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ func TestCryptString(t *testing.T) {
if err != nil || cs.String != "another secret text" {
t.Fatalf("UnmarshalJSON failed to provide original value")
}

badJsonBytes := append(jsonBytes, '}')

err = cs.UnmarshalJSON(badJsonBytes)
if err == nil {
t.Fatalf("UnmarshalJSON with bad json bytes should have errored")
}
})
t.Run("Scan", func(t *testing.T) {
scannable := "2tHq4GL8r7tTvfk6l2TS8d5nVDXY6ztqz6WTmbmq8ZOJ"
Expand All @@ -150,6 +157,12 @@ func TestCryptString(t *testing.T) {
t.Fatalf("Scan of []byte should have matched 'how are you doing', got: '%s'", csByte.String)
}

badScannable := "@tHq4GL8r7tTvfk6l2TS8d5nVDXY6ztqz6WTmbmq8ZOJ"
err = csString.Scan(interface{}(badScannable))
if err == nil {
t.Fatalf("Scan of malformed encrypted string should have errored")
}

var csGoofyType CryptString
err = csGoofyType.Scan(interface{}(12345))
if err == nil {
Expand Down Expand Up @@ -306,6 +319,13 @@ func TestCryptBytes(t *testing.T) {
if !bytes.Equal(originalBytes, cb.Bytes) {
t.Fatalf("UnmarshalJSON should have matched '%s', got: '%s'", originalBytes, cb.Bytes)
}

badJsonBytes := append(jsonBytes, '}')

err = cb.UnmarshalJSON(badJsonBytes)
if err == nil {
t.Fatalf("UnmarshalJSON with bad json bytes should have errored")
}
})
t.Run("Scan", func(t *testing.T) {
scannable := "2tHq4GL8r7tTvfk6l2TS8d5nVDXY6ztqz6WTmbmq8ZOJ"
Expand Down

0 comments on commit 003ea77

Please # to comment.