示例#1
0
func runSteps(t *testing.T, singleton bool, steps []step) {
	logOut := &bytes.Buffer{}
	logOut.WriteByte('\n')
	logW := &iotool.SafeWriter{W: logOut}
	defer func() {
		logW.SetWriter(nil) // disable writes to avoid races
		t.Log(logOut)
	}()

	dataOut := &bytes.Buffer{}
	sim := simulator.New(singleton, dataOut, logW)
	defer sim.Close()

	for _, step := range steps {
		if step.JSON != nil {
			jsonData, _ := json.Marshal(step.JSON)
			step.Cmd = fmt.Sprintf("%s %s", step.Cmd, string(jsonData))
		}

		fmt.Fprintf(logW, "== %s\n", step.Cmd)
		sim.RunCommand(step.Cmd)
		if step.Check != nil {
			actual := reflect.New(reflect.Indirect(reflect.ValueOf(step.Check)).Type()).Interface()
			if err := json.Unmarshal(dataOut.Bytes(), actual); err != nil {
				t.Fatal("json decode error", err)
			}
			if diff := pretty.Compare(step.Check, actual); diff != "" {
				t.Fatalf("check failed:\n%s", diff)
			}
		}
		dataOut.Reset()
	}
}
示例#2
0
文件: main.go 项目: devick/flynn
func main() {
	sim := simulator.New(false, os.Stdout, os.Stdout)
	scanner := uniline.DefaultScanner()
	for scanner.Scan("> ") {
		line := scanner.Text()
		if len(line) == 0 {
			continue
		}

		sim.RunCommand(strings.TrimSpace(line))
		scanner.AddToHistory(line)
	}
	if err := scanner.Err(); err != nil {
		panic(err)
	}
}