mirror of
https://github.com/costela/docker-etchosts.git
synced 2025-05-10 17:35:41 +02:00
add simple tests for entry writing
This commit is contained in:
parent
b6d9115583
commit
1aad0f5845
1 changed files with 36 additions and 0 deletions
36
etchosts_test.go
Normal file
36
etchosts_test.go
Normal file
|
@ -0,0 +1,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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue