github.com/temphia/temphia@v0.0.0-20240217195838-8c2001a6d2da/cmd/tests/main_test.go (about)

     1  package tests
     2  
     3  import (
     4  	"os"
     5  	"path"
     6  	"testing"
     7  
     8  	"github.com/k0kubun/pp"
     9  	"github.com/temphia/temphia/code/executors/re/retest"
    10  )
    11  
    12  func TestMain(m *testing.M) {
    13  	if os.Args[len(os.Args)-1] == "list_tests" {
    14  		pp.Println(m)
    15  		return
    16  	}
    17  
    18  	pp.Println("Test setup")
    19  
    20  	exitCode := m.Run()
    21  
    22  	pp.Println("Test teardown")
    23  
    24  	os.Exit(exitCode)
    25  }
    26  
    27  func TestDummyTest(t *testing.T) {
    28  
    29  }
    30  
    31  func TestRemoteExecutor(t *testing.T) {
    32  	WithPath("../../code/executors/re", t)(retest.TestRe)
    33  }
    34  
    35  func WithPath(p string, t *testing.T) func(func(t *testing.T)) {
    36  	return func(f func(t *testing.T)) {
    37  
    38  		dir, err := os.Getwd()
    39  		if err != nil {
    40  			t.Fatal("COULD NOT GET WORKING DIR PATH", err)
    41  		}
    42  
    43  		err = os.Chdir(path.Join(dir, p))
    44  		if err != nil {
    45  			t.Fatal(err)
    46  		}
    47  
    48  		f(t)
    49  		err = os.Chdir(dir)
    50  		if err != nil {
    51  			t.Fatal(err)
    52  		}
    53  
    54  	}
    55  }