jx/internal/folio/folio_test.go
Matthew Rich f1a56b0968
Some checks are pending
Lint / golangci-lint (push) Waiting to run
Declarative Tests / test (push) Waiting to run
Declarative Tests / build-fedora (push) Waiting to run
Declarative Tests / build-ubuntu-focal (push) Waiting to run
add document state transformer interface
2024-09-25 04:49:24 +00:00

63 lines
1.1 KiB
Go

// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
package folio
import (
_ "fmt"
_ "github.com/stretchr/testify/assert"
"log"
"os"
"os/user"
"os/exec"
_ "path/filepath"
"testing"
"decl/internal/tempdir"
)
var TempDir tempdir.Path = "testfolio"
var ProcessTestUserName string
var ProcessTestGroupName string
func TestMain(m *testing.M) {
err := TempDir.Create()
if err != nil || TempDir == "" {
log.Fatal(err)
}
ProcessTestUserName, ProcessTestGroupName = ProcessUserName()
RegisterMocks()
RegisterConfigurationMocks()
RegisterConverterMocks()
rc := m.Run()
TempDir.Remove()
os.Exit(rc)
}
func ProcessUserName() (string, string) {
processUser, userErr := user.Current()
if userErr != nil {
panic(userErr)
}
processGroup, groupErr := user.LookupGroupId(processUser.Gid)
if groupErr != nil {
panic(groupErr)
}
return processUser.Username, processGroup.Name
}
func ExitError(e error) string {
if e != nil {
switch v := e.(type) {
case *exec.ExitError:
return string(v.Stderr)
default:
return e.Error()
}
}
return ""
}