package target
import "testing"
func TestValidate(t *testing.T) {
cases := []struct {
name string
in Target
wantErr bool
}{
{"ok", Target{Host: "h", Port: 22}, false},
{"empty host", Target{Host: " ", Port: 22}, true},
{"port zero", Target{Host: "h", Port: 0}, true},
{"port too big", Target{Host: "h", Port: 70000}, true},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
err := tc.in.Validate()
if tc.wantErr != (err != nil) {
t.Fatalf("wantErr=%v, got %v", tc.wantErr, err)
}
})
}
}
func TestLabel(t *testing.T) {
if got := (Target{Host: "h", Port: 22}).Label(); got != "h:22" {
t.Errorf("label = %q, want h:22", got)
}
if got := (Target{Host: "h", Port: 22, Name: "ssh"}).Label(); got != "ssh" {
t.Errorf("label = %q, want ssh", got)
}
}
func TestHasTag(t *testing.T) {
tt := Target{Tags: []string{"core", "DNS"}}
if !tt.HasTag("dns") {
t.Errorf("expected dns tag")
}
if tt.HasTag("db") {
t.Errorf("unexpected db tag")
}
}