File: files_test.go

package info (click to toggle)
golang-github-containers-dnsname 1.1.1%2Bds1-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 196 kB
  • sloc: sh: 173; makefile: 77
file content (55 lines) | stat: -rw-r--r-- 1,340 bytes parent folder | download | duplicates (2)
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))
			}
		})
	}
}