-
Notifications
You must be signed in to change notification settings - Fork 26
/
scenarioOne.go
58 lines (48 loc) · 1.38 KB
/
scenarioOne.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
50
51
52
53
54
55
56
57
58
package mandoscontroller
import (
"io/ioutil"
"os"
"path/filepath"
mj "github.com/ElrondNetwork/arwen-wasm-vm/mandos-go/json/model"
mjwrite "github.com/ElrondNetwork/arwen-wasm-vm/mandos-go/json/write"
)
// RunSingleJSONScenario parses and prepares test, then calls testCallback.
func (r *ScenarioRunner) RunSingleJSONScenario(contextPath string) error {
var err error
contextPath, err = filepath.Abs(contextPath)
if err != nil {
return err
}
// Open our jsonFile
var jsonFile *os.File
jsonFile, err = os.Open(contextPath)
// if we os.Open returns an error then handle it
if err != nil {
return err
}
// defer the closing of our jsonFile so that we can parse it later on
defer jsonFile.Close()
byteValue, err := ioutil.ReadAll(jsonFile)
if err != nil {
return err
}
r.Parser.ValueInterpreter.FileResolver.SetContext(contextPath)
scenario, parseErr := r.Parser.ParseScenarioFile(byteValue)
if parseErr != nil {
return parseErr
}
return r.Executor.ExecuteScenario(scenario, r.Parser.ValueInterpreter.FileResolver)
}
// tool to modify scenarios
// use with extreme caution
func saveModifiedScenario(toPath string, scenario *mj.Scenario) {
resultJSON := mjwrite.ScenarioToJSONString(scenario)
err := os.MkdirAll(filepath.Dir(toPath), os.ModePerm)
if err != nil {
panic(err)
}
err = ioutil.WriteFile(toPath, []byte(resultJSON), 0644)
if err != nil {
panic(err)
}
}