Merge pull request #4647 from halseth/go-15-sprintf

[tests] reverse macaroon time caveat check, fix go 1.15 vet check.
This commit is contained in:
Conner Fromknecht 2020-09-24 13:03:41 -07:00 committed by GitHub
commit 3362c9437b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 10 deletions

@ -110,7 +110,7 @@ func TestConnectionCorrectness(t *testing.T) {
// Test out some message full-message reads. // Test out some message full-message reads.
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
msg := []byte("hello" + string(i)) msg := []byte(fmt.Sprintf("hello%d", i))
if _, err := localConn.Write(msg); err != nil { if _, err := localConn.Write(msg); err != nil {
t.Fatalf("remote conn failed to write: %v", err) t.Fatalf("remote conn failed to write: %v", err)

@ -1,6 +1,7 @@
package macaroons_test package macaroons_test
import ( import (
"fmt"
"strings" "strings"
"testing" "testing"
"time" "time"
@ -14,12 +15,13 @@ var (
testID = []byte("dummyId") testID = []byte("dummyId")
testLocation = "lnd" testLocation = "lnd"
testVersion = macaroon.LatestVersion testVersion = macaroon.LatestVersion
expectedTimeCaveatSubstring = "time-before " + string(time.Now().Year()) expectedTimeCaveatSubstring = fmt.Sprintf("time-before %d", time.Now().Year())
) )
func createDummyMacaroon(t *testing.T) *macaroon.Macaroon { func createDummyMacaroon(t *testing.T) *macaroon.Macaroon {
dummyMacaroon, err := macaroon.New(testRootKey, testID, dummyMacaroon, err := macaroon.New(
testLocation, testVersion) testRootKey, testID, testLocation, testVersion,
)
if err != nil { if err != nil {
t.Fatalf("Error creating initial macaroon: %v", err) t.Fatalf("Error creating initial macaroon: %v", err)
} }
@ -35,8 +37,9 @@ func TestAddConstraints(t *testing.T) {
// Now add a constraint and make sure we have a cloned macaroon // Now add a constraint and make sure we have a cloned macaroon
// with the constraint applied instead of a mutated initial one. // with the constraint applied instead of a mutated initial one.
newMac, err := macaroons.AddConstraints(initialMac, newMac, err := macaroons.AddConstraints(
macaroons.TimeoutConstraint(1)) initialMac, macaroons.TimeoutConstraint(1),
)
if err != nil { if err != nil {
t.Fatalf("Error adding constraint: %v", err) t.Fatalf("Error adding constraint: %v", err)
} }
@ -67,9 +70,11 @@ func TestTimeoutConstraint(t *testing.T) {
} }
// Finally, check that the created caveat has an // Finally, check that the created caveat has an
// acceptable value // acceptable value.
if strings.HasPrefix(string(testMacaroon.Caveats()[0].Id), if !strings.HasPrefix(
expectedTimeCaveatSubstring) { string(testMacaroon.Caveats()[0].Id),
expectedTimeCaveatSubstring,
) {
t.Fatalf("Added caveat '%s' does not meet the expectations!", t.Fatalf("Added caveat '%s' does not meet the expectations!",
testMacaroon.Caveats()[0].Id) testMacaroon.Caveats()[0].Id)
} }
@ -90,7 +95,7 @@ func TestIpLockConstraint(t *testing.T) {
} }
// Finally, check that the created caveat has an // Finally, check that the created caveat has an
// acceptable value // acceptable value.
if string(testMacaroon.Caveats()[0].Id) != "ipaddr 127.0.0.1" { if string(testMacaroon.Caveats()[0].Id) != "ipaddr 127.0.0.1" {
t.Fatalf("Added caveat '%s' does not meet the expectations!", t.Fatalf("Added caveat '%s' does not meet the expectations!",
testMacaroon.Caveats()[0].Id) testMacaroon.Caveats()[0].Id)