Skip to content

Commit

Permalink
tests: stop using deprecated assert fns
Browse files Browse the repository at this point in the history
  • Loading branch information
joonas-fi committed Apr 6, 2023
1 parent 4112188 commit 95b6f3e
Show file tree
Hide file tree
Showing 25 changed files with 125 additions and 125 deletions.
2 changes: 1 addition & 1 deletion app/byteshuman/humanize_test.go
Expand Up @@ -25,7 +25,7 @@ func TestHumanize(t *testing.T) {
{1152921504606846976, "1024.00 PiB"},
} {
t.Run(tc.output, func(t *testing.T) {
assert.EqualString(t, Humanize(tc.input), tc.output)
assert.Equal(t, Humanize(tc.input), tc.output)
})
}
}
6 changes: 3 additions & 3 deletions app/promconstmetrics/constmetrics_test.go
Expand Up @@ -31,7 +31,7 @@ func TestConstMetrics(t *testing.T) {
expositionOutput := &bytes.Buffer{}

assert.Ok(t, gatherToTextExport(allCollectors, expositionOutput))
assert.EqualString(t, expositionOutput.String(), `# HELP stars Stars in GitHub
assert.Equal(t, expositionOutput.String(), `# HELP stars Stars in GitHub
# TYPE stars gauge
stars{org="function61",repo="varasto"} 3 1579694400000
`)
Expand All @@ -41,7 +41,7 @@ stars{org="function61",repo="varasto"} 3 1579694400000
expositionOutput.Reset()

assert.Ok(t, gatherToTextExport(allCollectors, expositionOutput))
assert.EqualString(t, expositionOutput.String(), `# HELP stars Stars in GitHub
assert.Equal(t, expositionOutput.String(), `# HELP stars Stars in GitHub
# TYPE stars gauge
stars{org="function61",repo="varasto"} 11 1579694402000
`)
Expand All @@ -63,7 +63,7 @@ func TestVariableLabels(t *testing.T) {
expositionOutput := &bytes.Buffer{}

assert.Ok(t, gatherToTextExport(allCollectors, expositionOutput))
assert.EqualString(t, expositionOutput.String(), `# HELP stars Stars in GitHub
assert.Equal(t, expositionOutput.String(), `# HELP stars Stars in GitHub
# TYPE stars gauge
stars{org="function61",repo="gokit"} 5 1579694400000
stars{org="function61",repo="varasto"} 11 1579694400000
Expand Down
2 changes: 1 addition & 1 deletion app/retry/retry_test.go
Expand Up @@ -83,5 +83,5 @@ func TestTakesTooLong(t *testing.T) {
assert.Assert(t, attempts == 1)
assert.Assert(t, len(receivedErrors) == 1)
assert.Assert(t, regexp.MustCompile(`GIVING UP \(context timeout\): attempt 1 failed in .+: encountered timeout`).MatchString(receivedErrors[0].Error()))
assert.EqualString(t, err.Error(), receivedErrors[0].Error())
assert.Equal(t, err.Error(), receivedErrors[0].Error())
}
6 changes: 3 additions & 3 deletions crypto/cryptoutil/certificates_test.go
Expand Up @@ -10,9 +10,9 @@ func TestParsePemX509Certificate(t *testing.T) {
cert, err := ParsePemX509Certificate([]byte(testValidCertificate))
assert.Ok(t, err)

assert.EqualString(t, cert.Subject.CommonName, "godoc.org")
assert.EqualString(t, Identity(*cert), "godoc.org")
assert.EqualString(t, Issuer(*cert), "Let's Encrypt")
assert.Equal(t, cert.Subject.CommonName, "godoc.org")
assert.Equal(t, Identity(*cert), "godoc.org")
assert.Equal(t, Issuer(*cert), "Let's Encrypt")
}

const (
Expand Down
16 changes: 8 additions & 8 deletions crypto/cryptoutil/publickeycrypto_test.go
Expand Up @@ -7,7 +7,7 @@ import (
)

func TestMarshalPemBytes(t *testing.T) {
assert.EqualString(t, string(MarshalPemBytes([]byte("hello"), PemTypeCertificate)), `-----BEGIN CERTIFICATE-----
assert.Equal(t, string(MarshalPemBytes([]byte("hello"), PemTypeCertificate)), `-----BEGIN CERTIFICATE-----
aGVsbG8=
-----END CERTIFICATE-----
`)
Expand All @@ -26,25 +26,25 @@ func TestParsePemPkcs1EncodedRsaPublicKey(t *testing.T) {

// invalid PEM
_, err = ParsePemPkcs1EncodedRsaPublicKey([]byte("-----BEGIN RSA PUBLIC KEY-----\nMIIB@\n-----END RSA PUBLIC KEY-----"))
assert.EqualString(t, err.Error(), "PEM decode failed")
assert.Equal(t, err.Error(), "PEM decode failed")

// valid PEM, invalid asn1
_, err = ParsePemPkcs1EncodedRsaPublicKey([]byte("-----BEGIN RSA PUBLIC KEY-----\nMIIB\n-----END RSA PUBLIC KEY-----"))
assert.EqualString(t, err.Error(), "asn1: syntax error: truncated tag or length")
assert.Equal(t, err.Error(), "asn1: syntax error: truncated tag or length")
}

func TestParsePemEncodedPrivateKey(t *testing.T) {
rsaKey, err := ParsePemEncodedPrivateKey([]byte(testValidRsaPrivateKey))
assert.Ok(t, err)
rsaPublicKey, _ := PublicKeyFromPrivateKey(rsaKey)
rsaPublicKeyDescr, _ := PublicKeyHumanReadableDescription(rsaPublicKey)
assert.EqualString(t, rsaPublicKeyDescr, "RSA-1024")
assert.Equal(t, rsaPublicKeyDescr, "RSA-1024")

ecdsaKey, err := ParsePemEncodedPrivateKey([]byte(testValidEcdsaPrivateKey))
assert.Ok(t, err)
ecdsaPublicKey, _ := PublicKeyFromPrivateKey(ecdsaKey)
ecdsaPublicKeyDescr, _ := PublicKeyHumanReadableDescription(ecdsaPublicKey)
assert.EqualString(t, ecdsaPublicKeyDescr, "ECDSA")
assert.Equal(t, ecdsaPublicKeyDescr, "ECDSA")
}

func TestSha256FingerprintForPublicKey(t *testing.T) {
Expand All @@ -54,14 +54,14 @@ func TestSha256FingerprintForPublicKey(t *testing.T) {
fingerprint, err := Sha256FingerprintForPublicKey(pubKey)
assert.Ok(t, err)

assert.EqualString(t, fingerprint, "SHA256:mkKvVUiFg0oZd1IRltdabZPDD4oPUJcyIFnxeqi1sl8")
assert.Equal(t, fingerprint, "SHA256:mkKvVUiFg0oZd1IRltdabZPDD4oPUJcyIFnxeqi1sl8")
}

func TestMarshalPemPkcs1EncodedRsaPublicKey(t *testing.T) {
pubKey, err := ParsePemPkcs1EncodedRsaPublicKey([]byte(testValidRsaPublicKey))
assert.Ok(t, err)

assert.EqualString(t, string(MarshalPemPkcs1EncodedRsaPublicKey(pubKey)), `-----BEGIN RSA PUBLIC KEY-----
assert.Equal(t, string(MarshalPemPkcs1EncodedRsaPublicKey(pubKey)), `-----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEA+xGZ/wcz9ugFpP07Nspo6U17l0YhFiFpxxU4pTk3Lifz9R3zsIsu
ERwta7+fWIfxOo208ett/jhskiVodSEt3QBGh4XBipyWopKwZ93HHaDVZAALi/2A
+xTBtWdEo7XGUujKDvC2/aZKukfjpOiUI8AhLAfjmlcD/UZ1QPh0mHsglRNCmpCw
Expand All @@ -76,7 +76,7 @@ func TestMarshalPemPkcs1EncodedRsaPrivateKey(t *testing.T) {
pubKey, err := ParsePemPkcs1EncodedRsaPrivateKey([]byte(testValidRsaPrivateKey))
assert.Ok(t, err)

assert.EqualString(t, string(MarshalPemPkcs1EncodedRsaPrivateKey(pubKey)), `-----BEGIN RSA PRIVATE KEY-----
assert.Equal(t, string(MarshalPemPkcs1EncodedRsaPrivateKey(pubKey)), `-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZf
XJ/DgYSF6vUpwmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/
3j+skZ6UtW+5u09lHNsj6tQ51s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQAB
Expand Down
4 changes: 2 additions & 2 deletions crypto/cryptoutil/x509x25519_test.go
Expand Up @@ -17,7 +17,7 @@ func TestParsedPrivateKeyComputesToPublicKeyOpenSslEquivalent(t *testing.T) {

// since we managed to import OpenSSL-exported X25519 key, computed its public key and
// pubMarshaled equals what OpenSSL also computed from the private key, we know it works
assert.EqualString(t, string(bobPublicPem), bobPublicPemFromOpenssl)
assert.Equal(t, string(bobPublicPem), bobPublicPemFromOpenssl)
}

func TestPrivateAndPublicKeyParsing(t *testing.T) {
Expand All @@ -40,7 +40,7 @@ func TestPrivateAndPublicKeyParsing(t *testing.T) {
assert.Ok(t, err)

assert.Assert(t, bytes.Equal(aliceShared, bobShared))
assert.EqualString(t, fmt.Sprintf("%x", aliceShared), "1e9be8d5c01de22df9ccd852c17db8ca9367f72140cc1bbed9bac9e0ee7c1e53")
assert.Equal(t, fmt.Sprintf("%x", aliceShared), "1e9be8d5c01de22df9ccd852c17db8ca9367f72140cc1bbed9bac9e0ee7c1e53")

/*
Ideally we would like to compare OpenSSL's ECDH result to in-Go result (thus verifying
Expand Down
2 changes: 1 addition & 1 deletion crypto/envelopeenc/envelope_test.go
Expand Up @@ -8,5 +8,5 @@ import (

func TestEncryptFailsWithoutSlots(t *testing.T) {
_, err := Encrypt([]byte("sekrit"), []SlotEncrypter{}, "label")
assert.EqualString(t, err.Error(), "envelope with zero slots not supported")
assert.Equal(t, err.Error(), "envelope with zero slots not supported")
}
6 changes: 3 additions & 3 deletions crypto/envelopeenc/naclsecretbox_test.go
Expand Up @@ -11,19 +11,19 @@ func TestNaclSecretBoxEncrypter(t *testing.T) {
[32]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
"bestpassword")

assert.EqualString(t, pwdEnc.KekId(), "bestpassword")
assert.Equal(t, pwdEnc.KekId(), "bestpassword")

env, err := Encrypt([]byte("my secret message"), []SlotEncrypter{pwdEnc}, "example envelope")
assert.Ok(t, err)

decrypted, err := env.Decrypt(pwdEnc)
assert.Ok(t, err)

assert.EqualString(t, string(decrypted), "my secret message")
assert.Equal(t, string(decrypted), "my secret message")

// label must be non-malleable
env.Label = "malicious label"

_, err = env.Decrypt(pwdEnc)
assert.EqualString(t, err.Error(), "secretbox.Open failed")
assert.Equal(t, err.Error(), "secretbox.Open failed")
}
8 changes: 4 additions & 4 deletions crypto/envelopeenc/rsa_test.go
Expand Up @@ -17,7 +17,7 @@ func TestDecryptionRequiresCorrectLabel(t *testing.T) {

kek1Private := RsaOaepSha256Decrypter(kek1PrivateKey)

assert.EqualString(t, kek1Private.KekId(), "SHA256:P+E7i8cwgczvWmvPKV68wbhvHjrM4hgvq6gobxGiWrY")
assert.Equal(t, kek1Private.KekId(), "SHA256:P+E7i8cwgczvWmvPKV68wbhvHjrM4hgvq6gobxGiWrY")

envelope, err := Encrypt(
[]byte("hunter2"),
Expand All @@ -33,7 +33,7 @@ func TestDecryptionRequiresCorrectLabel(t *testing.T) {
envelope.Label = "foo2"

_, err = envelope.Decrypt(kek1Private)
assert.EqualString(t, err.Error(), "decryptWithSlot DecryptOAEP: crypto/rsa: decryption error")
assert.Equal(t, err.Error(), "decryptWithSlot DecryptOAEP: crypto/rsa: decryption error")
}

func TestEncryptAndDecrypt(t *testing.T) {
Expand Down Expand Up @@ -76,7 +76,7 @@ func TestEncryptAndDecrypt(t *testing.T) {
deterministicRand(tc.encryptionKey, tc.nonce))
assert.Ok(t, err)

assert.EqualString(
assert.Equal(
t,
hex.EncodeToString(pwdEnvelope.EncryptedContent),
tc.expectedOutput)
Expand All @@ -88,7 +88,7 @@ func TestEncryptAndDecrypt(t *testing.T) {
decrypted, err := pwdEnvelope.Decrypt(kek1Private)
assert.Ok(t, err)

assert.EqualString(t, string(decrypted), "hunter2")
assert.Equal(t, string(decrypted), "hunter2")
})
}
}
Expand Down
10 changes: 5 additions & 5 deletions crypto/mac/mac_test.go
Expand Up @@ -16,20 +16,20 @@ func TestAuthenticate(t *testing.T) {

signature := New(key1, msg).Sign()

assert.EqualString(t, signature, "bo4dqebLiFXPTpqv")
assert.Equal(t, signature, "bo4dqebLiFXPTpqv")

assert.Ok(t, New(key1, msg).Authenticate(signature))
assert.Assert(t, New(key1, msg).Authenticate("wrong signature") == ErrMacValidationFailed)
}

func TestDifferentMessagesProduceDifferentSignatures(t *testing.T) {
assert.EqualString(t, New(key1, "msg A").Sign(), "eq5Wd5Qh2cCgonpj")
assert.EqualString(t, New(key1, "msg B").Sign(), "HOc4MPpRdV4ytr4r")
assert.Equal(t, New(key1, "msg A").Sign(), "eq5Wd5Qh2cCgonpj")
assert.Equal(t, New(key1, "msg B").Sign(), "HOc4MPpRdV4ytr4r")
}

func TestDifferentKeysProduceDifferentSignatures(t *testing.T) {
msg := "message to authenticate"

assert.EqualString(t, New(key1, msg).Sign(), "PwBQuOJaF34tjmv2")
assert.EqualString(t, New(key2, msg).Sign(), "q8PkJSBswgeTrFcX")
assert.Equal(t, New(key1, msg).Sign(), "PwBQuOJaF34tjmv2")
assert.Equal(t, New(key2, msg).Sign(), "q8PkJSBswgeTrFcX")
}
2 changes: 1 addition & 1 deletion crypto/pkencryptedstream/stream_test.go
Expand Up @@ -29,7 +29,7 @@ func TestEncryptAndDecrypt(t *testing.T) {

plaintext, err := io.ReadAll(plaintextReader)
assert.Ok(t, err)
assert.EqualString(t, string(plaintext), "this will be encrypted")
assert.Equal(t, string(plaintext), "this will be encrypted")
}

const testPublicKeyDer = `-----BEGIN RSA PUBLIC KEY-----
Expand Down
6 changes: 3 additions & 3 deletions crypto/storedpassword/storeandverify_test.go
Expand Up @@ -13,11 +13,11 @@ func TestStoreAndVerify(t *testing.T) {

strategyId, _, _, err := deserialize(stored)
assert.Ok(t, err)
assert.EqualString(t, strategyId, "pbkdf2-sha256-100k")
assert.Equal(t, strategyId, "pbkdf2-sha256-100k")

// pretend above strategy is not found
upgrade, err := Verify(stored, "hunter2", alwaysFailingResolver)
assert.EqualString(t, err.Error(), "unknown strategy")
assert.Equal(t, err.Error(), "unknown strategy")
assert.Assert(t, upgrade == "")

// strategy should now be found
Expand All @@ -37,7 +37,7 @@ func TestStoreAndVerify(t *testing.T) {
// upgraded password should now use the ridiculously insecure strategy
strategyId, _, _, err = deserialize(upgrade)
assert.Ok(t, err)
assert.EqualString(t, strategyId, "pbkdf2-sha256-1")
assert.Equal(t, strategyId, "pbkdf2-sha256-1")

// verify upgraded password
upgrade, err = Verify(upgrade, "hunter2", downgradingResolver)
Expand Down
2 changes: 1 addition & 1 deletion encoding/hcl2json/hcl2json_test.go
Expand Up @@ -28,7 +28,7 @@ person {
jsonBytes, err := io.ReadAll(jsonBytesReader)
assert.Ok(t, err)

assert.EqualString(t, string(jsonBytes), `{
assert.Equal(t, string(jsonBytes), `{
"person": [
{
"age": 32,
Expand Down
16 changes: 8 additions & 8 deletions io/bidipipe/bidipipe_test.go
Expand Up @@ -15,8 +15,8 @@ func TestPipe(t *testing.T) {
err := Pipe(WithName("person1", person1), WithName("person2", person2))

assert.Ok(t, err)
assert.EqualString(t, person2.received, "Nice to meet you, Person2")
assert.EqualString(t, person1.received, "Thanks Person1, pleasure is all mine")
assert.Equal(t, person2.received, "Nice to meet you, Person2")
assert.Equal(t, person1.received, "Thanks Person1, pleasure is all mine")
}

func TestPipeWithErrorFromPerson1(t *testing.T) {
Expand All @@ -25,9 +25,9 @@ func TestPipeWithErrorFromPerson1(t *testing.T) {

err := Pipe(WithName("person1", person1), WithName("person2", person2))

assert.EqualString(t, err.Error(), "bidipipe: person1 -> person2 error: hurr durr, I broke")
assert.EqualString(t, person2.received, "")
assert.EqualString(t, person1.received, "Thanks Person1, pleasure is all mine")
assert.Equal(t, err.Error(), "bidipipe: person1 -> person2 error: hurr durr, I broke")
assert.Equal(t, person2.received, "")
assert.Equal(t, person1.received, "Thanks Person1, pleasure is all mine")
}

func TestPipeWithErrorFromPerson2(t *testing.T) {
Expand All @@ -36,9 +36,9 @@ func TestPipeWithErrorFromPerson2(t *testing.T) {

err := Pipe(WithName("person1", person1), WithName("person2", person2))

assert.EqualString(t, err.Error(), "bidipipe: person2 -> person1 error: hurr durr, I broke")
assert.EqualString(t, person2.received, "Nice to meet you, Person2")
assert.EqualString(t, person1.received, "")
assert.Equal(t, err.Error(), "bidipipe: person2 -> person1 error: hurr durr, I broke")
assert.Equal(t, person2.received, "Nice to meet you, Person2")
assert.Equal(t, person1.received, "")
}

type ReaderWriterMock struct {
Expand Down
4 changes: 2 additions & 2 deletions io/hashverifyreader/reader_test.go
Expand Up @@ -20,7 +20,7 @@ func TestReaderGoodHash(t *testing.T) {

out, err := io.ReadAll(verifiedReader)
assert.Ok(t, err)
assert.EqualString(t, string(out), "The quick brown fox jumps over the lazy dog")
assert.Equal(t, string(out), "The quick brown fox jumps over the lazy dog")
}

func TestReaderBadHash(t *testing.T) {
Expand All @@ -32,7 +32,7 @@ func TestReaderBadHash(t *testing.T) {
hexToBytes("7885198ae80b48ebf6c0d0d6b8ce86169570d346ec0b2c43029d04b3e3763ec3"))

_, err := io.ReadAll(thisHashWillNotMatch)
assert.EqualString(t, err.Error(), "hashVerifyReader: digest mismatch")
assert.Equal(t, err.Error(), "hashVerifyReader: digest mismatch")
}

func hexToBytes(input string) []byte {
Expand Down
28 changes: 14 additions & 14 deletions mime/mime_test.go
Expand Up @@ -7,26 +7,26 @@ import (
)

func TestTypeByExtension(t *testing.T) {
assert.EqualString(t, TypeByExtension(".json", NoFallback), "application/json")
assert.EqualString(t, TypeByExtension("json", NoFallback), "application/json")
assert.EqualString(t, TypeByExtension("JSON", NoFallback), "application/json")
assert.EqualString(t, TypeByExtension("JsOn", NoFallback), "application/json")
assert.Equal(t, TypeByExtension(".json", NoFallback), "application/json")
assert.Equal(t, TypeByExtension("json", NoFallback), "application/json")
assert.Equal(t, TypeByExtension("JSON", NoFallback), "application/json")
assert.Equal(t, TypeByExtension("JsOn", NoFallback), "application/json")

assert.EqualString(t, TypeByExtension("mkv", NoFallback), "video/x-matroska")
assert.EqualString(t, TypeByExtension("mkv", OctetStream), "video/x-matroska")
assert.Equal(t, TypeByExtension("mkv", NoFallback), "video/x-matroska")
assert.Equal(t, TypeByExtension("mkv", OctetStream), "video/x-matroska")

assert.EqualString(t, TypeByExtension("doesnotexist", NoFallback), "")
assert.EqualString(t, TypeByExtension("doesnotexist", OctetStream), "application/octet-stream")
assert.Equal(t, TypeByExtension("doesnotexist", NoFallback), "")
assert.Equal(t, TypeByExtension("doesnotexist", OctetStream), "application/octet-stream")
}

func TestExtensionByType(t *testing.T) {
assert.EqualString(t, ExtensionByType("image/jpeg", "bin"), "jpg")
assert.EqualString(t, ExtensionByType("video/x-matroska", "bin"), "mkv")
assert.EqualString(t, ExtensionByType("application/json", "bin"), "json")
assert.Equal(t, ExtensionByType("image/jpeg", "bin"), "jpg")
assert.Equal(t, ExtensionByType("video/x-matroska", "bin"), "mkv")
assert.Equal(t, ExtensionByType("application/json", "bin"), "json")

assert.EqualString(t, ExtensionByType("dunno/notfound", "bin"), "bin")
assert.EqualString(t, ExtensionByType("", "bin"), "bin")
assert.EqualString(t, ExtensionByType("", NoFallback), "")
assert.Equal(t, ExtensionByType("dunno/notfound", "bin"), "bin")
assert.Equal(t, ExtensionByType("", "bin"), "bin")
assert.Equal(t, ExtensionByType("", NoFallback), "")
}

func TestIs(t *testing.T) {
Expand Down

0 comments on commit 95b6f3e

Please sign in to comment.