mirror of
https://github.com/wneessen/go-hibp.git
synced 2024-11-22 12:50:50 +01:00
More test coverage
This commit is contained in:
parent
0ded55e697
commit
49b2ac95f6
3 changed files with 16 additions and 13 deletions
|
@ -1,6 +1,10 @@
|
|||
# go-hibp - Simple go client for the HIBP API
|
||||
|
||||
[![Go Reference](https://pkg.go.dev/badge/github.com/wneessen/go-hibp.svg)](https://pkg.go.dev/github.com/wneessen/go-hibp) [![Go Report Card](https://goreportcard.com/badge/github.com/wneessen/go-hibp)](https://goreportcard.com/report/github.com/wneessen/go-hibp) [![Build Status](https://api.cirrus-ci.com/github/wneessen/go-hibp.svg)](https://cirrus-ci.com/github/wneessen/go-hibp) <a href="https://ko-fi.com/D1D24V9IX"><img src="https://uploads-ssl.webflow.com/5c14e387dab576fe667689cf/5cbed8a4ae2b88347c06c923_BuyMeACoffee_blue.png" height="20" alt="buy ma a coffee"></a>
|
||||
[![Go Reference](https://pkg.go.dev/badge/github.com/wneessen/go-hibp.svg)](https://pkg.go.dev/github.com/wneessen/go-hibp)
|
||||
[![Go Report Card](https://goreportcard.com/badge/github.com/wneessen/go-hibp)](https://goreportcard.com/report/github.com/wneessen/go-hibp)
|
||||
[![Build Status](https://api.cirrus-ci.com/github/wneessen/go-hibp.svg)](https://cirrus-ci.com/github/wneessen/go-hibp)
|
||||
[![codecov](https://codecov.io/gh/wneessen/go-hibp/branch/main/graph/badge.svg?token=ST96EC0JHU)](https://codecov.io/gh/wneessen/go-hibp)
|
||||
<a href="https://ko-fi.com/D1D24V9IX"><img src="https://uploads-ssl.webflow.com/5c14e387dab576fe667689cf/5cbed8a4ae2b88347c06c923_BuyMeACoffee_blue.png" height="20" alt="buy ma a coffee"></a>
|
||||
|
||||
This Go package provides an simple to use interface to the excellent
|
||||
"[Have I Been Pwned](https://haveibeenpwned.com/API/v3)" (HIBP) API by Troy Hunt.
|
||||
|
|
|
@ -198,11 +198,12 @@ func TestBreachedAccountWithoutTruncate(t *testing.T) {
|
|||
breachDomain string
|
||||
shouldFail bool
|
||||
}{
|
||||
{"account-exists is breached once", "account-exists", "Adobe",
|
||||
{"account-exists is breached once", "account-exists@hibp-integration-tests.com", "Adobe",
|
||||
"adobe.com", false},
|
||||
{"multiple-breaches is breached multiple times", "multiple-breaches", "Adobe",
|
||||
{"multiple-breaches is breached multiple times", "multiple-breaches@hibp-integration-tests.com", "Adobe",
|
||||
"adobe.com", false},
|
||||
{"opt-out is not breached", "opt-out", "", "", true},
|
||||
{"opt-out is not breached", "opt-out@hibp-integration-tests.com", "", "", true},
|
||||
{"empty string should fail", "", "", "", true},
|
||||
}
|
||||
|
||||
apiKey := os.Getenv("HIBP_API_KEY")
|
||||
|
@ -212,9 +213,7 @@ func TestBreachedAccountWithoutTruncate(t *testing.T) {
|
|||
hc := New(WithApiKey(apiKey), WithRateLimitSleep())
|
||||
for _, tc := range testTable {
|
||||
t.Run(tc.testName, func(t *testing.T) {
|
||||
breachDetails, _, err := hc.BreachApi.BreachedAccount(
|
||||
fmt.Sprintf("%s@hibp-integration-tests.com", tc.accountName),
|
||||
WithoutTruncate())
|
||||
breachDetails, _, err := hc.BreachApi.BreachedAccount(tc.accountName, WithoutTruncate())
|
||||
if err != nil && !tc.shouldFail {
|
||||
t.Error(err)
|
||||
return
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package hibp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
@ -12,9 +11,11 @@ func TestPasteAccount(t *testing.T) {
|
|||
testName string
|
||||
accountName string
|
||||
isBreached bool
|
||||
shouldFail bool
|
||||
}{
|
||||
{"account-exists is breached once", "account-exists", true},
|
||||
{"opt-out is not breached", "opt-out", false},
|
||||
{"account-exists is breached once", "account-exists@hibp-integration-tests.com", true, false},
|
||||
{"opt-out is not breached", "opt-out-breach@hibp-integration-tests.com", false, true},
|
||||
{"empty account name", "", false, true},
|
||||
}
|
||||
|
||||
apiKey := os.Getenv("HIBP_API_KEY")
|
||||
|
@ -24,9 +25,8 @@ func TestPasteAccount(t *testing.T) {
|
|||
hc := New(WithApiKey(apiKey))
|
||||
for _, tc := range testTable {
|
||||
t.Run(tc.testName, func(t *testing.T) {
|
||||
pasteDetails, _, err := hc.PasteApi.PastedAccount(
|
||||
fmt.Sprintf("%s@hibp-integration-tests.com", tc.accountName))
|
||||
if err != nil && tc.isBreached {
|
||||
pasteDetails, _, err := hc.PasteApi.PastedAccount(tc.accountName)
|
||||
if err != nil && !tc.shouldFail {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue