1 // Copyright 2015 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 //go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
15 const ubuntuTrustyAvahi = `# /etc/nsswitch.conf
17 # Example configuration of GNU Name Service Switch functionality.
18 # If you have the libc-doc-reference' and nfo' packages installed, try:
19 # nfo libc "Name Service Switch"' for information about this file.
25 hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4
36 func TestParseNSSConf(t *testing.T) {
48 sources: map[string][]nssSource{
49 "foo": {{source: "a"}, {source: "b"}},
57 sources: map[string][]nssSource{
58 "foo": {{source: "a"}, {source: "b"}},
66 sources: map[string][]nssSource{
67 "foo": {{source: "a"}, {source: "b"}},
75 sources: map[string][]nssSource{
76 "foo": {{source: "a"}, {source: "b"}},
84 sources: map[string][]nssSource{
85 "foo": {{source: "a"}, {source: "b"}},
91 in: " foo:a b [!a=b X=Y ] c#d \n",
93 sources: map[string][]nssSource{
98 criteria: []nssCriterion{
116 // Ubuntu Trusty w/ avahi-daemon, libavahi-* etc installed.
118 name: "ubuntu_trusty_avahi",
119 in: ubuntuTrustyAvahi,
121 sources: map[string][]nssSource{
122 "passwd": {{source: "compat"}},
123 "group": {{source: "compat"}},
124 "shadow": {{source: "compat"}},
128 source: "mdns4_minimal",
129 criteria: []nssCriterion{
140 "networks": {{source: "files"}},
165 for _, tt := range tests {
166 gotConf := nssStr(t, tt.in)
167 gotConf.mtime = time.Time{} // ignore mtime in comparison
168 if !reflect.DeepEqual(gotConf, tt.want) {
169 t.Errorf("%s: mismatch\n got %#v\nwant %#v", tt.name, gotConf, tt.want)