本文整理汇总了Golang中github.com/pachyderm/pachyderm/src/client/pkg/require.NoError函数的典型用法代码示例。如果您正苦于以下问题:Golang NoError函数的具体用法?Golang NoError怎么用?Golang NoError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NoError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestMountCachingViaShell
func TestMountCachingViaShell(t *testing.T) {
if testing.Short() {
t.Skip("Skipped because of short mode")
}
testFuse(t, func(c client.APIClient, mountpoint string) {
repo1 := "foo"
require.NoError(t, c.CreateRepo(repo1))
// Now if we walk the FS we should see the file.
// This first act of 'walking' should also initiate the cache
ls := exec.Command("ls")
ls.Dir = mountpoint
out, err := ls.Output()
require.NoError(t, err)
require.Equal(t, "foo\n", string(out))
// Now create another repo, and look for it under the mount point
repo2 := "bar"
require.NoError(t, c.CreateRepo(repo2))
// Now if we walk the FS we should see the new file.
// This second ls on mac doesn't report the file!
ls = exec.Command("ls")
ls.Dir = mountpoint
out, err = ls.Output()
require.NoError(t, err)
require.Equal(t, true, "foo\nbar\n" == string(out) || "bar\nfoo\n" == string(out))
})
}
示例2: testBlock
func testBlock(t *testing.T, apiServer persist.APIServer) {
jobInfo, err := apiServer.CreateJobInfo(context.Background(), &persist.JobInfo{
JobID: uuid.NewWithoutDashes(),
})
require.NoError(t, err)
jobID := jobInfo.JobID
go func() {
_, err := apiServer.CreateJobOutput(
context.Background(),
&persist.JobOutput{
JobID: jobID,
OutputCommit: client.NewCommit("foo", "bar"),
})
require.NoError(t, err)
_, err = apiServer.CreateJobState(
context.Background(),
&persist.JobState{
JobID: jobID,
State: ppsclient.JobState_JOB_SUCCESS,
})
require.NoError(t, err)
}()
_, err = apiServer.InspectJob(
context.Background(),
&ppsclient.InspectJobRequest{
Job: &ppsclient.Job{ID: jobID},
BlockState: true,
},
)
require.NoError(t, err)
}
示例3: TestCommitOpenReadDir
func TestCommitOpenReadDir(t *testing.T) {
if testing.Short() {
t.Skip("Skipped because of short mode")
}
testFuse(t, func(c client.APIClient, mountpoint string) {
repoName := "foo"
require.NoError(t, c.CreateRepo(repoName))
commit, err := c.StartCommit(repoName, "", "")
require.NoError(t, err)
t.Logf("open commit %v", commit.ID)
const (
greetingName = "greeting"
greeting = "Hello, world\n"
greetingPerm = 0644
)
require.NoError(t, ioutil.WriteFile(filepath.Join(mountpoint, repoName, commit.ID, greetingName), []byte(greeting), greetingPerm))
const (
scriptName = "script"
script = "#!/bin/sh\necho foo\n"
scriptPerm = 0750
)
require.NoError(t, ioutil.WriteFile(filepath.Join(mountpoint, repoName, commit.ID, scriptName), []byte(script), scriptPerm))
require.NoError(t, fstestutil.CheckDir(filepath.Join(mountpoint, repoName, commit.ID), map[string]fstestutil.FileInfoCheck{
greetingName: func(fi os.FileInfo) error {
// TODO respect greetingPerm
if g, e := fi.Mode(), os.FileMode(0666); g != e {
return fmt.Errorf("wrong mode: %v != %v", g, e)
}
if g, e := fi.Size(), int64(len(greeting)); g != e {
t.Errorf("wrong size: %v != %v", g, e)
}
// TODO show fileModTime as mtime
// if g, e := fi.ModTime().UTC(), fileModTime; g != e {
// t.Errorf("wrong mtime: %v != %v", g, e)
// }
return nil
},
scriptName: func(fi os.FileInfo) error {
// TODO respect scriptPerm
if g, e := fi.Mode(), os.FileMode(0666); g != e {
return fmt.Errorf("wrong mode: %v != %v", g, e)
}
if g, e := fi.Size(), int64(len(script)); g != e {
t.Errorf("wrong size: %v != %v", g, e)
}
// TODO show fileModTime as mtime
// if g, e := fi.ModTime().UTC(), fileModTime; g != e {
// t.Errorf("wrong mtime: %v != %v", g, e)
// }
return nil
},
}))
})
}
示例4: TestSeekRead
func TestSeekRead(t *testing.T) {
if testing.Short() {
t.Skip("Skipped because of short mode")
}
testFuse(t, func(c client.APIClient, mountpoint string) {
repo := "test"
require.NoError(t, c.CreateRepo(repo))
commit, err := c.StartCommit(repo, "", "")
require.NoError(t, err)
path := filepath.Join(mountpoint, repo, commit.ID, "file")
file, err := os.Create(path)
require.NoError(t, err)
_, err = file.Write([]byte("foobarbaz"))
require.NoError(t, err)
require.NoError(t, file.Close())
require.NoError(t, c.FinishCommit(repo, commit.ID))
fmt.Printf("==== Finished commit\n")
file, err = os.Open(path)
defer file.Close()
require.NoError(t, err)
word1 := make([]byte, 3)
n1, err := file.Read(word1)
require.NoError(t, err)
require.Equal(t, 3, n1)
require.Equal(t, "foo", string(word1))
fmt.Printf("==== %v - Read word len %v : %v\n", time.Now(), n1, string(word1))
offset, err := file.Seek(6, 0)
fmt.Printf("==== %v - err (%v)\n", time.Now(), err)
fmt.Printf("==== %v - offset (%v)\n", time.Now(), offset)
// MAC OS X BEHAVIOR - it allows seek
require.NoError(t, err)
require.Equal(t, int64(6), offset)
fmt.Printf("==== Seeked to %v\n", offset)
/* Leaving in place so the test's intention is clear / for repro'ing manually for mac */
word2 := make([]byte, 3)
n2, err := file.Read(word2)
require.NoError(t, err)
require.Equal(t, 3, n2)
require.Equal(t, "baz", string(word2))
fmt.Printf("==== Read word len %v : %v\n", n2, string(word2))
})
}
示例5: Test296
func Test296(t *testing.T) {
lion.SetLevel(lion.LevelDebug)
if testing.Short() {
t.Skip("Skipped because of short mode")
}
testFuse(t, func(c client.APIClient, mountpoint string) {
repo := "test"
require.NoError(t, c.CreateRepo(repo))
commit, err := c.StartCommit(repo, "", "")
require.NoError(t, err)
path := filepath.Join(mountpoint, repo, commit.ID, "file")
stdin := strings.NewReader(fmt.Sprintf("echo 1 >%s", path))
require.NoError(t, pkgexec.RunStdin(stdin, "sh"))
stdin = strings.NewReader(fmt.Sprintf("echo 2 >%s", path))
require.NoError(t, pkgexec.RunStdin(stdin, "sh"))
require.NoError(t, c.FinishCommit(repo, commit.ID))
commit2, err := c.StartCommit(repo, commit.ID, "")
require.NoError(t, err)
path = filepath.Join(mountpoint, repo, commit2.ID, "file")
stdin = strings.NewReader(fmt.Sprintf("echo 3 >%s", path))
require.NoError(t, pkgexec.RunStdin(stdin, "sh"))
require.NoError(t, c.FinishCommit(repo, commit2.ID))
data, err := ioutil.ReadFile(path)
require.NoError(t, err)
require.Equal(t, "3\n", string(data))
})
}
示例6: TestOpenAndWriteFile
func TestOpenAndWriteFile(t *testing.T) {
if testing.Short() {
t.Skip("Skipped because of short mode")
}
testFuse(t, func(c client.APIClient, mountpoint string) {
require.NoError(t, c.CreateRepo("repo"))
commit1, err := c.StartCommit("repo", "", "")
require.NoError(t, err)
filePath := filepath.Join(mountpoint, "repo", commit1.ID, "foo")
f, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
require.NoError(t, err)
defer func() {
err = f.Close()
require.NoError(t, err)
}()
data1 := []byte("something\nis\nrotten\n")
_, err = f.Write(data1)
require.NoError(t, err)
data2 := []byte("in\nthe\nstate\nof\nDenmark\n")
_, err = f.Write(data2)
require.NoError(t, err)
require.NoError(t, f.Sync())
require.NoError(t, c.FinishCommit("repo", commit1.ID))
result, err := ioutil.ReadFile(filePath)
require.NoError(t, err)
require.Equal(t, fmt.Sprintf("%v%v", string(data1), string(data2)), string(result))
})
}
示例7: RunTestWithRethinkAPIServer
func RunTestWithRethinkAPIServer(t *testing.T, testFunc func(t *testing.T, persistAPIServer persist.APIServer)) {
if testing.Short() {
t.Skip("Skipping test because of short mode.")
}
apiServer, err := NewTestRethinkAPIServer()
require.NoError(t, err)
defer func() {
require.NoError(t, apiServer.Close())
}()
testFunc(t, apiServer)
}
示例8: TestRepoReadDir
func TestRepoReadDir(t *testing.T) {
if testing.Short() {
t.Skip("Skipped because of short mode")
}
testFuse(t, func(c client.APIClient, mountpoint string) {
repoName := "foo"
require.NoError(t, c.CreateRepo(repoName))
commitA, err := c.StartCommit(repoName, "", "")
require.NoError(t, err)
require.NoError(t, c.FinishCommit(repoName, commitA.ID))
t.Logf("finished commit %v", commitA.ID)
commitB, err := c.StartCommit(repoName, "", "")
require.NoError(t, err)
t.Logf("open commit %v", commitB.ID)
require.NoError(t, fstestutil.CheckDir(filepath.Join(mountpoint, repoName), map[string]fstestutil.FileInfoCheck{
commitA.ID: func(fi os.FileInfo) error {
if g, e := fi.Mode(), os.ModeDir|0555; g != e {
return fmt.Errorf("wrong mode: %v != %v", g, e)
}
// TODO show commitSize in commit stat?
if g, e := fi.Size(), int64(0); g != e {
t.Errorf("wrong size: %v != %v", g, e)
}
// TODO show CommitInfo.StartTime as ctime, CommitInfo.Finished as mtime
// TODO test ctime via .Sys
// if g, e := fi.ModTime().UTC(), commitFinishTime; g != e {
// t.Errorf("wrong mtime: %v != %v", g, e)
// }
return nil
},
commitB.ID: func(fi os.FileInfo) error {
if g, e := fi.Mode(), os.ModeDir|0775; g != e {
return fmt.Errorf("wrong mode: %v != %v", g, e)
}
// TODO show commitSize in commit stat?
if g, e := fi.Size(), int64(0); g != e {
t.Errorf("wrong size: %v != %v", g, e)
}
// TODO show CommitInfo.StartTime as ctime, ??? as mtime
// TODO test ctime via .Sys
// if g, e := fi.ModTime().UTC(), commitFinishTime; g != e {
// t.Errorf("wrong mtime: %v != %v", g, e)
// }
return nil
},
}))
})
}
示例9: TestCreateFileInDir
func TestCreateFileInDir(t *testing.T) {
lion.SetLevel(lion.LevelDebug)
if testing.Short() {
t.Skip("Skipped because of short mode")
}
testFuse(t, func(c client.APIClient, mountpoint string) {
require.NoError(t, c.CreateRepo("repo"))
commit, err := c.StartCommit("repo", "", "")
require.NoError(t, err)
require.NoError(t, os.Mkdir(filepath.Join(mountpoint, "repo", commit.ID, "dir"), 0700))
require.NoError(t, ioutil.WriteFile(filepath.Join(mountpoint, "repo", commit.ID, "dir", "file"), []byte("foo"), 0644))
require.NoError(t, c.FinishCommit("repo", commit.ID))
})
}
示例10: testRun
func testRun(t *testing.T, imageName string, commands []string, expectedStdout string, expectedStderr string) {
if testing.Short() {
t.Skip("Skipping integration tests in short mode")
}
client, err := newTestDockerClient()
require.NoError(t, err)
err = client.Pull(imageName, PullOptions{})
require.NoError(t, err)
container, err := client.Create(
imageName,
CreateOptions{
HasCommand: commands != nil,
},
)
require.NoError(t, err)
err = client.Start(
container,
StartOptions{
Commands: commands,
},
)
require.NoError(t, err)
err = client.Wait(container, WaitOptions{})
require.NoError(t, err)
stdout := bytes.NewBuffer(nil)
stderr := bytes.NewBuffer(nil)
err = client.Logs(container, LogsOptions{Stdout: stdout, Stderr: stderr})
require.NoError(t, err)
require.Equal(t, expectedStdout, stdout.String())
require.Equal(t, expectedStderr, stderr.String())
err = client.Remove(container, RemoveOptions{})
require.NoError(t, err)
}
示例11: TestSeekWriteBackwards
func TestSeekWriteBackwards(t *testing.T) {
if testing.Short() {
t.Skip("Skipped because of short mode")
}
testFuse(t, func(c client.APIClient, mountpoint string) {
repo := "test"
require.NoError(t, c.CreateRepo(repo))
commit, err := c.StartCommit(repo, "", "")
require.NoError(t, err)
path := filepath.Join(mountpoint, repo, commit.ID, "file")
file, err := os.Create(path)
require.NoError(t, err)
defer func() {
// MAC OS X BEHAVIOR - it allows seek but this is an invalid write
require.YesError(t, file.Close())
}()
_, err = file.Write([]byte("foofoofoo"))
require.NoError(t, err)
err = file.Sync()
require.NoError(t, err)
offset, err := file.Seek(3, 0)
fmt.Printf("==== %v - err (%v)\n", time.Now(), err)
fmt.Printf("==== %v - offset (%v)\n", time.Now(), offset)
// MAC OS X BEHAVIOR - it allows seek
require.NoError(t, err)
require.Equal(t, int64(3), offset)
/* Leaving in place so the test's intention is clear / for repro'ing manually for mac */
err = file.Sync()
require.NoError(t, err)
n1, err := file.Write([]byte("bar"))
// MAC OS X BEHAVIOR - it allows seek
require.NoError(t, err)
require.Equal(t, 3, n1)
fmt.Printf("==== %v - write word len %v\n", time.Now(), n1)
require.NoError(t, c.FinishCommit(repo, commit.ID))
})
}
示例12: TestBigWrite
func TestBigWrite(t *testing.T) {
if testing.Short() {
t.Skip("Skipped because of short mode")
}
testFuse(t, func(c client.APIClient, mountpoint string) {
repo := "test"
require.NoError(t, c.CreateRepo(repo))
commit, err := c.StartCommit(repo, "", "")
require.NoError(t, err)
path := filepath.Join(mountpoint, repo, commit.ID, "file1")
stdin := strings.NewReader(fmt.Sprintf("yes | tr -d '\\n' | head -c 1000000 > %s", path))
require.NoError(t, pkgexec.RunStdin(stdin, "sh"))
require.NoError(t, c.FinishCommit(repo, commit.ID))
data, err := ioutil.ReadFile(path)
require.NoError(t, err)
require.Equal(t, bytes.Repeat([]byte{'y'}, 1000000), data)
})
}
示例13: TestEtcdWatch
func TestEtcdWatch(t *testing.T) {
if os.Getenv("ETCD_PORT_2379_TCP_ADDR") == "" {
t.Skip("skipping test; $ETCD_PORT_2379_TCP_ADDR not set")
}
t.Parallel()
client, err := getEtcdClient()
require.NoError(t, err)
runWatchTest(t, client)
}
示例14: TestRootReadDir
func TestRootReadDir(t *testing.T) {
if testing.Short() {
t.Skip("Skipped because of short mode")
}
testFuse(t, func(c client.APIClient, mountpoint string) {
require.NoError(t, c.CreateRepo("one"))
require.NoError(t, c.CreateRepo("two"))
require.NoError(t, fstestutil.CheckDir(mountpoint, map[string]fstestutil.FileInfoCheck{
"one": func(fi os.FileInfo) error {
if g, e := fi.Mode(), os.ModeDir|0555; g != e {
return fmt.Errorf("wrong mode: %v != %v", g, e)
}
// TODO show repoSize in repo stat?
if g, e := fi.Size(), int64(0); g != e {
t.Errorf("wrong size: %v != %v", g, e)
}
// TODO show RepoInfo.Created as time
// if g, e := fi.ModTime().UTC(), repoModTime; g != e {
// t.Errorf("wrong mtime: %v != %v", g, e)
// }
return nil
},
"two": func(fi os.FileInfo) error {
if g, e := fi.Mode(), os.ModeDir|0555; g != e {
return fmt.Errorf("wrong mode: %v != %v", g, e)
}
// TODO show repoSize in repo stat?
if g, e := fi.Size(), int64(0); g != e {
t.Errorf("wrong size: %v != %v", g, e)
}
// TODO show RepoInfo.Created as time
// if g, e := fi.ModTime().UTC(), repoModTime; g != e {
// t.Errorf("wrong mtime: %v != %v", g, e)
// }
return nil
},
}))
})
}
示例15: TestMountCachingViaWalk
func TestMountCachingViaWalk(t *testing.T) {
if testing.Short() {
t.Skip("Skipped because of short mode")
}
testFuse(t, func(c client.APIClient, mountpoint string) {
repo1 := "foo"
require.NoError(t, c.CreateRepo(repo1))
// Now if we walk the FS we should see the file.
// This first act of 'walking' should also initiate the cache
var filesSeen []interface{}
walkCallback := func(path string, info os.FileInfo, err error) error {
tokens := strings.Split(path, "/mnt")
filesSeen = append(filesSeen, tokens[len(tokens)-1])
return nil
}
err := filepath.Walk(mountpoint, walkCallback)
require.NoError(t, err)
require.OneOfEquals(t, "/foo", filesSeen)
// Now create another repo, and look for it under the mount point
repo2 := "bar"
require.NoError(t, c.CreateRepo(repo2))
// Now if we walk the FS we should see the new file.
// This now works. But originally (issue #205) this second ls on mac doesn't report the file!
filesSeen = make([]interface{}, 0)
err = filepath.Walk(mountpoint, walkCallback)
require.NoError(t, err)
require.OneOfEquals(t, "/foo", filesSeen)
require.OneOfEquals(t, "/bar", filesSeen)
})
}