本文整理汇总了Golang中v/io/jiri.X.BinDir方法的典型用法代码示例。如果您正苦于以下问题:Golang X.BinDir方法的具体用法?Golang X.BinDir怎么用?Golang X.BinDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类v/io/jiri.X
的用法示例。
在下文中一共展示了X.BinDir方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: testTransitionBinDir
func testTransitionBinDir(jirix *jiri.X, test binDirTest) (e error) {
oldDir, newDir := filepath.Join(jirix.Root, "devtools", "bin"), jirix.BinDir()
// The new bin dir always exists.
if err := os.MkdirAll(newDir, 0777); err != nil {
return fmt.Errorf("make new dir failed: %v", err)
}
if err := test.Setup(oldDir, newDir); err != nil {
return fmt.Errorf("setup failed: %v", err)
}
if test.Teardown != nil {
defer func() {
if err := test.Teardown(oldDir, newDir); err != nil && e == nil {
e = fmt.Errorf("teardown failed: %v", err)
}
}()
}
oldInfo, _ := os.Stat(oldDir)
switch err := project.TransitionBinDir(jirix); {
case err != nil && test.Error == "":
return fmt.Errorf("got error %q, want success", err)
case err != nil && !strings.Contains(fmt.Sprint(err), test.Error):
return fmt.Errorf("got error %q, want prefix %q", err, test.Error)
case err == nil && test.Error != "":
return fmt.Errorf("got no error, want %q", test.Error)
case err == nil && test.Error == "":
// Make sure the symlink exists and is correctly linked.
link, err := os.Readlink(oldDir)
if err != nil {
return fmt.Errorf("old dir isn't a symlink: %v", err)
}
if got, want := link, newDir; got != want {
return fmt.Errorf("old dir symlink got %v, want %v", got, want)
}
if test.CheckBackup {
// Make sure the oldDir was backed up correctly.
backupDir := filepath.Join(jirix.RootMetaDir(), "bin.BACKUP")
backupInfo, err := os.Stat(backupDir)
if err != nil {
return fmt.Errorf("stat backup dir failed: %v", err)
}
if !os.SameFile(oldInfo, backupInfo) {
return fmt.Errorf("old dir wasn't backed up correctly")
}
}
}
return nil
}