github.com/shved/got@v0.0.0-20230322140632-a4bfa1e99685/got/got_test.go (about)

     1  package got
     2  
     3  import (
     4  	"io/ioutil"
     5  	"log"
     6  	"os"
     7  	"path"
     8  	"path/filepath"
     9  	"testing"
    10  
    11  	"github.com/shved/got/misc"
    12  )
    13  
    14  var dummyAppPath string
    15  
    16  func TestMain(m *testing.M) {
    17  	rootP, err := filepath.Abs("..")
    18  	if err != nil {
    19  		log.Fatalf("get dummy app abs path: %v", err)
    20  	}
    21  	dummyAppPath = path.Join(rootP, "test/dummy_app")
    22  	os.Chdir(dummyAppPath)
    23  
    24  	misc.CreateDummyApp()
    25  	exitCode := m.Run()
    26  	misc.RemoveDummyApp()
    27  	os.Exit(exitCode)
    28  }
    29  
    30  func TestInitRepo(t *testing.T) {
    31  	InitRepo()
    32  	entries, err := ioutil.ReadDir(dummyAppPath)
    33  	if err != nil {
    34  		t.Fatalf("reading dummy app dir: %v", err)
    35  	}
    36  	var names []string
    37  	for _, fi := range entries {
    38  		names = append(names, fi.Name())
    39  	}
    40  
    41  	var repoInitiated = false
    42  	for _, name := range names {
    43  		if name == ".got" {
    44  			repoInitiated = true
    45  		}
    46  	}
    47  
    48  	if !repoInitiated {
    49  		t.Fatalf("no repo dir found in dummy app path, got %v", names)
    50  	}
    51  
    52  	SetRepoRoot()
    53  	if AbsRepoRoot != dummyAppPath {
    54  		t.Fatalf("expected repo root to be %v, got %v", dummyAppPath, AbsRepoRoot)
    55  	}
    56  }