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