github.com/opentofu/opentofu@v1.7.1/internal/states/statemgr/testdata/lockstate.go (about) 1 package main 2 3 import ( 4 "io" 5 "log" 6 "os" 7 8 "github.com/opentofu/opentofu/internal/encryption" 9 "github.com/opentofu/opentofu/internal/states/statemgr" 10 ) 11 12 // Attempt to open and lock a tofu state file. 13 // Lock failure exits with 0 and writes "lock failed" to stderr. 14 func main() { 15 if len(os.Args) != 2 { 16 log.Fatal(os.Args[0], "statefile") 17 } 18 19 s := statemgr.NewFilesystem(os.Args[1], encryption.StateEncryptionDisabled()) 20 21 info := statemgr.NewLockInfo() 22 info.Operation = "test" 23 info.Info = "state locker" 24 25 _, err := s.Lock(info) 26 if err != nil { 27 io.WriteString(os.Stderr, "lock failed") 28 } 29 }