1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-03-27 22:01:46 +02:00
2022-08-11 21:24:15 +10:00

62 lines
1.1 KiB
Go

package integration
import (
"encoding/json"
"io/ioutil"
"log"
"os"
"strconv"
"github.com/jesseduffield/gocui"
)
// this all relates to the old way of doing integration tests where you record yourself
// and then replay the events.
func GetRecordingSpeed() float64 {
// humans are slow so this speeds things up.
speed := 1.0
envReplaySpeed := os.Getenv("SPEED")
if envReplaySpeed != "" {
var err error
speed, err = strconv.ParseFloat(envReplaySpeed, 64)
if err != nil {
log.Fatal(err)
}
}
return speed
}
func LoadRecording() (*gocui.Recording, error) {
path := os.Getenv("REPLAY_EVENTS_FROM")
data, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
recording := &gocui.Recording{}
err = json.Unmarshal(data, &recording)
if err != nil {
return nil, err
}
return recording, nil
}
func SaveRecording(recording *gocui.Recording) error {
if !RecordingEvents() {
return nil
}
jsonEvents, err := json.Marshal(recording)
if err != nil {
return err
}
path := recordEventsTo()
return ioutil.WriteFile(path, jsonEvents, 0o600)
}