github.com/mithrandie/csvq@v1.18.1/lib/parser/main_test.go (about)

     1  package parser
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"testing"
     7  )
     8  
     9  func GetTestFilePath(filename string) string {
    10  	return filepath.Join(TestDir, filename)
    11  }
    12  
    13  var TestDir = filepath.Join(os.TempDir(), "csvq_parser_test")
    14  
    15  func TestMain(m *testing.M) {
    16  	os.Exit(run(m))
    17  }
    18  
    19  func run(m *testing.M) int {
    20  	defer teardown()
    21  
    22  	setup()
    23  	return m.Run()
    24  }
    25  
    26  func setup() {
    27  	if _, err := os.Stat(TestDir); err == nil {
    28  		_ = os.RemoveAll(TestDir)
    29  	}
    30  
    31  	if _, err := os.Stat(TestDir); os.IsNotExist(err) {
    32  		_ = os.Mkdir(TestDir, 0755)
    33  	}
    34  
    35  	fp, _ := os.Create(GetTestFilePath("dummy.sql"))
    36  	defer func() { _ = fp.Close() }()
    37  }
    38  
    39  func teardown() {
    40  	if _, err := os.Stat(TestDir); err == nil {
    41  		_ = os.RemoveAll(TestDir)
    42  	}
    43  }