@@ -27,6 +27,12 @@ func TestGoodIndexJSON(t *testing.T) {
2727
2828 err := ValidateMetadataFile (fileName , fileBytes )
2929 assert .NoError (t , err , "Error validating a good index" )
30+
31+ fileName = "META-INF/statedb/mongodb/indexes/myIndex.json"
32+ fileBytes = []byte (`{"index":{"fields":["data.docType","data.owner"]},"name":"indexOwner"}` )
33+
34+ err = ValidateMetadataFile (fileName , fileBytes )
35+ assert .NoError (t , err , "Error validating a good index" )
3036}
3137
3238func TestBadIndexJSON (t * testing.T ) {
@@ -46,6 +52,19 @@ func TestBadIndexJSON(t *testing.T) {
4652 assert .True (t , ok , "Should have received an InvalidIndexContentError" )
4753
4854 t .Log ("SAMPLE ERROR STRING:" , err .Error ())
55+
56+ fileName = "META-INF/statedb/mongodb/indexes/myIndex.json"
57+ fileBytes = []byte ("invalid json" )
58+
59+ err = ValidateMetadataFile (fileName , fileBytes )
60+
61+ assert .Error (t , err , "Should have received an InvalidIndexContentError" )
62+
63+ // Type assertion on InvalidIndexContentError
64+ _ , ok = err .(* InvalidIndexContentError )
65+ assert .True (t , ok , "Should have received an InvalidIndexContentError" )
66+
67+ t .Log ("SAMPLE ERROR STRING:" , err .Error ())
4968}
5069
5170func TestIndexWrongLocation (t * testing.T ) {
@@ -64,6 +83,18 @@ func TestIndexWrongLocation(t *testing.T) {
6483 assert .True (t , ok , "Should have received an UnhandledDirectoryError" )
6584
6685 t .Log ("SAMPLE ERROR STRING:" , err .Error ())
86+
87+ fileName = "META-INF/statedb/mongodb/myIndex.json"
88+ fileBytes = []byte (`{"index":{"fields":["data.docType","data.owner"]},"name":"indexOwner"` )
89+
90+ err = ValidateMetadataFile (fileName , fileBytes )
91+ assert .Error (t , err , "Should have received an UnhandledDirectoryError" )
92+
93+ // Type assertion on UnhandledDirectoryError
94+ _ , ok = err .(* UnhandledDirectoryError )
95+ assert .True (t , ok , "Should have received an UnhandledDirectoryError" )
96+
97+ t .Log ("SAMPLE ERROR STRING:" , err .Error ())
6798}
6899
69100func TestInvalidMetadataType (t * testing.T ) {
@@ -80,6 +111,7 @@ func TestInvalidMetadataType(t *testing.T) {
80111 // Type assertion on UnhandledDirectoryError
81112 _ , ok := err .(* UnhandledDirectoryError )
82113 assert .True (t , ok , "Should have received an UnhandledDirectoryError" )
114+
83115}
84116
85117func TestBadMetadataExtension (t * testing.T ) {
@@ -108,6 +140,14 @@ func TestBadFilePaths(t *testing.T) {
108140 fmt .Println (err )
109141 assert .Error (t , err , "Should have received an error for bad META-INF directory" )
110142
143+ // Test bad META-INF
144+ fileName = "META-INF1/statedb/mongodb/indexes/test1.json"
145+ fileBytes = []byte (`{"index":{"fields":["data.docType","data.owner"]},"name":"indexOwner","type":"json"}` )
146+
147+ err = ValidateMetadataFile (fileName , fileBytes )
148+ fmt .Println (err )
149+ assert .Error (t , err , "Should have received an error for bad META-INF directory" )
150+
111151 // Test bad path length
112152 fileName = "META-INF/statedb/test1.json"
113153 fileBytes = []byte (`{"index":{"fields":["data.docType","data.owner"]},"name":"indexOwner","type":"json"}` )
@@ -116,6 +156,14 @@ func TestBadFilePaths(t *testing.T) {
116156 fmt .Println (err )
117157 assert .Error (t , err , "Should have received an error for bad length" )
118158
159+ // Test invalid indexes directory name
160+ fileName = "META-INF/statedb/mongodb/index/test1.json"
161+ fileBytes = []byte (`{"index":{"fields":["data.docType","data.owner"]},"name":"indexOwner","type":"json"}` )
162+
163+ err = ValidateMetadataFile (fileName , fileBytes )
164+ fmt .Println (err )
165+ assert .Error (t , err , "Should have received an error for invalid indexes directory" )
166+
119167 // Test invalid database name
120168 fileName = "META-INF/statedb/goleveldb/indexes/test1.json"
121169 fileBytes = []byte (`{"index":{"fields":["data.docType","data.owner"]},"name":"indexOwner","type":"json"}` )
@@ -140,6 +188,14 @@ func TestBadFilePaths(t *testing.T) {
140188 fmt .Println (err )
141189 assert .Error (t , err , "Should have received an error for invalid collections directory" )
142190
191+ // Test invalid collections directory name
192+ fileName = "META-INF/statedb/mongodb/collection/testcoll/indexes/test1.json"
193+ fileBytes = []byte (`{"index":{"fields":["data.docType","data.owner"]},"name":"indexOwner","type":"json"}` )
194+
195+ err = ValidateMetadataFile (fileName , fileBytes )
196+ fmt .Println (err )
197+ assert .Error (t , err , "Should have received an error for invalid collections directory" )
198+
143199 // Test valid collections name
144200 fileName = "META-INF/statedb/couchdb/collections/testcoll/indexes/test1.json"
145201 fileBytes = []byte (`{"index":{"fields":["data.docType","data.owner"]},"name":"indexOwner","type":"json"}` )
@@ -148,6 +204,14 @@ func TestBadFilePaths(t *testing.T) {
148204 fmt .Println (err )
149205 assert .NoError (t , err , "Error should not have been thrown for a valid collection name" )
150206
207+ // Test valid collections name
208+ fileName = "META-INF/statedb/mongodb/collections/testcoll/indexes/test1.json"
209+ fileBytes = []byte (`{"index":{"fields":["data.docType","data.owner"]},"name":"indexOwner","type":"json"}` )
210+
211+ err = ValidateMetadataFile (fileName , fileBytes )
212+ fmt .Println (err )
213+ assert .NoError (t , err , "Error should not have been thrown for a valid collection name" )
214+
151215 // Test invalid collections name
152216 fileName = "META-INF/statedb/couchdb/collections/#testcoll/indexes/test1.json"
153217 fileBytes = []byte (`{"index":{"fields":["data.docType","data.owner"]},"name":"indexOwner","type":"json"}` )
@@ -156,6 +220,14 @@ func TestBadFilePaths(t *testing.T) {
156220 fmt .Println (err )
157221 assert .Error (t , err , "Should have received an error for an invalid collection name" )
158222
223+ // Test invalid collections name
224+ fileName = "META-INF/statedb/mongodb/collections/#testcoll/indexes/test1.json"
225+ fileBytes = []byte (`{"index":{"fields":["data.docType","data.owner"]},"name":"indexOwner","type":"json"}` )
226+
227+ err = ValidateMetadataFile (fileName , fileBytes )
228+ fmt .Println (err )
229+ assert .Error (t , err , "Should have received an error for an invalid collection name" )
230+
159231 // Test invalid collections name
160232 fileName = "META-INF/statedb/couchdb/collections/testcoll/indexes/test1.txt"
161233 fileBytes = []byte (`{"index":{"fields":["data.docType","data.owner"]},"name":"indexOwner","type":"json"}` )
@@ -164,6 +236,13 @@ func TestBadFilePaths(t *testing.T) {
164236 fmt .Println (err )
165237 assert .Error (t , err , "Should have received an error for an invalid file name" )
166238
239+ // Test invalid collections name
240+ fileName = "META-INF/statedb/mongodb/collections/testcoll/indexes/test1.txt"
241+ fileBytes = []byte (`{"index":{"fields":["data.docType","data.owner"]},"name":"indexOwner","type":"json"}` )
242+
243+ err = ValidateMetadataFile (fileName , fileBytes )
244+ fmt .Println (err )
245+ assert .Error (t , err , "Should have received an error for an invalid file name" )
167246}
168247
169248func TestIndexValidation (t * testing.T ) {
0 commit comments