opentofu/internal/states/statemgr/testdata/lockstate.go
Marcin Wyszynski 772ac1fc35
Pass context to all statemgr.Locker operations (#789)
Signed-off-by: Marcin Wyszynski <marcin.pixie@gmail.com>
2023-10-25 14:22:11 +02:00

32 lines
557 B
Go

package main
import (
"context"
"io"
"log"
"os"
"github.com/opentofu/opentofu/internal/states/statemgr"
)
// Attempt to open and lock a tofu state file.
// Lock failure exits with 0 and writes "lock failed" to stderr.
func main() {
if len(os.Args) != 2 {
log.Fatal(os.Args[0], "statefile")
}
s := statemgr.NewFilesystem(os.Args[1])
info := statemgr.NewLockInfo()
info.Operation = "test"
info.Info = "state locker"
ctx := context.Background()
_, err := s.Lock(ctx, info)
if err != nil {
io.WriteString(os.Stderr, "lock failed")
}
}