From 7f34fcbc991dcd063a23405e5714bc4becce96c8 Mon Sep 17 00:00:00 2001 From: Bernhard Froehlich Date: Tue, 16 Feb 2021 15:57:50 +0000 Subject: [PATCH] gofmt: Fix formatting --- auth.go | 8 ++++---- auth_test.go | 50 +++++++++++++++++++++++++------------------------- main_test.go | 22 +++++++++++----------- 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/auth.go b/auth.go index 2b7517fb..3ecce76d 100644 --- a/auth.go +++ b/auth.go @@ -14,8 +14,8 @@ var ( ) type AuthUser struct { - username string - passwordHash string + username string + passwordHash string allowedAddresses []string } @@ -48,8 +48,8 @@ func parseLine(line string) *AuthUser { } user := AuthUser{ - username: parts[0], - passwordHash: parts[1], + username: parts[0], + passwordHash: parts[1], allowedAddresses: nil, } diff --git a/auth_test.go b/auth_test.go index 82dd4522..580b77cc 100644 --- a/auth_test.go +++ b/auth_test.go @@ -8,7 +8,7 @@ func stringsEqual(a, b []string) bool { if len(a) != len(b) { return false } - for i, _ := range a { + for i := range a { if a[i] != b[i] { return false } @@ -18,50 +18,50 @@ func stringsEqual(a, b []string) bool { func TestParseLine(t *testing.T) { var tests = []struct { - name string + name string expectFail bool - line string - username string - addrs []string + line string + username string + addrs []string }{ { - name: "Empty line", + name: "Empty line", expectFail: true, - line: "", + line: "", }, { - name: "Too few fields", + name: "Too few fields", expectFail: true, - line: "joe", + line: "joe", }, { - name: "Too many fields", + name: "Too many fields", expectFail: true, - line: "joe xxx joe@example.com whatsthis", + line: "joe xxx joe@example.com whatsthis", }, { - name: "Normal case", - line: "joe xxx joe@example.com", + name: "Normal case", + line: "joe xxx joe@example.com", username: "joe", - addrs: []string{"joe@example.com"}, + addrs: []string{"joe@example.com"}, }, { - name: "No allowed addrs given", - line: "joe xxx", + name: "No allowed addrs given", + line: "joe xxx", username: "joe", - addrs: []string{}, + addrs: []string{}, }, { - name: "Trailing comma", - line: "joe xxx joe@example.com,", + name: "Trailing comma", + line: "joe xxx joe@example.com,", username: "joe", - addrs: []string{"joe@example.com"}, + addrs: []string{"joe@example.com"}, }, { - name: "Multiple allowed addrs", - line: "joe xxx joe@example.com,@foo.example.com", + name: "Multiple allowed addrs", + line: "joe xxx joe@example.com,@foo.example.com", username: "joe", - addrs: []string{"joe@example.com", "@foo.example.com"}, + addrs: []string{"joe@example.com", "@foo.example.com"}, }, } @@ -77,12 +77,12 @@ func TestParseLine(t *testing.T) { if user.username != test.username { t.Errorf("Testcase %d: Incorrect username: expected %v, got %v", - i, test.username, user.username) + i, test.username, user.username) } if !stringsEqual(user.allowedAddresses, test.addrs) { t.Errorf("Testcase %d: Incorrect addresses: expected %v, got %v", - i, test.addrs, user.allowedAddresses) + i, test.addrs, user.allowedAddresses) } }) } diff --git a/main_test.go b/main_test.go index 6d56b559..81e77357 100644 --- a/main_test.go +++ b/main_test.go @@ -24,17 +24,17 @@ func TestAddrAllowedSingle(t *testing.T) { func TestAddrAllowedDifferentCase(t *testing.T) { allowedAddrs := []string{"joe@abc.com"} - testAddrs := []string{ - "joe@ABC.com", - "Joe@abc.com", - "JOE@abc.com", - "JOE@ABC.COM", - } - for _, addr := range testAddrs { - if !addrAllowed(addr, allowedAddrs) { - t.Errorf("Address %v not allowed, but should be", addr) - } - } + testAddrs := []string{ + "joe@ABC.com", + "Joe@abc.com", + "JOE@abc.com", + "JOE@ABC.COM", + } + for _, addr := range testAddrs { + if !addrAllowed(addr, allowedAddrs) { + t.Errorf("Address %v not allowed, but should be", addr) + } + } } func TestAddrAllowedLocal(t *testing.T) {