From 8ca5342b37b674449bd197e0e7203a5fd252b35c Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Thu, 24 Sep 2020 11:20:48 +0200 Subject: [PATCH 1/3] brontide test: fix go 1.15 vet check --- brontide/noise_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brontide/noise_test.go b/brontide/noise_test.go index dd0882ce..720219a0 100644 --- a/brontide/noise_test.go +++ b/brontide/noise_test.go @@ -110,7 +110,7 @@ func TestConnectionCorrectness(t *testing.T) { // Test out some message full-message reads. 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 { t.Fatalf("remote conn failed to write: %v", err) From 14960b1fb46facc9bdccb63aa11228b00480fda3 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Thu, 24 Sep 2020 11:22:13 +0200 Subject: [PATCH 2/3] macaroons test: reverse macaroon time caveat check This commit fixes a go 1.15 vet check. In doing so it uncovers that the time caveat check is actually reversed. Since we should check that the caveat is added, we should only fail the check when the caveat prefix is not equal. --- macaroons/constraints_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/macaroons/constraints_test.go b/macaroons/constraints_test.go index dd97536a..569acea8 100644 --- a/macaroons/constraints_test.go +++ b/macaroons/constraints_test.go @@ -1,6 +1,7 @@ package macaroons_test import ( + "fmt" "strings" "testing" "time" @@ -14,7 +15,7 @@ var ( testID = []byte("dummyId") testLocation = "lnd" 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 { @@ -67,8 +68,8 @@ func TestTimeoutConstraint(t *testing.T) { } // Finally, check that the created caveat has an - // acceptable value - if strings.HasPrefix(string(testMacaroon.Caveats()[0].Id), + // acceptable value. + if !strings.HasPrefix(string(testMacaroon.Caveats()[0].Id), expectedTimeCaveatSubstring) { t.Fatalf("Added caveat '%s' does not meet the expectations!", testMacaroon.Caveats()[0].Id) @@ -90,7 +91,7 @@ func TestIpLockConstraint(t *testing.T) { } // Finally, check that the created caveat has an - // acceptable value + // acceptable value. if string(testMacaroon.Caveats()[0].Id) != "ipaddr 127.0.0.1" { t.Fatalf("Added caveat '%s' does not meet the expectations!", testMacaroon.Caveats()[0].Id) From 65865030d63b9c948cb3085c1e3e37335d194700 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Thu, 24 Sep 2020 11:59:08 +0200 Subject: [PATCH 3/3] macaroons test: fix formatting --- macaroons/constraints_test.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/macaroons/constraints_test.go b/macaroons/constraints_test.go index 569acea8..44f78fff 100644 --- a/macaroons/constraints_test.go +++ b/macaroons/constraints_test.go @@ -19,8 +19,9 @@ var ( ) func createDummyMacaroon(t *testing.T) *macaroon.Macaroon { - dummyMacaroon, err := macaroon.New(testRootKey, testID, - testLocation, testVersion) + dummyMacaroon, err := macaroon.New( + testRootKey, testID, testLocation, testVersion, + ) if err != nil { t.Fatalf("Error creating initial macaroon: %v", err) } @@ -36,8 +37,9 @@ func TestAddConstraints(t *testing.T) { // Now add a constraint and make sure we have a cloned macaroon // with the constraint applied instead of a mutated initial one. - newMac, err := macaroons.AddConstraints(initialMac, - macaroons.TimeoutConstraint(1)) + newMac, err := macaroons.AddConstraints( + initialMac, macaroons.TimeoutConstraint(1), + ) if err != nil { t.Fatalf("Error adding constraint: %v", err) } @@ -69,8 +71,10 @@ func TestTimeoutConstraint(t *testing.T) { // Finally, check that the created caveat has an // acceptable value. - if !strings.HasPrefix(string(testMacaroon.Caveats()[0].Id), - expectedTimeCaveatSubstring) { + if !strings.HasPrefix( + string(testMacaroon.Caveats()[0].Id), + expectedTimeCaveatSubstring, + ) { t.Fatalf("Added caveat '%s' does not meet the expectations!", testMacaroon.Caveats()[0].Id) }