goext/bfcodegen/enum-generate_test.go

43 lines
1.0 KiB
Go
Raw Normal View History

2023-06-07 12:45:48 +02:00
package bfcodegen
import (
2023-08-14 18:39:22 +02:00
_ "embed"
"gogs.mikescher.com/BlackForestBytes/goext/cmdext"
"gogs.mikescher.com/BlackForestBytes/goext/langext"
"gogs.mikescher.com/BlackForestBytes/goext/tst"
"os"
"path/filepath"
2023-06-07 12:45:48 +02:00
"testing"
2023-08-14 18:39:22 +02:00
"time"
2023-06-07 12:45:48 +02:00
)
2023-08-14 18:39:22 +02:00
//go:embed _test_example.tgz
var ExampleModels []byte
2023-06-07 12:45:48 +02:00
2023-08-14 18:39:22 +02:00
func TestGenerateEnumSpecs(t *testing.T) {
tmpFile := filepath.Join(t.TempDir(), langext.MustHexUUID()+".tgz")
tmpDir := filepath.Join(t.TempDir(), langext.MustHexUUID())
err := os.WriteFile(tmpFile, ExampleModels, 0o777)
tst.AssertNoErr(t, err)
t.Cleanup(func() { _ = os.Remove(tmpFile) })
err = os.Mkdir(tmpDir, 0o777)
tst.AssertNoErr(t, err)
t.Cleanup(func() { _ = os.RemoveAll(tmpFile) })
_, err = cmdext.Runner("tar").Arg("-xvzf").Arg(tmpFile).Arg("-C").Arg(tmpDir).FailOnExitCode().FailOnTimeout().Timeout(time.Minute).Run()
tst.AssertNoErr(t, err)
err = GenerateEnumSpecs(tmpDir, tmpDir+"/enums_gen.go")
tst.AssertNoErr(t, err)
err = GenerateEnumSpecs(tmpDir, tmpDir+"/enums_gen.go")
tst.AssertNoErr(t, err)
2023-06-07 12:45:48 +02:00
}