2023-10-31 22:58:28 +01:00
|
|
|
package bfcodegen
|
|
|
|
|
|
|
|
import (
|
|
|
|
_ "embed"
|
|
|
|
"fmt"
|
|
|
|
"gogs.mikescher.com/BlackForestBytes/goext/cmdext"
|
|
|
|
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
|
|
|
"gogs.mikescher.com/BlackForestBytes/goext/tst"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2023-12-07 17:57:06 +01:00
|
|
|
//go:embed _test_example_1.tgz
|
|
|
|
var IDExampleModels1 []byte
|
2023-10-31 22:58:28 +01:00
|
|
|
|
|
|
|
func TestGenerateIDSpecs(t *testing.T) {
|
|
|
|
|
|
|
|
tmpFile := filepath.Join(t.TempDir(), langext.MustHexUUID()+".tgz")
|
|
|
|
|
|
|
|
tmpDir := filepath.Join(t.TempDir(), langext.MustHexUUID())
|
|
|
|
|
2023-12-07 17:57:06 +01:00
|
|
|
err := os.WriteFile(tmpFile, IDExampleModels1, 0o777)
|
2023-10-31 22:58:28 +01:00
|
|
|
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 = GenerateIDSpecs(tmpDir, tmpDir+"/id_gen.go")
|
|
|
|
tst.AssertNoErr(t, err)
|
|
|
|
|
|
|
|
err = GenerateIDSpecs(tmpDir, tmpDir+"/id_gen.go")
|
|
|
|
tst.AssertNoErr(t, err)
|
|
|
|
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Println("=====================================================================================================")
|
|
|
|
fmt.Println(string(tst.Must(os.ReadFile(tmpDir + "/id_gen.go"))(t)))
|
|
|
|
fmt.Println("=====================================================================================================")
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Println()
|
|
|
|
}
|