-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathetchosts_test.go
36 lines (34 loc) · 986 Bytes
/
etchosts_test.go
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
package main
import (
"bytes"
"fmt"
"testing"
)
func Test_writeEntryWithBanner(t *testing.T) {
type args struct {
ip string
names []string
}
tests := []struct {
name string
args args
wantTmp string
wantErr bool
}{
{"do not write empty ip", args{"", []string{"somename", "someothername"}}, "", false},
{"do not write empty names", args{"1.2.3.4", []string{}}, "", false},
{"complete entry", args{"1.2.3.4", []string{"somename", "someothername"}}, fmt.Sprintf("%s\n1.2.3.4\tsomename someothername\n", banner), false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tmp := &bytes.Buffer{}
if err := writeEntryWithBanner(tmp, tt.args.ip, tt.args.names); (err != nil) != tt.wantErr {
t.Errorf("writeEntryWithBanner() error = %v, wantErr %v", err, tt.wantErr)
return
}
if gotTmp := tmp.String(); gotTmp != tt.wantTmp {
t.Errorf("writeEntryWithBanner() got:\n%#v, want\n%#v", gotTmp, tt.wantTmp)
}
})
}
}