-
Notifications
You must be signed in to change notification settings - Fork 0
/
folder_parser_test.go
47 lines (40 loc) · 1.21 KB
/
folder_parser_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
package main
import (
"couchappp-go/tests"
"encoding/base64"
"testing"
)
func TestFolderToJSONS_SimpleDesign(t *testing.T) {
result, err := FolderToJSON("tests/fixtures/simple_design")
if err != nil {
t.Errorf("Unexpected error %v", err)
}
expected := "_design/simple"
if result["_id"] != expected {
t.Errorf("Expected %s, but got %s", expected, result["_id"])
}
}
func TestProcessFolderToCouch_SimpleDesign(t *testing.T) {
const TargetDB = "test1"
authTestConfig, err := tests.LoadTestConfig()
if err != nil {
t.Errorf("Config file not properly setup %v", err)
}
params := CliParams{
source: "tests/fixtures/simple_design",
db: TargetDB,
host: "http://localhost:5984",
}
if authTestConfig.Username != "" {
params.base64auth = "Basic " + base64.StdEncoding.EncodeToString([]byte(authTestConfig.Username+":"+authTestConfig.Password))
}
// cleanup before pushing
_, _ = deleteDatabase(params.host, params.db, params.base64auth)
ProcessFolderToCouch(params)
// fetch document and make sure id matches
expected := "_design/simple"
doc, _ := getDoc(params.host, params.db, expected, params.base64auth)
if doc["_id"] != expected {
t.Errorf("Expected %s, but got %s", expected, doc["_id"])
}
}