summaryrefslogtreecommitdiffstats
path: root/app/import_test.go
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2017-02-16 14:49:01 +0000
committerHarrison Healey <harrisonmhealey@gmail.com>2017-02-16 09:49:01 -0500
commitd60d05f2d86400faf3303e655c46c5b8d77879c4 (patch)
tree8907bdf20c38ab06c066c0946126157462b34981 /app/import_test.go
parent821939e5dab144ac14b4f288cb8d0c9e3bb570d0 (diff)
downloadchat-d60d05f2d86400faf3303e655c46c5b8d77879c4.tar.gz
chat-d60d05f2d86400faf3303e655c46c5b8d77879c4.tar.bz2
chat-d60d05f2d86400faf3303e655c46c5b8d77879c4.zip
PLT-5521: Mandatory version in line 1 of bulk import. (#5400)
Diffstat (limited to 'app/import_test.go')
-rw-r--r--app/import_test.go41
1 files changed, 39 insertions, 2 deletions
diff --git a/app/import_test.go b/app/import_test.go
index 008267942..ea71d0e0c 100644
--- a/app/import_test.go
+++ b/app/import_test.go
@@ -18,6 +18,10 @@ func ptrInt64(i int64) *int64 {
return &i
}
+func ptrInt(i int) *int {
+ return &i
+}
+
func ptrBool(b bool) *bool {
return &b
}
@@ -1367,7 +1371,8 @@ func TestImportBulkImport(t *testing.T) {
channelName := model.NewId()
// Run bulk import with a valid 1 of everything.
- data1 := `{"type": "team", "team": {"type": "O", "display_name": "lskmw2d7a5ao7ppwqh5ljchvr4", "name": "` + teamName + `"}}
+ data1 := `{"type": "version", "version": 1}
+{"type": "team", "team": {"type": "O", "display_name": "lskmw2d7a5ao7ppwqh5ljchvr4", "name": "` + teamName + `"}}
{"type": "channel", "channel": {"type": "O", "display_name": "xr6m6udffngark2uekvr3hoeny", "team": "` + teamName + `", "name": "` + channelName + `"}}
{"type": "user", "user": {"username": "kufjgnkxkrhhfgbrip6qxkfsaa", "email": "kufjgnkxkrhhfgbrip6qxkfsaa@example.com"}}
{"type": "user", "user": {"username": "bwshaim6qnc2ne7oqkd5b2s2rq", "email": "bwshaim6qnc2ne7oqkd5b2s2rq@example.com", "teams": [{"name": "` + teamName + `", "channels": [{"name": "` + channelName + `"}]}]}}`
@@ -1377,8 +1382,40 @@ func TestImportBulkImport(t *testing.T) {
}
// Run bulk import using a string that contains a line with invalid json.
- data2 := `{"type": "team", "team": {"type": "O", "display_name": "lskmw2d7a5ao7ppwqh5ljchvr4", "name": "vinewy665jam3n6oxzhsdgajly"}`
+ data2 := `{"type": "version", "version": 1`
if err, line := BulkImport(strings.NewReader(data2), false); err == nil || line != 1 {
t.Fatalf("Should have failed due to invalid JSON on line 1.")
}
+
+ // Run bulk import using valid JSON but missing version line at the start.
+ data3:= `{"type": "team", "team": {"type": "O", "display_name": "lskmw2d7a5ao7ppwqh5ljchvr4", "name": "` + teamName + `"}}
+{"type": "channel", "channel": {"type": "O", "display_name": "xr6m6udffngark2uekvr3hoeny", "team": "` + teamName + `", "name": "` + channelName + `"}}
+{"type": "user", "user": {"username": "kufjgnkxkrhhfgbrip6qxkfsaa", "email": "kufjgnkxkrhhfgbrip6qxkfsaa@example.com"}}
+{"type": "user", "user": {"username": "bwshaim6qnc2ne7oqkd5b2s2rq", "email": "bwshaim6qnc2ne7oqkd5b2s2rq@example.com", "teams": [{"name": "` + teamName + `", "channels": [{"name": "` + channelName + `"}]}]}}`
+ if err, line := BulkImport(strings.NewReader(data3), false); err == nil || line != 1 {
+ t.Fatalf("Should have failed due to missing version line on line 1.")
+ }
+}
+
+func TestImportProcessImportDataFileVersionLine(t *testing.T) {
+ _ = Setup()
+
+ data := LineImportData{
+ Type: "version",
+ Version: ptrInt(1),
+ }
+ if version, err := processImportDataFileVersionLine(data); err != nil || version != 1 {
+ t.Fatalf("Expected no error and version 1.")
+ }
+
+ data.Type = "NotVersion"
+ if _, err := processImportDataFileVersionLine(data); err == nil {
+ t.Fatalf("Expected error on invalid version line.")
+ }
+
+ data.Type = "version"
+ data.Version = nil
+ if _, err := processImportDataFileVersionLine(data); err == nil {
+ t.Fatalf("Expected error on invalid version line.")
+ }
}