jx/internal/folio/folio_test.go

63 lines
1.1 KiB
Go
Raw Normal View History

2024-08-18 01:19:56 +00:00
// 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"
2024-09-24 19:22:49 +00:00
"decl/internal/tempdir"
2024-08-18 01:19:56 +00:00
)
2024-09-24 19:22:49 +00:00
var TempDir tempdir.Path = "testfolio"
2024-08-18 01:19:56 +00:00
var ProcessTestUserName string
var ProcessTestGroupName string
func TestMain(m *testing.M) {
err := TempDir.Create()
2024-08-18 01:19:56 +00:00
if err != nil || TempDir == "" {
log.Fatal(err)
}
ProcessTestUserName, ProcessTestGroupName = ProcessUserName()
RegisterMocks()
2024-09-19 07:57:26 +00:00
RegisterConfigurationMocks()
2024-09-24 19:22:49 +00:00
RegisterConverterMocks()
2024-08-18 01:19:56 +00:00
rc := m.Run()
2024-09-24 19:22:49 +00:00
TempDir.Remove()
2024-08-18 01:19:56 +00:00
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 ""
}