From 49b2ac95f6db0cf11049a151b7ed588ddd58261d Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Sat, 7 May 2022 15:59:20 +0200 Subject: [PATCH] More test coverage --- README.md | 6 +++++- breach_test.go | 11 +++++------ paste_test.go | 12 ++++++------ 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 7e19ce1..07eeb6c 100644 --- a/README.md +++ b/README.md @@ -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) buy ma a coffee +[![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) +buy ma a coffee 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. diff --git a/breach_test.go b/breach_test.go index b69270c..87f53e3 100644 --- a/breach_test.go +++ b/breach_test.go @@ -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 diff --git a/paste_test.go b/paste_test.go index 0244d83..be3d2ba 100644 --- a/paste_test.go +++ b/paste_test.go @@ -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) }