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
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewCustomLinks(t *testing.T) {
|
func TestNewCustomLinks(t *testing.T) {
|
||||||
customLinks := map[string]string{
|
tests := []struct {
|
||||||
"cubeapple": "https://cube.apple",
|
name string
|
||||||
}
|
args map[string]string
|
||||||
if customLink, err := NewCustomLinks(customLinks); customLink == nil || err != nil {
|
want []CustomLink
|
||||||
t.Errorf("Unknown error in NewCustomLinks: %v", err)
|
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{
|
for _, tt := range tests {
|
||||||
"": "https://cube.apple",
|
got, err := NewCustomLinks(tt.args)
|
||||||
}
|
if (err != nil) != tt.wantErr {
|
||||||
if customLink, err := NewCustomLinks(customLinks); customLink != nil || err == nil {
|
t.Errorf("%q. NewCustomLinks() error = %v, wantErr %v", tt.name, err, tt.wantErr)
|
||||||
t.Error("Expected error: CustomLink missing key for Name")
|
continue
|
||||||
}
|
}
|
||||||
|
if !reflect.DeepEqual(got, tt.want) {
|
||||||
customLinks = map[string]string{
|
t.Errorf("%q. NewCustomLinks() = %v, want %v", tt.name, got, tt.want)
|
||||||
"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")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue