github.com/metux/go-metabuild@v0.0.0-20240118143255-d9ed5ab697f9/engine/main_test.go (about)

     1  package engine
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  
     7  	magic "github.com/metux/go-magicdict"
     8  )
     9  
    10  const (
    11  	StdStage = StagePackage
    12  )
    13  
    14  var (
    15  	TestingEngine *Engine
    16  )
    17  
    18  func LoadTestingEngine(t *testing.T) {
    19  	// jump.to projects root
    20  	os.Chdir("../")
    21  
    22  	if TestingEngine != nil {
    23  		return
    24  	}
    25  
    26  	engine := Engine{}
    27  	if err := engine.Load("examples/pkg/zlib/metabuild.yaml", "examples/conf/settings.yaml"); err != nil {
    28  		t.Fatalf("yaml load failed: %s", err)
    29  	}
    30  
    31  	TestingEngine = &engine
    32  }
    33  
    34  // extra check whether SpecObj really implements the magic.Entry interface
    35  func test1(t *testing.T, ent magic.Entry) {
    36  	t.Logf("%s", ent.Keys())
    37  }
    38  
    39  func TestEngine(t *testing.T) {
    40  	LoadTestingEngine(t)
    41  	if err := TestingEngine.RunStage(StdStage); err != nil {
    42  		t.Fatal("build error:", err)
    43  	}
    44  
    45  	test1(t, (*TestingEngine).Global)
    46  	(*TestingEngine).Global.YamlStore("/tmp/metabuild-dump.yaml", 0644)
    47  }