Skip to content

Commit

Permalink
certdb/sql: remove uses of github.com/stretchr/testify/require
Browse files Browse the repository at this point in the history
This was the only location where this assertion library was used; all
other code in this repository used Go's stdlib for assertions. The
remaining uses in this package could be replaced without too much
trouble, which allowed for the dependency (including its indirect
dependencies) to be removed altogether.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
  • Loading branch information
thaJeztah committed Jul 29, 2023
1 parent f0549e3 commit 8d25f25
Show file tree
Hide file tree
Showing 53 changed files with 27 additions and 23,465 deletions.
28 changes: 20 additions & 8 deletions certdb/sql/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package sql

import (
"math"
"reflect"
"testing"
"time"

"github.com/cloudflare/cfssl/certdb"
"github.com/cloudflare/cfssl/certdb/testdb"

"github.com/jmoiron/sqlx"
"github.com/stretchr/testify/require"
)

const (
Expand Down Expand Up @@ -95,8 +95,13 @@ func testInsertCertificateAndGetCertificate(ta TestAccessor, t *testing.T) {
t.Errorf("want Certificate %+v, got %+v", want, got)
}
gotMeta, err := got.GetMetadata()
require.NoError(t, err)
require.Equal(t, map[string]interface{}{"k": "v"}, gotMeta)
if err != nil {
t.Fatal(err)
}
expected := map[string]interface{}{"k": "v"}
if !reflect.DeepEqual(gotMeta, expected) {
t.Fatalf("expected: %+v, got: %+v", expected, gotMeta)
}

unexpired, err := ta.Accessor.GetUnexpiredCertificates()

Expand Down Expand Up @@ -156,12 +161,19 @@ func testInsertCertificateAndGetUnexpiredCertificate(ta TestAccessor, t *testing
}

unexpiredFiltered, err := ta.Accessor.GetUnexpiredCertificatesByLabel([]string{"foo"})
require.NoError(t, err)
require.Len(t, unexpiredFiltered, 1)
if err != nil {
t.Fatal(err)
}
if l := len(unexpiredFiltered); l != 1 {
t.Error("Should have 1 unexpiredFiltered certificate record:", l)
}
unexpiredFiltered, err = ta.Accessor.GetUnexpiredCertificatesByLabel([]string{"bar"})
require.NoError(t, err)
require.Len(t, unexpiredFiltered, 0)

if err != nil {
t.Fatal(err)
}
if l := len(unexpiredFiltered); l != 0 {
t.Error("Should have 0 unexpiredFiltered certificate record:", l)
}
}
func testInsertCertificateAndGetUnexpiredCertificateNullCommonName(ta TestAccessor, t *testing.T) {
ta.Truncate()
Expand Down
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ require (
github.com/lib/pq v1.10.9
github.com/mattn/go-sqlite3 v1.14.17
github.com/prometheus/client_golang v1.16.0
github.com/stretchr/testify v1.8.4
github.com/zmap/zcrypto v0.0.0-20230310154051-c8b263fd8300
github.com/zmap/zlint/v3 v3.5.0
golang.org/x/crypto v0.10.0
Expand All @@ -23,24 +22,22 @@ require (
require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/getsentry/sentry-go v0.11.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/kylelemons/go-gypsy v1.0.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/pelletier/go-toml v1.9.3 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/weppos/publicsuffix-go v0.30.0 // indirect
github.com/ziutek/mymysql v1.5.4 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/text v0.10.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
)
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,6 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20191120175047-4206685974f2/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
10 changes: 6 additions & 4 deletions signer/local/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ import (
"github.com/cloudflare/cfssl/helpers"
"github.com/cloudflare/cfssl/log"
"github.com/cloudflare/cfssl/signer"
"github.com/stretchr/testify/require"

ct "github.com/google/certificate-transparency-go"
"github.com/zmap/zlint/v3/lint"
)
Expand Down Expand Up @@ -1622,13 +1620,17 @@ func TestLint(t *testing.T) {
} else if err != nil && tc.expectedErr != nil {
actual := err.Error()
expected := tc.expectedErr.Error()
require.Equal(t, expected, actual)
if expected != actual {
t.Fatalf("expected: %v, got: %v", expected, actual)
}
if len(tc.expectedErrResults) > 0 {
le, ok := err.(*LintError)
if !ok {
t.Fatalf("expected LintError type err, got %v", err)
}
require.EqualValues(t, tc.expectedErrResults, le.ErrorResults)
if !reflect.DeepEqual(tc.expectedErrResults, le.ErrorResults) {
t.Fatalf("expected: %v, got: %v", tc.expectedErrResults, le.ErrorResults)
}
}
}
})
Expand Down
15 changes: 0 additions & 15 deletions vendor/github.com/davecgh/go-spew/LICENSE

This file was deleted.

145 changes: 0 additions & 145 deletions vendor/github.com/davecgh/go-spew/spew/bypass.go

This file was deleted.

38 changes: 0 additions & 38 deletions vendor/github.com/davecgh/go-spew/spew/bypasssafe.go

This file was deleted.

Loading

0 comments on commit 8d25f25

Please sign in to comment.