当前位置: 首页>>代码示例>>Golang>>正文


Golang errors.NewSourcePathError函数代码示例

本文整理汇总了Golang中github.com/openshift/source-to-image/pkg/errors.NewSourcePathError函数的典型用法代码示例。如果您正苦于以下问题:Golang NewSourcePathError函数的具体用法?Golang NewSourcePathError怎么用?Golang NewSourcePathError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewSourcePathError函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Download

// Download downloads the application source code from the GIT repository
// and checkout the Ref specified in the config.
func (c *Clone) Download(config *api.Config) (*api.SourceInfo, error) {
	targetSourceDir := filepath.Join(config.WorkingDir, api.Source)
	config.WorkingSourceDir = targetSourceDir
	var info *api.SourceInfo

	if c.ValidCloneSpec(config.Source) {
		if len(config.ContextDir) > 0 {
			targetSourceDir = filepath.Join(config.WorkingDir, api.ContextTmp)
		}
		glog.V(2).Infof("Cloning into %s", targetSourceDir)
		if err := c.Clone(config.Source, targetSourceDir); err != nil {
			glog.V(1).Infof("Git clone failed: %+v", err)
			return nil, err
		}

		if len(config.Ref) > 0 {
			if err := c.Checkout(targetSourceDir, config.Ref); err != nil {
				return nil, err
			}
			glog.V(1).Infof("Checked out %q", config.Ref)
		}

		if len(config.ContextDir) > 0 {
			originalTargetDir := filepath.Join(config.WorkingDir, api.Source)
			c.RemoveDirectory(originalTargetDir)
			// we want to copy entire dir contents, thus we need to use dir/. construct
			path := filepath.Join(targetSourceDir, config.ContextDir) + string(filepath.Separator) + "."
			err := c.Copy(path, originalTargetDir)
			if err != nil {
				return nil, err
			}
			info = c.GetInfo(targetSourceDir)
			c.RemoveDirectory(targetSourceDir)
		} else {
			info = c.GetInfo(targetSourceDir)
		}

		if len(config.ContextDir) > 0 {
			info.ContextDir = config.ContextDir
		}

		return info, nil
	}
	// we want to copy entire dir contents, thus we need to use dir/. construct
	path := filepath.Join(config.Source, config.ContextDir) + string(filepath.Separator) + "."
	if !c.Exists(path) {
		return nil, errors.NewSourcePathError(path)
	}
	if err := c.Copy(path, targetSourceDir); err != nil {
		return nil, err
	}

	// When building from a local directory (not using GIT clone spec scheme) we
	// skip gathering informations about the source as there is no guarantee that
	// the folder is a GIT repository or it requires context-dir to be set.
	if !config.Quiet {
		glog.Warning("You are using <source> location that is not valid GIT repository. The source code information will not be stored into the output image. Use this image only for local testing and development.")
	}
	return nil, nil
}
开发者ID:jhadvig,项目名称:origin,代码行数:62,代码来源:clone.go

示例2: TestFetchSource

func TestFetchSource(t *testing.T) {
	type fetchTest struct {
		validCloneSpec   bool
		refSpecified     bool
		cloneExpected    bool
		checkoutExpected bool
		copyExpected     bool
		sourcePath       string
		expectedError    *error
	}

	err := stierr.NewSourcePathError("error")
	tests := []fetchTest{
		// 0
		{
			validCloneSpec:   false,
			refSpecified:     false,
			cloneExpected:    false,
			checkoutExpected: false,
			copyExpected:     false,
			sourcePath:       "invalid/path",
			expectedError:    &err,
		},
		// 1
		{
			validCloneSpec:   false,
			refSpecified:     false,
			cloneExpected:    false,
			checkoutExpected: false,
			copyExpected:     true,
		},
		// 2
		{
			validCloneSpec:   true,
			refSpecified:     false,
			cloneExpected:    true,
			checkoutExpected: false,
			copyExpected:     false,
		},
		// 3
		{
			validCloneSpec:   true,
			refSpecified:     true,
			cloneExpected:    true,
			checkoutExpected: true,
			copyExpected:     false,
		},
	}

	for testNum, ft := range tests {
		bh := testBuildHandler()
		gh := bh.git.(*test.FakeGit)
		fh := bh.fs.(*test.FakeFileSystem)

		bh.config.WorkingDir = "/working-dir"
		gh.ValidCloneSpecResult = ft.validCloneSpec
		if ft.refSpecified {
			bh.config.Ref = "a-branch"
		}
		if len(ft.sourcePath) == 0 {
			bh.config.Source = "a-repo-source"
		} else {
			bh.config.Source = ft.sourcePath
		}

		expectedTargetDir := "/working-dir/upload/src"
		_, e := bh.source.Download(bh.config)
		if ft.expectedError == nil && e != nil {
			t.Errorf("Unexpected error %v [%d]", e, testNum)
		}
		if ft.expectedError != nil {
			if e == nil {
				t.Errorf("Did not get expected error [%d]", testNum)
				continue
			}
			if (*ft.expectedError).(stierr.Error).ErrorCode != e.(stierr.Error).ErrorCode {
				t.Errorf("Expected error code %d, got %d [%d]", (*ft.expectedError).(stierr.Error).ErrorCode, e.(stierr.Error).ErrorCode, testNum)
			}
		}
		if ft.cloneExpected {
			if gh.CloneSource != "a-repo-source" {
				t.Errorf("Clone was not called with the expected source. Got %s, expected %s [%d]", gh.CloneSource, "a-source-repo-source", testNum)
			}
			if gh.CloneTarget != expectedTargetDir {
				t.Errorf("Unexpected target directory for clone operation. Got %s, expected %s [%d]", gh.CloneTarget, expectedTargetDir, testNum)
			}
		}
		if ft.checkoutExpected {
			if gh.CheckoutRef != "a-branch" {
				t.Errorf("Checkout was not called with the expected branch. Got %s, expected %s [%d]", gh.CheckoutRef, "a-branch", testNum)
			}
			if gh.CheckoutRepo != expectedTargetDir {
				t.Errorf("Unexpected target repository for checkout operation. Got %s, expected %s [%d]", gh.CheckoutRepo, expectedTargetDir, testNum)
			}
		}
		if ft.copyExpected {
			if fh.CopySource != "a-repo-source/." {
				t.Errorf("Copy was not called with the expected source. Got %s, expected %s [%d]", fh.CopySource, "a-repo-source/.", testNum)
			}
			if fh.CopyDest != expectedTargetDir {
//.........这里部分代码省略.........
开发者ID:jdnieto,项目名称:origin,代码行数:101,代码来源:sti_test.go

示例3: Download

// Download downloads the application source code from the Git repository
// and checkout the Ref specified in the config.
func (c *Clone) Download(config *api.Config) (*api.SourceInfo, error) {
	targetSourceDir := filepath.Join(config.WorkingDir, api.Source)
	config.WorkingSourceDir = targetSourceDir
	var info *api.SourceInfo
	hasRef := len(config.Ref) > 0
	hasSubmodules := !config.DisableRecursive
	cloneConfig := api.CloneConfig{Quiet: true, Recursive: hasSubmodules && !hasRef}

	if c.ValidCloneSpec(config.Source) {
		if len(config.ContextDir) > 0 {
			targetSourceDir = filepath.Join(config.WorkingDir, api.ContextTmp)
			glog.V(1).Infof("Downloading %q (%q) ...", config.Source, config.ContextDir)
		} else {
			glog.V(1).Infof("Downloading %q ...", config.Source)
		}

		// If we have a specific checkout ref, use submodule update instead of recursive
		// Otherwise the versions will be incorrect.
		if hasRef && hasSubmodules {
			glog.V(2).Infof("Cloning sources (deferring submodule init) into %q", targetSourceDir)
		} else if cloneConfig.Recursive {
			glog.V(2).Infof("Cloning sources and all Git submodules into %q", targetSourceDir)
		} else {
			glog.V(2).Infof("Cloning sources into %q", targetSourceDir)
		}

		if err := c.Clone(config.Source, targetSourceDir, cloneConfig); err != nil {
			glog.V(1).Infof("Git clone failed: %+v", err)
			return nil, err
		}

		if hasRef {
			if err := c.Checkout(targetSourceDir, config.Ref); err != nil {
				return nil, err
			}
			glog.V(1).Infof("Checked out %q", config.Ref)
			if hasSubmodules {
				if err := c.SubmoduleUpdate(targetSourceDir, true, true); err != nil {
					return nil, err
				}
				glog.V(1).Infof("Updated submodules for %q", config.Ref)
			}
		}

		if len(config.ContextDir) > 0 {
			originalTargetDir := filepath.Join(config.WorkingDir, api.Source)
			c.RemoveDirectory(originalTargetDir)
			// we want to copy entire dir contents, thus we need to use dir/. construct
			path := filepath.Join(targetSourceDir, config.ContextDir) + string(filepath.Separator) + "."
			err := c.Copy(path, originalTargetDir)
			if err != nil {
				return nil, err
			}
			info = c.GetInfo(targetSourceDir)
			c.RemoveDirectory(targetSourceDir)
		} else {
			info = c.GetInfo(targetSourceDir)
		}

		if len(config.ContextDir) > 0 {
			info.ContextDir = config.ContextDir
		}

		return info, nil
	}
	// we want to copy entire dir contents, thus we need to use dir/. construct
	path := filepath.Join(config.Source, config.ContextDir) + string(filepath.Separator) + "."
	if !c.Exists(path) {
		return nil, errors.NewSourcePathError(path)
	}
	if err := c.Copy(path, targetSourceDir); err != nil {
		return nil, err
	}

	// When building from a local directory (not using Git clone spec scheme) we
	// skip gathering informations about the source as there is no guarantee that
	// the folder is a Git repository or it requires context-dir to be set.
	if !config.Quiet {
		glog.Warning("You are using <source> location that is not valid Git repository. The source code information will not be stored into the output image. Use this image only for local testing and development.")
	}
	return nil, nil
}
开发者ID:legionus,项目名称:origin,代码行数:84,代码来源:clone.go


注:本文中的github.com/openshift/source-to-image/pkg/errors.NewSourcePathError函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。