func newLocalGitProject(t *testing.T, gitStub *git.GitStub) (project *localGitProject, gitRepoStub *git.GitRepoStub) { tmpDirPath, err := ioutil.TempDir("", "godm-local_git_project_test") if !assert.Nil(t, err, "Failed creating a temp dir for localGitProject tests.") { t.FailNow() } if gitStub == nil { gitStub = git.NewGitStub() } gitRepoStub = git.NewGitRepoStub() gitStub.Repos[tmpDirPath] = gitRepoStub git.Service = gitStub project, err = NewGitProjectFromPath(tmpDirPath, tmpDirPath) if !assert.Nil(t, err, "Failed creating a localGitProject for tests.") { t.FailNow() } if !assert.Equal(t, tmpDirPath, project.GetBaseDir(), "Fresh localGitProject from temp dir has a wrong base dir.") { t.FailNow() } return }
"1 Git vendor": { prepare: func(t *testing.T, project *ProjectNoVCL, failMessageAndArgs ...interface{}) { targetDirPath := path.Join(project.GetBaseDir(), "vendor", "test1") + "/" err := os.MkdirAll(targetDirPath, os.ModeDir|os.ModePerm) assert.Nil(t, err, failMessageAndArgs...) targetFilePath := path.Join(targetDirPath, "whatever.go") file, err := os.Create(targetFilePath) assert.Nil(t, err, failMessageAndArgs...) _, err = file.WriteString("package test1\n") assert.Nil(t, err, failMessageAndArgs...) gitStub := git.NewGitStub() gitStub.Repos[targetDirPath] = git.NewGitRepoStub() git.Service = gitStub }, expectedImportPaths: map[string]LocalProject{ "test1": &localGitProject{}, }, }, } func TestProjectNoVCL_GetVendors(t *testing.T) { testCasesLoop: for caseName, testCase := range testCases { failMessageAndArgs := []interface{}{"Test case %q failed.", caseName} project := newProjectNoVCLProject(t) defer os.RemoveAll(project.GetBaseDir())