mirror of
https://github.com/prymitive/karma
synced 2026-05-05 03:16:51 +00:00
Add tests for annotations
This commit is contained in:
85
internal/models/annotation_test.go
Normal file
85
internal/models/annotation_test.go
Normal file
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user