0b92f1c2f3
apply, flush and purge take the try lock and fail with ErrPending, which now names 'tomswall revert' as the recovery after a failed automatic revert. Each try gets an ID passed to the timer's 'revert --id', so a stale timer cannot revert a newer try. Adds tests for Revert success/failure/stale ID and for restoring a present table at the engine level.
31 lines
722 B
Go
31 lines
722 B
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"git.unkin.net/unkin/tomswall/internal/tryapply"
|
|
)
|
|
|
|
func TestMutatingCommandsRefuseWhileTryPending(t *testing.T) {
|
|
orig := tryapply.Dir
|
|
tryapply.Dir = t.TempDir()
|
|
t.Cleanup(func() { tryapply.Dir = orig })
|
|
if err := os.WriteFile(filepath.Join(tryapply.Dir, "try-snapshot.json"), []byte("{}"), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
configPath = "../../tomswall.example.yaml"
|
|
|
|
for _, cmd := range []*cobra.Command{applyCmd(), flushCmd(), purgeCmd()} {
|
|
t.Run(cmd.Use, func(t *testing.T) {
|
|
if err := cmd.RunE(cmd, nil); !errors.Is(err, tryapply.ErrPending) {
|
|
t.Errorf("got %v, want ErrPending", err)
|
|
}
|
|
})
|
|
}
|
|
}
|