Refactor links_test to use table test and cleaner error check
Signed-off-by: Jared Scheib <jared.scheib@gmail.com>pull/1660/head
parent
2e93ad5230
commit
c637e5407d
|
@ -1,35 +1,60 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewCustomLinks(t *testing.T) {
|
||||
customLinks := map[string]string{
|
||||
"cubeapple": "https://cube.apple",
|
||||
}
|
||||
if customLink, err := NewCustomLinks(customLinks); customLink == nil || err != nil {
|
||||
t.Errorf("Unknown error in NewCustomLinks: %v", err)
|
||||
tests := []struct {
|
||||
name string
|
||||
args map[string]string
|
||||
want []CustomLink
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "Unknown error in NewCustomLinks",
|
||||
args: map[string]string{
|
||||
"cubeapple": "https://cube.apple",
|
||||
},
|
||||
want: []CustomLink{
|
||||
{
|
||||
Name: "cubeapple",
|
||||
URL: "https://cube.apple",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "CustomLink missing key for Name",
|
||||
args: map[string]string{
|
||||
"": "https://cube.apple",
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "CustomLink missing value for URL",
|
||||
args: map[string]string{
|
||||
"cubeapple": "",
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "Missing protocol scheme",
|
||||
args: map[string]string{
|
||||
"cubeapple": ":k%8a#",
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
customLinks = map[string]string{
|
||||
"": "https://cube.apple",
|
||||
}
|
||||
if customLink, err := NewCustomLinks(customLinks); customLink != nil || err == nil {
|
||||
t.Error("Expected error: CustomLink missing key for Name")
|
||||
}
|
||||
|
||||
customLinks = map[string]string{
|
||||
"cubeapple": "",
|
||||
}
|
||||
if customLink, err := NewCustomLinks(customLinks); customLink != nil || err == nil {
|
||||
t.Error("Expected error: CustomLink missing value for URL")
|
||||
}
|
||||
|
||||
customLinks = map[string]string{
|
||||
"cubeapple": ":k%8a#",
|
||||
}
|
||||
if customLink, err := NewCustomLinks(customLinks); customLink != nil || err == nil {
|
||||
t.Error("Expected error: missing protocol scheme")
|
||||
for _, tt := range tests {
|
||||
got, err := NewCustomLinks(tt.args)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("%q. NewCustomLinks() error = %v, wantErr %v", tt.name, err, tt.wantErr)
|
||||
continue
|
||||
}
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("%q. NewCustomLinks() = %v, want %v", tt.name, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue