-
Notifications
You must be signed in to change notification settings - Fork 2
/
api_testsuite_test.go
49 lines (35 loc) · 1.23 KB
/
api_testsuite_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
package main
import (
"testing"
"github.com/programmfabrik/apitest/pkg/lib/filesystem"
"github.com/spf13/afero"
)
func TestLoadManifest(t *testing.T) {
filesystem.Fs = afero.NewMemMapFs()
afero.WriteFile(filesystem.Fs, "externalFile", []byte(`{"load":{"me":"loaded"}}`), 644)
afero.WriteFile(filesystem.Fs, "testManifest.json", []byte(`{"testload": {{ file "externalFile" | gjson "load.me"}}}`), 644)
s := Suite{manifestPath: "testManifest.json"}
res, err := s.loadManifest()
if err != nil {
t.Fatal(err)
}
if string(res) != `{"testload": "loaded"}` {
t.Errorf(`Exp '{"testload": "loaded"}' != '%s' Got`, res)
}
}
func TestLoadManifestCustomDelimiters(t *testing.T) {
filesystem.Fs = afero.NewMemMapFs()
afero.WriteFile(filesystem.Fs, "externalFile", []byte(`{"load":{"me":"loaded"}}`), 0644)
afero.WriteFile(filesystem.Fs, "testManifest.json", []byte(`// template-delims: ## ##
// template-remove-tokens: "<placeholder>" "...."
{"testload": ## file "externalFile" | gjson "load.me" ##}"...."`), 0644)
s := Suite{manifestPath: "testManifest.json"}
res, err := s.loadManifest()
if err != nil {
t.Fatal(err)
}
if string(res) != `
{"testload": "loaded"}` {
t.Errorf(`Exp '{"testload": "loaded"}' != '%s' Got`, res)
}
}