Adding a hostname flag option for use with gh api

This commit is contained in:
wilso199 2020-10-01 14:49:00 -04:00 committed by GitHub
parent 4b395c5dd2
commit 3ecb9de1a7
5 changed files with 105 additions and 14 deletions

View file

@ -3,6 +3,8 @@ package utils
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestFuzzyAgo(t *testing.T) {
@ -36,3 +38,48 @@ func TestFuzzyAgo(t *testing.T) {
}
}
}
func TestHostnameValidator(t *testing.T) {
tests := []struct {
name string
input interface{}
wantsErr bool
}{
{
name: "valid hostname",
input: "internal.instance",
wantsErr: false,
},
{
name: "hostname with slashes",
input: "//internal.instance",
wantsErr: true,
},
{
name: "empty hostname",
input: " ",
wantsErr: true,
},
{
name: "hostname with colon",
input: "internal.instance:2205",
wantsErr: true,
},
{
name: "non-string hostname",
input: 62,
wantsErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := HostnameValidator(tt.input)
if tt.wantsErr {
assert.Error(t, err)
return
}
assert.Equal(t, nil, err)
})
}
}