@@ -1067,16 +1067,11 @@ func MustReadAll(r io.Reader) []byte {
1067
1067
return buf
1068
1068
}
1069
1069
1070
- // Ensure handler can delete a frame .
1070
+ // Ensure handler can create a input definition .
1071
1071
func TestHandler_CreateInputDefinition (t * testing.T ) {
1072
1072
hldr := MustOpenHolder ()
1073
1073
defer hldr .Close ()
1074
1074
hldr .MustCreateIndexIfNotExists ("i0" , pilosa.IndexOptions {})
1075
-
1076
- h := NewHandler ()
1077
- h .Holder = hldr .Holder
1078
- h .Cluster = NewCluster (1 )
1079
- w := httptest .NewRecorder ()
1080
1075
inputBody := []byte (`
1081
1076
{
1082
1077
"frames":[{
@@ -1107,10 +1102,73 @@ func TestHandler_CreateInputDefinition(t *testing.T) {
1107
1102
}
1108
1103
]
1109
1104
}` )
1105
+ h := NewHandler ()
1106
+ h .Holder = hldr .Holder
1107
+ h .Cluster = NewCluster (1 )
1108
+ w := httptest .NewRecorder ()
1110
1109
h .ServeHTTP (w , MustNewHTTPRequest ("POST" , "/index/i0/input-definition/input1" , bytes .NewBuffer (inputBody )))
1111
1110
if w .Code != http .StatusOK {
1112
1111
t .Fatalf ("unexpected status code: %d" , w .Code )
1113
1112
} else if body := w .Body .String (); body != `{}` + "\n " {
1114
1113
t .Fatalf ("unexpected body: %s" , body )
1115
1114
}
1116
1115
}
1116
+
1117
+ // Ensure handler can delete a input definition.
1118
+ func TestHandler_DeleteInputDefinition (t * testing.T ) {
1119
+ hldr := MustOpenHolder ()
1120
+ defer hldr .Close ()
1121
+ index := hldr .MustCreateIndexIfNotExists ("i0" , pilosa.IndexOptions {})
1122
+
1123
+ frames := pilosa.InputFrame {Name : "f" , Options : pilosa.FrameOptions {RowLabel : "row" }}
1124
+ action := pilosa.Action {Frame : "f" , ValueDestination : "map" , ValueMap : map [string ]uint64 {"Green" : 1 }}
1125
+ fields := pilosa.Field {Name : "id" , PrimaryKey : true , Actions : []pilosa.Action {action }}
1126
+ _ , err := index .CreateInputDefinition ("test" , []pilosa.InputFrame {frames }, []pilosa.Field {fields })
1127
+ if err != nil {
1128
+ t .Fatal (err )
1129
+ }
1130
+
1131
+ h := NewHandler ()
1132
+ h .Holder = hldr .Holder
1133
+ h .Cluster = NewCluster (1 )
1134
+ w := httptest .NewRecorder ()
1135
+ h .ServeHTTP (w , MustNewHTTPRequest ("DELETE" , "/index/i0/input-definition/test" , strings .NewReader ("" )))
1136
+ if w .Code != http .StatusOK {
1137
+ t .Fatalf ("unexpected status code: %d" , w .Code )
1138
+ } else if body := w .Body .String (); body != `{}` + "\n " {
1139
+ t .Fatalf ("unexpected body: %s" , body )
1140
+ } else if index .InputDefinition ("test" ) != nil {
1141
+ t .Fatalf ("unexpected result: %s" , index .InputDefinition ("test" ))
1142
+ }
1143
+ }
1144
+
1145
+ // Return existing input definition
1146
+ func TestHandler_GetInputDefinition (t * testing.T ) {
1147
+ hldr := MustOpenHolder ()
1148
+ defer hldr .Close ()
1149
+ index := hldr .MustCreateIndexIfNotExists ("i0" , pilosa.IndexOptions {})
1150
+
1151
+ frames := pilosa.InputFrame {Name : "f" , Options : pilosa.FrameOptions {RowLabel : "row" }}
1152
+ action := pilosa.Action {Frame : "f" , ValueDestination : "map" , ValueMap : map [string ]uint64 {"Green" : 1 }}
1153
+ fields := pilosa.Field {Name : "id" , PrimaryKey : true , Actions : []pilosa.Action {action }}
1154
+ inputDef , err := index .CreateInputDefinition ("test" , []pilosa.InputFrame {frames }, []pilosa.Field {fields })
1155
+ if err != nil {
1156
+ t .Fatal (err )
1157
+ }
1158
+
1159
+ response := & pilosa.InputDefinitionInfo {Frames : inputDef .Frames (), Fields : inputDef .Fields ()}
1160
+ expect , err := json .Marshal (response )
1161
+ if err != nil {
1162
+ t .Fatal (err )
1163
+ }
1164
+ h := NewHandler ()
1165
+ h .Holder = hldr .Holder
1166
+ h .Cluster = NewCluster (1 )
1167
+ w := httptest .NewRecorder ()
1168
+ h .ServeHTTP (w , MustNewHTTPRequest ("GET" , "/index/i0/input-definition/test" , strings .NewReader ("" )))
1169
+ if w .Code != http .StatusOK {
1170
+ t .Fatalf ("unexpected status code: %d" , w .Code )
1171
+ } else if body := w .Body .String (); body != string (expect )+ "\n " {
1172
+ t .Fatalf ("unexpected body: %s, expect: %s" , body , string (expect ))
1173
+ }
1174
+ }
0 commit comments