sourcegraph/internal/database/util_test.go
Camden Cheek e3520f20ff
Chore: replace pointer helpers with pointers package (#55687)
We have a nice pointers package now, so this PR just replaces some
helper functions with that package.
2023-08-09 19:11:06 +00:00

39 lines
739 B
Go

package database
import (
"context"
"encoding/json"
"testing"
"github.com/sourcegraph/sourcegraph/internal/encryption"
)
func testEncryptionKeyID(key encryption.Key) string {
v, err := key.Version(context.Background())
if err != nil {
panic("why are you sending me a key with an exploding version??")
}
return v.JSON()
}
func assertJSONEqual(t *testing.T, want, got any) {
wantJ := asJSON(t, want)
gotJ := asJSON(t, got)
if wantJ != gotJ {
t.Errorf("Wanted %s, but got %s", wantJ, gotJ)
}
}
func jsonEqual(t *testing.T, a, b any) bool {
return asJSON(t, a) == asJSON(t, b)
}
func asJSON(t *testing.T, v any) string {
b, err := json.MarshalIndent(v, "", " ")
if err != nil {
t.Fatal(err)
}
return string(b)
}