示例#1
0
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
}
示例#2
0
		expectedImportPaths: nil,
	},
	"1 NoVCL 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...)

			git.Service = git.NewGitStub()
		},
		expectedImportPaths: map[string]LocalProject{
			"test1": &ProjectNoVCL{},
		},
	},
	"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...)