本文整理汇总了Golang中launchpad/net/gocheck.C.MkDir方法的典型用法代码示例。如果您正苦于以下问题:Golang C.MkDir方法的具体用法?Golang C.MkDir怎么用?Golang C.MkDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类launchpad/net/gocheck.C
的用法示例。
在下文中一共展示了C.MkDir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestMakeJournalDirs
func (s *MongoSuite) TestMakeJournalDirs(c *gc.C) {
dir := c.MkDir()
err := mongo.MakeJournalDirs(dir)
c.Assert(err, gc.IsNil)
testJournalDirs(dir, c)
}
示例2: extBundleDirPath
func extBundleDirPath(c *gc.C, dirpath string) string {
path := filepath.Join(c.MkDir(), "bundle.charm")
cmd := exec.Command("/bin/sh", "-c", fmt.Sprintf("cd %s; zip --fifo --symlinks -r %s .", dirpath, path))
output, err := cmd.CombinedOutput()
c.Assert(err, gc.IsNil, gc.Commentf("Command output: %s", output))
return path
}
示例3: TestPreallocFilesWriteErrors
func (s *preallocSuite) TestPreallocFilesWriteErrors(c *gc.C) {
dir := c.MkDir()
prefix := filepath.Join(dir, "test.")
err := ioutil.WriteFile(prefix+"0", nil, 0644)
c.Assert(err, gc.IsNil)
err = ioutil.WriteFile(prefix+"1", nil, 0644)
c.Assert(err, gc.IsNil)
var called int
s.PatchValue(mongo.PreallocFile, func(filename string, size int) (bool, error) {
var created bool
var err error
called++
if called == 2 {
created = true
err = fmt.Errorf("failed to zero test.1")
}
return created, err
})
err = mongo.PreallocFiles(prefix, 4096, 8192)
c.Assert(err, gc.ErrorMatches, "failed to zero test.1")
// test.0 still exists because we said we didn't
// create it (i.e. it already existed)
_, err = os.Stat(prefix + "0")
c.Assert(err, gc.IsNil)
// test.1 no longer exists because we said we created
// it, but then failed to write to it.
_, err = os.Stat(prefix + "1")
c.Assert(err, jc.Satisfies, os.IsNotExist)
}
示例4: SetUpTest
func (s *ValidateImageMetadataSuite) SetUpTest(c *gc.C) {
s.FakeJujuHomeSuite.SetUpTest(c)
s.metadataDir = c.MkDir()
coretesting.WriteEnvironments(c, metadataTestEnvConfig)
s.PatchEnvironment("AWS_ACCESS_KEY_ID", "access")
s.PatchEnvironment("AWS_SECRET_ACCESS_KEY", "secret")
}
示例5: TestDumpFileOnErrorScript
func (*scriptSuite) TestDumpFileOnErrorScript(c *gc.C) {
tempdir := c.MkDir()
filename := filepath.Join(tempdir, "log.txt")
err := ioutil.WriteFile(filename, []byte("abc"), 0644)
c.Assert(err, gc.IsNil)
dumpScript := shell.DumpFileOnErrorScript(filename)
c.Logf("%s", dumpScript)
run := func(command string) (stdout, stderr string) {
var stdoutBuf, stderrBuf bytes.Buffer
cmd := exec.Command("/bin/bash", "-s")
cmd.Stdin = strings.NewReader(dumpScript + command)
cmd.Stdout = &stdoutBuf
cmd.Stderr = &stderrBuf
cmd.Run()
return stdoutBuf.String(), stderrBuf.String()
}
stdout, stderr := run("exit 0")
c.Assert(stdout, gc.Equals, "")
c.Assert(stderr, gc.Equals, "")
stdout, stderr = run("exit 1")
c.Assert(stdout, gc.Equals, "")
c.Assert(stderr, gc.Equals, "abc")
err = os.Remove(filename)
c.Assert(err, gc.IsNil)
stdout, stderr = run("exit 1")
c.Assert(stdout, gc.Equals, "")
c.Assert(stderr, gc.Equals, "")
}
示例6: TestUnknownPushLocation
func (s *PublishSuite) TestUnknownPushLocation(c *gc.C) {
addMeta(c, s.branch, "")
err := s.branch.Push(&bzr.PushAttr{Location: c.MkDir() + "/foo", Remember: true})
c.Assert(err, gc.IsNil)
_, err = s.runPublish(c)
c.Assert(err, gc.ErrorMatches, `cannot infer charm URL from branch location: ".*/foo"`)
}
示例7: TestBadCommandName
func (s *ServerSuite) TestBadCommandName(c *gc.C) {
dir := c.MkDir()
_, err := s.Call(c, jujuc.Request{"validCtx", dir, "", nil})
c.Assert(err, gc.ErrorMatches, "bad request: command not specified")
_, err = s.Call(c, jujuc.Request{"validCtx", dir, "witchcraft", nil})
c.Assert(err, gc.ErrorMatches, `bad request: unknown command "witchcraft"`)
}
示例8: TestResolveMetadata
func (*metadataHelperSuite) TestResolveMetadata(c *gc.C) {
var versionStrings = []string{"1.2.3-precise-amd64"}
dir := c.MkDir()
ttesting.MakeTools(c, dir, "releases", versionStrings)
toolsList := coretools.List{{
Version: version.MustParseBinary(versionStrings[0]),
Size: 123,
SHA256: "abc",
}}
stor, err := filestorage.NewFileStorageReader(dir)
c.Assert(err, gc.IsNil)
err = tools.ResolveMetadata(stor, nil)
c.Assert(err, gc.IsNil)
// We already have size/sha256, so ensure that storage isn't consulted.
countingStorage := &countingStorage{StorageReader: stor}
metadata := tools.MetadataFromTools(toolsList)
err = tools.ResolveMetadata(countingStorage, metadata)
c.Assert(err, gc.IsNil)
c.Assert(countingStorage.counter, gc.Equals, 0)
// Now clear size/sha256, and check that it is called, and
// the size/sha256 sum are updated.
metadata[0].Size = 0
metadata[0].SHA256 = ""
err = tools.ResolveMetadata(countingStorage, metadata)
c.Assert(err, gc.IsNil)
c.Assert(countingStorage.counter, gc.Equals, 1)
c.Assert(metadata[0].Size, gc.Not(gc.Equals), 0)
c.Assert(metadata[0].SHA256, gc.Not(gc.Equals), "")
}
示例9: TestReadWriteMetadata
func (*metadataHelperSuite) TestReadWriteMetadata(c *gc.C) {
metadata := []*tools.ToolsMetadata{{
Release: "precise",
Version: "1.2.3",
Arch: "amd64",
Path: "path1",
}, {
Release: "raring",
Version: "1.2.3",
Arch: "amd64",
Path: "path2",
}}
stor, err := filestorage.NewFileStorageWriter(c.MkDir())
c.Assert(err, gc.IsNil)
out, err := tools.ReadMetadata(stor)
c.Assert(out, gc.HasLen, 0)
c.Assert(err, gc.IsNil) // non-existence is not an error
err = tools.WriteMetadata(stor, metadata, tools.DoNotWriteMirrors)
c.Assert(err, gc.IsNil)
out, err = tools.ReadMetadata(stor)
for _, md := range out {
// FullPath is set by ReadMetadata.
c.Assert(md.FullPath, gc.Not(gc.Equals), "")
md.FullPath = ""
}
c.Assert(out, gc.DeepEquals, metadata)
}
示例10: assertWriteMetadata
func (s *simplestreamsSuite) assertWriteMetadata(c *gc.C, withMirrors bool) {
var versionStrings = []string{
"1.2.3-precise-amd64",
"2.0.1-raring-amd64",
}
dir := c.MkDir()
ttesting.MakeTools(c, dir, "releases", versionStrings)
toolsList := coretools.List{
{
// If sha256/size is already known, do not recalculate
Version: version.MustParseBinary("1.2.3-precise-amd64"),
Size: 123,
SHA256: "abcd",
}, {
Version: version.MustParseBinary("2.0.1-raring-amd64"),
// The URL is not used for generating metadata.
URL: "bogus://",
},
}
writer, err := filestorage.NewFileStorageWriter(dir)
c.Assert(err, gc.IsNil)
writeMirrors := tools.DoNotWriteMirrors
if withMirrors {
writeMirrors = tools.WriteMirrors
}
err = tools.MergeAndWriteMetadata(writer, toolsList, writeMirrors)
c.Assert(err, gc.IsNil)
metadata := ttesting.ParseMetadataFromDir(c, dir, withMirrors)
assertMetadataMatches(c, dir, toolsList, metadata)
}
示例11: TestWriteMetadataMergeWithExisting
func (s *simplestreamsSuite) TestWriteMetadataMergeWithExisting(c *gc.C) {
dir := c.MkDir()
existingToolsList := coretools.List{
{
Version: version.MustParseBinary("1.2.3-precise-amd64"),
Size: 123,
SHA256: "abc",
}, {
Version: version.MustParseBinary("2.0.1-raring-amd64"),
Size: 456,
SHA256: "xyz",
},
}
writer, err := filestorage.NewFileStorageWriter(dir)
c.Assert(err, gc.IsNil)
err = tools.MergeAndWriteMetadata(writer, existingToolsList, tools.DoNotWriteMirrors)
c.Assert(err, gc.IsNil)
newToolsList := coretools.List{
existingToolsList[0],
{
Version: version.MustParseBinary("2.1.0-raring-amd64"),
Size: 789,
SHA256: "def",
},
}
err = tools.MergeAndWriteMetadata(writer, newToolsList, tools.DoNotWriteMirrors)
c.Assert(err, gc.IsNil)
requiredToolsList := append(existingToolsList, newToolsList[1])
metadata := ttesting.ParseMetadataFromDir(c, dir, false)
assertMetadataMatches(c, dir, requiredToolsList, metadata)
}
示例12: SetUpTest
func (s *ManifestDeployerSuite) SetUpTest(c *gc.C) {
s.BaseSuite.SetUpTest(c)
s.bundles = &bundleReader{}
s.targetPath = filepath.Join(c.MkDir(), "target")
deployerPath := filepath.Join(c.MkDir(), "deployer")
s.deployer = charm.NewManifestDeployer(s.targetPath, deployerPath, s.bundles)
}
示例13: mockShellCommand
// mockShellCommand creates a new command with the given
// name and contents, and patches $PATH so that it will be
// executed by preference. It returns the name of a file
// that is written by each call to the command - mockShellCalls
// can be used to retrieve the calls.
func mockShellCommand(c *gc.C, s *testing.CleanupSuite, name string) string {
dir := c.MkDir()
s.PatchEnvPathPrepend(dir)
// Note the shell script produces output of the form:
// +arg1+\n
// +arg2+\n
// ...
// +argn+\n
// -
//
// It would be nice if there was a simple way of unambiguously
// quoting shell arguments, but this will do as long
// as no argument contains a newline character.
outputFile := filepath.Join(dir, name+".out")
contents := `#!/bin/sh
{
for i in "[email protected]"; do
echo +"$i"+
done
echo -
} >> ` + utils.ShQuote(outputFile) + `
`
err := ioutil.WriteFile(filepath.Join(dir, name), []byte(contents), 0755)
c.Assert(err, gc.IsNil)
return outputFile
}
示例14: TestUpstartServiceIPv6
func (s *MongoSuite) TestUpstartServiceIPv6(c *gc.C) {
dataDir := c.MkDir()
svc, err := mongo.UpstartService("", dataDir, dataDir, mongo.JujuMongodPath, 1234, 1024)
c.Assert(err, gc.IsNil)
c.Assert(strings.Contains(svc.Conf.Cmd, "--ipv6"), jc.IsTrue)
}
示例15: SetUpTest
func (b *buildSuite) SetUpTest(c *gc.C) {
b.BaseSuite.SetUpTest(c)
dir1 := c.MkDir()
dir2 := c.MkDir()
c.Log(dir1)
c.Log(dir2)
path := os.Getenv("PATH")
os.Setenv("PATH", fmt.Sprintf("%s:%s:%s", dir1, dir2, path))
// Make an executable file called "juju-test" in dir2.
b.filePath = filepath.Join(dir2, "juju-test")
err := ioutil.WriteFile(
b.filePath,
[]byte("doesn't matter, we don't execute it"),
0755)
c.Assert(err, gc.IsNil)
cwd, err := os.Getwd()
c.Assert(err, gc.IsNil)
b.cwd = c.MkDir()
err = os.Chdir(b.cwd)
c.Assert(err, gc.IsNil)
b.restore = func() {
os.Setenv("PATH", path)
os.Chdir(cwd)
}
}