1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
package main
import (
"reflect"
"testing"
)
func Test_generateDNSMasqConfig(t *testing.T) {
testResult := `## WARNING: THIS IS AN AUTOGENERATED FILE
## AND SHOULD NOT BE EDITED MANUALLY AS IT
## LIKELY TO AUTOMATICALLY BE REPLACED.
strict-order
local=/foobar.org/
domain=foobar.org
expand-hosts
pid-file=/run/containers/cni/dnsname/cni0/pidfile
except-interface=lo
bind-dynamic
no-hosts
interface=cni0
addn-hosts=/run/containers/cni/dnsname/cni0/addnhosts
`
testConfig := dnsNameFile{
AddOnHostsFile: makePath("cni0", hostsFileName),
Binary: "/usr/bin/foo",
ConfigFile: makePath("cni0", confFileName),
Domain: "foobar.org",
NetworkInterface: "cni0",
PidFile: makePath("cni0", pidFileName),
}
type args struct {
config dnsNameFile
}
tests := []struct {
name string
args args
want []byte
wantErr bool
}{
{"pass", args{testConfig}, []byte(testResult), false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := generateDNSMasqConfig(tt.args.config)
if (err != nil) != tt.wantErr {
t.Errorf("generateDNSMasqConfig() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("generateDNSMasqConfig() got = '%v', want '%v'", string(got), string(tt.want))
}
})
}
}
|