|
| 1 | +package models_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "reflect" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/cloudflare/unsee/internal/models" |
| 8 | +) |
| 9 | + |
| 10 | +type annotationMapsTestCase struct { |
| 11 | + annotationMap map[string]string |
| 12 | + annotations models.Annotations |
| 13 | +} |
| 14 | + |
| 15 | +var annotationMapsTestCases = []annotationMapsTestCase{ |
| 16 | + annotationMapsTestCase{ |
| 17 | + annotationMap: map[string]string{ |
| 18 | + "foo": "bar", |
| 19 | + }, |
| 20 | + annotations: models.Annotations{ |
| 21 | + models.Annotation{ |
| 22 | + Name: "foo", |
| 23 | + Value: "bar", |
| 24 | + Visible: true, |
| 25 | + IsLink: false, |
| 26 | + }, |
| 27 | + }, |
| 28 | + }, |
| 29 | + annotationMapsTestCase{ |
| 30 | + annotationMap: map[string]string{ |
| 31 | + "foo": "http://localhost", |
| 32 | + }, |
| 33 | + annotations: models.Annotations{ |
| 34 | + models.Annotation{ |
| 35 | + Name: "foo", |
| 36 | + Value: "http://localhost", |
| 37 | + Visible: true, |
| 38 | + IsLink: true, |
| 39 | + }, |
| 40 | + }, |
| 41 | + }, |
| 42 | + annotationMapsTestCase{ |
| 43 | + annotationMap: map[string]string{ |
| 44 | + "foo": "ftp://localhost", |
| 45 | + }, |
| 46 | + annotations: models.Annotations{ |
| 47 | + models.Annotation{ |
| 48 | + Name: "foo", |
| 49 | + Value: "ftp://localhost", |
| 50 | + Visible: true, |
| 51 | + IsLink: true, |
| 52 | + }, |
| 53 | + }, |
| 54 | + }, |
| 55 | + annotationMapsTestCase{ |
| 56 | + annotationMap: map[string]string{ |
| 57 | + "foo": "https://localhost/xxx", |
| 58 | + "abc": "xyz", |
| 59 | + }, |
| 60 | + annotations: models.Annotations{ |
| 61 | + models.Annotation{ |
| 62 | + Name: "abc", |
| 63 | + Value: "xyz", |
| 64 | + Visible: true, |
| 65 | + IsLink: false, |
| 66 | + }, |
| 67 | + models.Annotation{ |
| 68 | + Name: "foo", |
| 69 | + Value: "https://localhost/xxx", |
| 70 | + Visible: true, |
| 71 | + IsLink: true, |
| 72 | + }, |
| 73 | + }, |
| 74 | + }, |
| 75 | +} |
| 76 | + |
| 77 | +func TestAnnotationsFromMap(t *testing.T) { |
| 78 | + for _, testCase := range annotationMapsTestCases { |
| 79 | + result := models.AnnotationsFromMap(testCase.annotationMap) |
| 80 | + if !reflect.DeepEqual(testCase.annotations, result) { |
| 81 | + t.Errorf("AnnotationsFromMap result mismatch for map %v, expected %v got %v", |
| 82 | + testCase.annotationMap, testCase.annotations, result) |
| 83 | + } |
| 84 | + } |
| 85 | +} |
0 commit comments