-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
40 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 [email protected] whatsthis", | ||
line: "joe xxx [email protected] whatsthis", | ||
}, | ||
{ | ||
name: "Normal case", | ||
line: "joe xxx [email protected]", | ||
name: "Normal case", | ||
line: "joe xxx [email protected]", | ||
username: "joe", | ||
addrs: []string{"[email protected]"}, | ||
addrs: []string{"[email protected]"}, | ||
}, | ||
{ | ||
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 [email protected],", | ||
name: "Trailing comma", | ||
line: "joe xxx [email protected],", | ||
username: "joe", | ||
addrs: []string{"[email protected]"}, | ||
addrs: []string{"[email protected]"}, | ||
}, | ||
{ | ||
name: "Multiple allowed addrs", | ||
line: "joe xxx [email protected],@foo.example.com", | ||
name: "Multiple allowed addrs", | ||
line: "joe xxx [email protected],@foo.example.com", | ||
username: "joe", | ||
addrs: []string{"[email protected]", "@foo.example.com"}, | ||
addrs: []string{"[email protected]", "@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) | ||
} | ||
}) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,17 +24,17 @@ func TestAddrAllowedSingle(t *testing.T) { | |
|
||
func TestAddrAllowedDifferentCase(t *testing.T) { | ||
allowedAddrs := []string{"[email protected]"} | ||
testAddrs := []string{ | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
} | ||
for _, addr := range testAddrs { | ||
if !addrAllowed(addr, allowedAddrs) { | ||
t.Errorf("Address %v not allowed, but should be", addr) | ||
} | ||
} | ||
testAddrs := []string{ | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
} | ||
for _, addr := range testAddrs { | ||
if !addrAllowed(addr, allowedAddrs) { | ||
t.Errorf("Address %v not allowed, but should be", addr) | ||
} | ||
} | ||
} | ||
|
||
func TestAddrAllowedLocal(t *testing.T) { | ||
|