-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathschema_test.go
80 lines (72 loc) · 2.19 KB
/
schema_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"github.com/stretchr/testify/require"
"testing"
)
func TestBuildSchemaFromMappings(t *testing.T) {
mappings := map[string]interface{}{
"es-index": map[string]interface{}{
"mappings": map[string]interface{}{
"properties": map[string]interface{}{
"+X Temperature": map[string]interface{}{
"type": "float",
},
"-X Temperature": map[string]interface{}{
"type": "float",
},
"3": map[string]interface{}{
"properties": map[string]interface{}{
"3V Bus Current": map[string]interface{}{
"type": "float",
},
"3V Bus Voltage": map[string]interface{}{
"type": "float",
},
"3V Input Current": map[string]interface{}{
"type": "float",
},
},
},
"5V Current": map[string]interface{}{
"type": "float",
},
"@timestamp": map[string]interface{}{
"type": "date",
},
"Battery Temperature": map[string]interface{}{
"type": "float",
},
"Unix Time": map[string]interface{}{
"type": "long",
},
"Archive": map[string]interface{}{
"type": "boolean",
},
},
},
},
}
schemas := buildSchemaFromMappings(mappings, nil)
require.Len(t, schemas, 3)
require.Contains(t, schemas, "es_index")
require.Contains(t, schemas, "es_index_by_id")
require.Contains(t, schemas, "es_index_aggregations")
documentListSchema := schemas["es_index"]
documentByIDSchema := schemas["es_index_by_id"]
documentAggregation := schemas["es_index_aggregations"]
require.Equal(t, "es_index", documentListSchema.Name)
require.Equal(t, "[es_index_document]", documentListSchema.Type.String())
require.Equal(t, "es_index_by_id", documentByIDSchema.Name)
require.Equal(t, "es_index_document", documentByIDSchema.Type.String())
require.Equal(t, "es_index_aggregations", documentAggregation.Name)
require.Equal(t, "es_index_aggregation_document", documentAggregation.Type.String())
}
func TestBuildSchemaFromEmptyMappings(t *testing.T) {
mappings := map[string]interface{}{
"es-index": map[string]interface{}{
"mappings": map[string]interface{}{},
},
}
schemas := buildSchemaFromMappings(mappings, nil)
require.Len(t, schemas, 0)
}