From 40604453eeda005cc9885783b9dc97d047502a21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Sat, 19 Aug 2017 19:20:27 -0700 Subject: [PATCH] Add tests for annotations --- internal/models/annotation_test.go | 85 ++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 internal/models/annotation_test.go diff --git a/internal/models/annotation_test.go b/internal/models/annotation_test.go new file mode 100644 index 000000000..3b7f01d83 --- /dev/null +++ b/internal/models/annotation_test.go @@ -0,0 +1,85 @@ +package models_test + +import ( + "reflect" + "testing" + + "github.com/cloudflare/unsee/internal/models" +) + +type annotationMapsTestCase struct { + annotationMap map[string]string + annotations models.Annotations +} + +var annotationMapsTestCases = []annotationMapsTestCase{ + annotationMapsTestCase{ + annotationMap: map[string]string{ + "foo": "bar", + }, + annotations: models.Annotations{ + models.Annotation{ + Name: "foo", + Value: "bar", + Visible: true, + IsLink: false, + }, + }, + }, + annotationMapsTestCase{ + annotationMap: map[string]string{ + "foo": "http://localhost", + }, + annotations: models.Annotations{ + models.Annotation{ + Name: "foo", + Value: "http://localhost", + Visible: true, + IsLink: true, + }, + }, + }, + annotationMapsTestCase{ + annotationMap: map[string]string{ + "foo": "ftp://localhost", + }, + annotations: models.Annotations{ + models.Annotation{ + Name: "foo", + Value: "ftp://localhost", + Visible: true, + IsLink: true, + }, + }, + }, + annotationMapsTestCase{ + annotationMap: map[string]string{ + "foo": "https://localhost/xxx", + "abc": "xyz", + }, + annotations: models.Annotations{ + models.Annotation{ + Name: "abc", + Value: "xyz", + Visible: true, + IsLink: false, + }, + models.Annotation{ + Name: "foo", + Value: "https://localhost/xxx", + Visible: true, + IsLink: true, + }, + }, + }, +} + +func TestAnnotationsFromMap(t *testing.T) { + for _, testCase := range annotationMapsTestCases { + result := models.AnnotationsFromMap(testCase.annotationMap) + if !reflect.DeepEqual(testCase.annotations, result) { + t.Errorf("AnnotationsFromMap result mismatch for map %v, expected %v got %v", + testCase.annotationMap, testCase.annotations, result) + } + } +}