63 lines
1.1 KiB
Go
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 ""
|
|
}
|