mirror of
https://github.com/prymitive/karma
synced 2026-08-23 11:56:20 +00:00
fix(tests): add annotations sort test
This commit is contained in:
@@ -2,6 +2,7 @@ package models_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"github.com/prymitive/karma/internal/models"
|
||||
@@ -13,7 +14,7 @@ type annotationMapsTestCase struct {
|
||||
}
|
||||
|
||||
var annotationMapsTestCases = []annotationMapsTestCase{
|
||||
annotationMapsTestCase{
|
||||
{
|
||||
annotationMap: map[string]string{
|
||||
"foo": "bar",
|
||||
},
|
||||
@@ -26,7 +27,7 @@ var annotationMapsTestCases = []annotationMapsTestCase{
|
||||
},
|
||||
},
|
||||
},
|
||||
annotationMapsTestCase{
|
||||
{
|
||||
annotationMap: map[string]string{
|
||||
"foo": "http://localhost",
|
||||
},
|
||||
@@ -39,7 +40,7 @@ var annotationMapsTestCases = []annotationMapsTestCase{
|
||||
},
|
||||
},
|
||||
},
|
||||
annotationMapsTestCase{
|
||||
{
|
||||
annotationMap: map[string]string{
|
||||
"foo": "ftp://localhost",
|
||||
},
|
||||
@@ -52,7 +53,7 @@ var annotationMapsTestCases = []annotationMapsTestCase{
|
||||
},
|
||||
},
|
||||
},
|
||||
annotationMapsTestCase{
|
||||
{
|
||||
annotationMap: map[string]string{
|
||||
"foo": "https://localhost/xxx",
|
||||
"abc": "xyz",
|
||||
@@ -83,3 +84,33 @@ func TestAnnotationsFromMap(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnnotationsSort(t *testing.T) {
|
||||
annotations := models.Annotations{
|
||||
models.Annotation{
|
||||
Name: "bar",
|
||||
Value: "abc",
|
||||
Visible: true,
|
||||
IsLink: false,
|
||||
},
|
||||
models.Annotation{
|
||||
Name: "xyz",
|
||||
Value: "xyz",
|
||||
Visible: true,
|
||||
IsLink: true,
|
||||
},
|
||||
models.Annotation{
|
||||
Name: "abc",
|
||||
Value: "bar",
|
||||
Visible: true,
|
||||
IsLink: true,
|
||||
},
|
||||
}
|
||||
sort.Stable(annotations)
|
||||
if annotations[0].Name != "abc" {
|
||||
t.Errorf("Expected 'abc' to be first, got '%s'", annotations[0].Name)
|
||||
}
|
||||
if annotations[2].Name != "xyz" {
|
||||
t.Errorf("Expected 'xyz' to be last, got '%s'", annotations[2].Name)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user