From bf64d7bdc2a549d73f91c8378719303756a8d0f2 Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Tue, 28 Mar 2017 18:40:46 -0700 Subject: [PATCH] automagic simplification --- builder/azure/pkcs12/bmp-string_test.go | 6 +++--- builder/azure/pkcs12/crypto_test.go | 6 +++--- builder/azure/pkcs12/pbkdf_test.go | 2 +- post-processor/vagrant/aws_test.go | 2 +- post-processor/vagrant/digitalocean_test.go | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/builder/azure/pkcs12/bmp-string_test.go b/builder/azure/pkcs12/bmp-string_test.go index fcbc7b7b1..8d4599e91 100644 --- a/builder/azure/pkcs12/bmp-string_test.go +++ b/builder/azure/pkcs12/bmp-string_test.go @@ -35,7 +35,7 @@ func TestBMPStringDecode(t *testing.T) { func TestBMPString(t *testing.T) { str, err := bmpString("") - if bytes.Compare(str, []byte{0, 0}) != 0 { + if !bytes.Equal(str, []byte{0, 0}) { t.Errorf("expected empty string to return double 0, but found: % x", str) } if err != nil { @@ -44,7 +44,7 @@ func TestBMPString(t *testing.T) { // Example from https://tools.ietf.org/html/rfc7292#appendix-B str, err = bmpString("Beavis") - if bytes.Compare(str, []byte{0x00, 0x42, 0x00, 0x65, 0x00, 0x61, 0x00, 0x0076, 0x00, 0x69, 0x00, 0x73, 0x00, 0x00}) != 0 { + if !bytes.Equal(str, []byte{0x00, 0x42, 0x00, 0x65, 0x00, 0x61, 0x00, 0x0076, 0x00, 0x69, 0x00, 0x73, 0x00, 0x00}) { t.Errorf("expected 'Beavis' to return 0x00 0x42 0x00 0x65 0x00 0x61 0x00 0x76 0x00 0x69 0x00 0x73 0x00 0x00, but found: % x", str) } if err != nil { @@ -54,7 +54,7 @@ func TestBMPString(t *testing.T) { // some characters from the "Letterlike Symbols Unicode block" tst := "\u2115 - Double-struck N" str, err = bmpString(tst) - if bytes.Compare(str, []byte{0x21, 0x15, 0x00, 0x20, 0x00, 0x2d, 0x00, 0x20, 0x00, 0x44, 0x00, 0x6f, 0x00, 0x75, 0x00, 0x62, 0x00, 0x6c, 0x00, 0x65, 0x00, 0x2d, 0x00, 0x73, 0x00, 0x74, 0x00, 0x72, 0x00, 0x75, 0x00, 0x63, 0x00, 0x6b, 0x00, 0x20, 0x00, 0x4e, 0x00, 0x00}) != 0 { + if !bytes.Equal(str, []byte{0x21, 0x15, 0x00, 0x20, 0x00, 0x2d, 0x00, 0x20, 0x00, 0x44, 0x00, 0x6f, 0x00, 0x75, 0x00, 0x62, 0x00, 0x6c, 0x00, 0x65, 0x00, 0x2d, 0x00, 0x73, 0x00, 0x74, 0x00, 0x72, 0x00, 0x75, 0x00, 0x63, 0x00, 0x6b, 0x00, 0x20, 0x00, 0x4e, 0x00, 0x00}) { t.Errorf("expected '%s' to return 0x21 0x15 0x00 0x20 0x00 0x2d 0x00 0x20 0x00 0x44 0x00 0x6f 0x00 0x75 0x00 0x62 0x00 0x6c 0x00 0x65 0x00 0x2d 0x00 0x73 0x00 0x74 0x00 0x72 0x00 0x75 0x00 0x63 0x00 0x6b 0x00 0x20 0x00 0x4e 0x00 0x00, but found: % x", tst, str) } if err != nil { diff --git a/builder/azure/pkcs12/crypto_test.go b/builder/azure/pkcs12/crypto_test.go index 3f40ba771..fb7f8484d 100644 --- a/builder/azure/pkcs12/crypto_test.go +++ b/builder/azure/pkcs12/crypto_test.go @@ -47,7 +47,7 @@ func pbDecrypt(info decryptable, password []byte) (decrypted []byte, err error) if psLen := int(decrypted[len(decrypted)-1]); psLen > 0 && psLen <= cbc.BlockSize() { m := decrypted[:len(decrypted)-psLen] ps := decrypted[len(decrypted)-psLen:] - if bytes.Compare(ps, bytes.Repeat([]byte{byte(psLen)}, psLen)) != 0 { + if !bytes.Equal(ps, bytes.Repeat([]byte{byte(psLen)}, psLen)) { return nil, ErrDecryption } decrypted = m @@ -87,7 +87,7 @@ func TestPbDecrypterFor(t *testing.T) { expectedM := []byte{185, 73, 135, 249, 137, 1, 122, 247} cbc.CryptBlocks(M, M) - if bytes.Compare(M, expectedM) != 0 { + if !bytes.Equal(M, expectedM) { t.Errorf("expected M to be '%d', but found '%d", expectedM, M) } } @@ -127,7 +127,7 @@ func TestPbDecrypt(t *testing.T) { if err != nil { t.Errorf("error decrypting C=%x: %v", c, err) } - if bytes.Compare(m, e) != 0 { + if !bytes.Equal(m, e) { t.Errorf("expected C=%x to be decoded to M=%x, but found %x", c, e, m) } case error: diff --git a/builder/azure/pkcs12/pbkdf_test.go b/builder/azure/pkcs12/pbkdf_test.go index a52b697d8..cd66e059e 100644 --- a/builder/azure/pkcs12/pbkdf_test.go +++ b/builder/azure/pkcs12/pbkdf_test.go @@ -12,7 +12,7 @@ func TestThatPBKDFWorksCorrectlyForLongKeys(t *testing.T) { password, _ := bmpString("sesame") key := pbkdf(salt, password, 2048) - if expected := []byte("\x7c\xd9\xfd\x3e\x2b\x3b\xe7\x69\x1a\x44\xe3\xbe\xf0\xf9\xea\x0f\xb9\xb8\x97\xd4\xe3\x25\xd9\xd1"); bytes.Compare(key, expected) != 0 { + if expected := []byte("\x7c\xd9\xfd\x3e\x2b\x3b\xe7\x69\x1a\x44\xe3\xbe\xf0\xf9\xea\x0f\xb9\xb8\x97\xd4\xe3\x25\xd9\xd1"); !bytes.Equal(key, expected) { t.Fatalf("expected key '% x', but found '% x'", key, expected) } } diff --git a/post-processor/vagrant/aws_test.go b/post-processor/vagrant/aws_test.go index 7754a48ec..02eb02365 100644 --- a/post-processor/vagrant/aws_test.go +++ b/post-processor/vagrant/aws_test.go @@ -31,7 +31,7 @@ func TestAWSProvider_ArtifactId(t *testing.T) { t.Fatalf("should not have error: %s", err) } result := `aws.region_config "us-east-1", ami: "ami-1234"` - if strings.Index(vagrantfile, result) == -1 { + if !strings.Contains(vagrantfile, result) { t.Fatalf("wrong substitution: %s", vagrantfile) } } diff --git a/post-processor/vagrant/digitalocean_test.go b/post-processor/vagrant/digitalocean_test.go index 964877c75..6256fc249 100644 --- a/post-processor/vagrant/digitalocean_test.go +++ b/post-processor/vagrant/digitalocean_test.go @@ -31,11 +31,11 @@ func TestDigitalOceanProvider_ArtifactId(t *testing.T) { t.Fatalf("should not have error: %s", err) } image := `digital_ocean.image = "42"` - if strings.Index(vagrantfile, image) == -1 { + if !strings.Contains(vagrantfile, image) { t.Fatalf("wrong image substitution: %s", vagrantfile) } region := `digital_ocean.region = "San Francisco"` - if strings.Index(vagrantfile, region) == -1 { + if !strings.Contains(vagrantfile, region) { t.Fatalf("wrong region substitution: %s", vagrantfile) } }