| 1 |
package cookie |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
|
| 6 |
"codeberg.org/miekg/dns/cmd/atomdns/internal/dnsserver" |
| 7 |
) |
| 8 |
|
| 9 |
func TestSetup(t *testing.T) { |
| 10 |
testcases := []struct { |
| 11 |
input string |
| 12 |
exp string |
| 13 |
}{ |
| 14 |
{`cookie`, ""}, |
| 15 |
{`cookie "geheim"`, "geheim"}, |
| 16 |
} |
| 17 |
for i, tc := range testcases { |
| 18 |
cookie := new(Cookie) |
| 19 |
co := dnsserver.NewTestController(tc.input) |
| 20 |
err := cookie.Setup(co) |
| 21 |
|
| 22 |
if tc.exp == "" { |
| 23 |
if err == nil { |
| 24 |
t.Errorf("test %d: expected error, got nothing", i) |
| 25 |
} |
| 26 |
continue |
| 27 |
} |
| 28 |
|
| 29 |
if tc.exp != cookie.Secret { |
| 30 |
t.Errorf("test %d: expected %s, got %s", i, tc.input, cookie.Secret) |
| 31 |
} |
| 32 |
} |
| 33 |
} |