本文整理汇总了Golang中gopkg/in/check/v1.C.MkDir方法的典型用法代码示例。如果您正苦于以下问题:Golang C.MkDir方法的具体用法?Golang C.MkDir怎么用?Golang C.MkDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gopkg/in/check/v1.C
的用法示例。
在下文中一共展示了C.MkDir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestResolveMetadata
func (*metadataHelperSuite) TestResolveMetadata(c *gc.C) {
var versionStrings = []string{"1.2.3-precise-amd64"}
dir := c.MkDir()
toolstesting.MakeTools(c, dir, "released", versionStrings)
toolsList := coretools.List{{
Version: version.MustParseBinary(versionStrings[0]),
Size: 123,
SHA256: "abc",
}}
stor, err := filestorage.NewFileStorageReader(dir)
c.Assert(err, jc.ErrorIsNil)
err = tools.ResolveMetadata(stor, "released", nil)
c.Assert(err, jc.ErrorIsNil)
// We already have size/sha256, so ensure that storage isn't consulted.
countingStorage := &countingStorage{StorageReader: stor}
metadata := tools.MetadataFromTools(toolsList, "released")
err = tools.ResolveMetadata(countingStorage, "released", metadata)
c.Assert(err, jc.ErrorIsNil)
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, "released", metadata)
c.Assert(err, jc.ErrorIsNil)
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), "")
}
示例2: TestOther
func (s *PathsSuite) TestOther(c *gc.C) {
s.PatchValue(&os.HostOS, func() os.OSType { return os.Unknown })
dataDir := c.MkDir()
unitTag := names.NewUnitTag("some-service/323")
paths := uniter.NewPaths(dataDir, unitTag)
relData := relPathFunc(dataDir)
relAgent := relPathFunc(relData("agents", "unit-some-service-323"))
c.Assert(paths, jc.DeepEquals, uniter.Paths{
ToolsDir: relData("tools/unit-some-service-323"),
Runtime: uniter.RuntimePaths{
JujuRunSocket: relAgent("run.socket"),
JujucServerSocket: "@" + relAgent("agent.socket"),
},
State: uniter.StatePaths{
BaseDir: relAgent(),
CharmDir: relAgent("charm"),
OperationsFile: relAgent("state", "uniter"),
RelationsDir: relAgent("state", "relations"),
BundlesDir: relAgent("state", "bundles"),
DeployerDir: relAgent("state", "deployer"),
StorageDir: relAgent("state", "storage"),
MetricsSpoolDir: relAgent("state", "spool", "metrics"),
},
})
}
示例3: TestGetReturnsFileContents
func (s *charmsSuite) TestGetReturnsFileContents(c *gc.C) {
// Add the dummy charm.
ch := testcharms.Repo.CharmArchive(c.MkDir(), "dummy")
_, err := s.uploadRequest(
c, s.charmsURI(c, "?series=quantal"), true, ch.Path)
c.Assert(err, jc.ErrorIsNil)
// Ensure the file contents are properly returned.
for i, t := range []struct {
summary string
file string
response string
}{{
summary: "relative path",
file: "revision",
response: "1",
}, {
summary: "exotic path",
file: "./hooks/../revision",
response: "1",
}, {
summary: "sub-directory path",
file: "hooks/install",
response: "#!/bin/bash\necho \"Done!\"\n",
},
} {
c.Logf("test %d: %s", i, t.summary)
uri := s.charmsURI(c, "?url=local:quantal/dummy-1&file="+t.file)
resp, err := s.authRequest(c, "GET", uri, "", nil)
c.Assert(err, jc.ErrorIsNil)
s.assertGetFileResponse(c, resp, t.response, "text/plain; charset=utf-8")
}
}
示例4: TestReplace
func (*SymlinkSuite) TestReplace(c *gc.C) {
target, err := symlink.GetLongPathAsString(c.MkDir())
c.Assert(err, gc.IsNil)
target_second, err := symlink.GetLongPathAsString(c.MkDir())
c.Assert(err, gc.IsNil)
link := filepath.Join(target, "link")
_, err = os.Stat(target)
c.Assert(err, gc.IsNil)
_, err = os.Stat(target_second)
c.Assert(err, gc.IsNil)
err = symlink.New(target, link)
c.Assert(err, gc.IsNil)
link_target, err := symlink.Read(link)
c.Assert(err, gc.IsNil)
c.Assert(link_target, gc.Equals, filepath.FromSlash(target))
err = symlink.Replace(link, target_second)
c.Assert(err, gc.IsNil)
link_target, err = symlink.Read(link)
c.Assert(err, gc.IsNil)
c.Assert(link_target, gc.Equals, filepath.FromSlash(target_second))
}
示例5: SetUpTest
func (s *ToolsMetadataSuite) SetUpTest(c *gc.C) {
s.FakeJujuXDGDataHomeSuite.SetUpTest(c)
s.AddCleanup(dummy.Reset)
cfg, err := config.New(config.UseDefaults, map[string]interface{}{
"name": "erewhemos",
"type": "dummy",
"uuid": coretesting.ModelTag.Id(),
"controller-uuid": coretesting.ControllerTag.Id(),
"conroller": true,
})
c.Assert(err, jc.ErrorIsNil)
env, err := bootstrap.Prepare(
modelcmd.BootstrapContextNoVerify(coretesting.Context(c)),
jujuclienttesting.NewMemStore(),
bootstrap.PrepareParams{
ControllerConfig: coretesting.FakeControllerConfig(),
ControllerName: cfg.Name(),
ModelConfig: cfg.AllAttrs(),
Cloud: dummy.SampleCloudSpec(),
AdminSecret: "admin-secret",
},
)
c.Assert(err, jc.ErrorIsNil)
s.env = env
loggo.GetLogger("").SetLogLevel(loggo.INFO)
// Switch the default tools location.
s.publicStorageDir = c.MkDir()
s.PatchValue(&tools.DefaultBaseURL, s.publicStorageDir)
}
示例6: step
func (s createCharm) step(c *gc.C, ctx *context) {
base := testcharms.Repo.ClonedDirPath(c.MkDir(), "wordpress")
allCharmHooks := baseCharmHooks
allCharmHooks = append(allCharmHooks, leaderCharmHooks...)
allCharmHooks = append(allCharmHooks, storageCharmHooks...)
for _, name := range allCharmHooks {
path := filepath.Join(base, "hooks", name)
good := true
for _, bad := range s.badHooks {
if name == bad {
good = false
}
}
ctx.writeHook(c, path, good)
}
if s.customize != nil {
s.customize(c, ctx, base)
}
dir, err := corecharm.ReadCharmDir(base)
c.Assert(err, jc.ErrorIsNil)
err = dir.SetDiskRevision(s.revision)
c.Assert(err, jc.ErrorIsNil)
step(c, ctx, addCharm{dir, curl(s.revision)})
}
示例7: bootstrapEnv
func (s *NewAPIClientSuite) bootstrapEnv(c *gc.C, envName string, store configstore.Storage) {
if store == nil {
store = configstore.NewMem()
}
ctx := envtesting.BootstrapContext(c)
c.Logf("env name: %s", envName)
env, err := environs.PrepareFromName(envName, ctx, store)
c.Assert(err, jc.ErrorIsNil)
storageDir := c.MkDir()
s.PatchValue(&envtools.DefaultBaseURL, storageDir)
stor, err := filestorage.NewFileStorageWriter(storageDir)
c.Assert(err, jc.ErrorIsNil)
envtesting.UploadFakeTools(c, stor, "released", "released")
err = bootstrap.Bootstrap(ctx, env, bootstrap.BootstrapParams{})
c.Assert(err, jc.ErrorIsNil)
info, err := store.ReadInfo(envName)
c.Assert(err, jc.ErrorIsNil)
creds := info.APICredentials()
creds.User = dummy.AdminUserTag().Name()
c.Logf("set creds: %#v", creds)
info.SetAPICredentials(creds)
err = info.Write()
c.Assert(err, jc.ErrorIsNil)
c.Logf("creds: %#v", info.APICredentials())
info, err = store.ReadInfo(envName)
c.Assert(err, jc.ErrorIsNil)
c.Logf("read creds: %#v", info.APICredentials())
c.Logf("store: %#v", store)
}
示例8: SetUp
func (fix *SimpleToolsFixture) SetUp(c *gc.C, dataDir string) {
fix.dataDir = dataDir
fix.logDir = c.MkDir()
current := version.Binary{
Number: version.Current,
Arch: arch.HostArch(),
Series: series.HostSeries(),
}
toolsDir := tools.SharedToolsDir(fix.dataDir, current)
err := os.MkdirAll(toolsDir, 0755)
c.Assert(err, jc.ErrorIsNil)
jujudPath := filepath.Join(toolsDir, "jujud")
err = ioutil.WriteFile(jujudPath, []byte(fakeJujud), 0755)
c.Assert(err, jc.ErrorIsNil)
toolsPath := filepath.Join(toolsDir, "downloaded-tools.txt")
testTools := coretools.Tools{Version: current, URL: "http://testing.invalid/tools"}
data, err := json.Marshal(testTools)
c.Assert(err, jc.ErrorIsNil)
err = ioutil.WriteFile(toolsPath, data, 0644)
c.Assert(err, jc.ErrorIsNil)
fix.binDir = c.MkDir()
fix.origPath = os.Getenv("PATH")
os.Setenv("PATH", fix.binDir+":"+fix.origPath)
fix.makeBin(c, "status", `echo "blah stop/waiting"`)
fix.makeBin(c, "stopped-status", `echo "blah stop/waiting"`)
fix.makeBin(c, "started-status", `echo "blah start/running, process 666"`)
fix.makeBin(c, "start", "cp $(which started-status) $(which status)")
fix.makeBin(c, "stop", "cp $(which stopped-status) $(which status)")
fix.data = svctesting.NewFakeServiceData()
}
示例9: SetUpTest
func (s *CharmSuite) SetUpTest(c *gc.C) {
s.Server = charmstoretesting.OpenServer(c, s.jcSuite.Session, charmstore.ServerParams{
AuthUsername: "test-user",
AuthPassword: "test-password",
})
urls := []string{
"~who/quantal/mysql-23",
"~who/quantal/dummy-24",
"~who/quantal/riak-25",
"~who/quantal/wordpress-26",
"~who/quantal/logging-27",
}
for _, url := range urls {
id := charm.MustParseReference(url)
ch := testcharms.Repo.CharmArchive(c.MkDir(), id.Name)
s.Server.UploadCharm(c, ch, id, true)
}
s.jcSuite.PatchValue(&charmrepo.CacheDir, c.MkDir())
// Patch the charm repo initializer function: it is replaced with a charm
// store repo pointing to the testing server.
s.jcSuite.PatchValue(&charmrevisionupdater.NewCharmStore, func(p charmrepo.NewCharmStoreParams) charmrepo.Interface {
p.URL = s.Server.URL()
return charmrepo.NewCharmStore(p)
})
s.charms = make(map[string]*state.Charm)
}
示例10: setUpEnvAndTools
func (s *UpgradeJujuSuite) setUpEnvAndTools(c *gc.C, currentVersion string, agentVersion string, tools []string) {
current := version.MustParseBinary(currentVersion)
s.PatchValue(&jujuversion.Current, current.Number)
s.PatchValue(&arch.HostArch, func() string { return current.Arch })
s.PatchValue(&series.HostSeries, func() string { return current.Series })
toolsDir := c.MkDir()
updateAttrs := map[string]interface{}{
"agent-version": agentVersion,
"agent-metadata-url": "file://" + toolsDir + "/tools",
}
err := s.State.UpdateModelConfig(updateAttrs, nil, nil)
c.Assert(err, jc.ErrorIsNil)
versions := make([]version.Binary, len(tools))
for i, v := range tools {
versions[i], err = version.ParseBinary(v)
if err != nil {
c.Assert(err, jc.Satisfies, series.IsUnknownOSForSeriesError)
}
}
if len(versions) > 0 {
stor, err := filestorage.NewFileStorageWriter(toolsDir)
c.Assert(err, jc.ErrorIsNil)
envtesting.MustUploadFakeToolsVersions(stor, s.Environ.Config().AgentStream(), versions...)
}
}
示例11: TestControllerLoginCommand
func (s *cmdControllerSuite) TestControllerLoginCommand(c *gc.C) {
user := s.Factory.MakeUser(c, &factory.UserParams{
NoEnvUser: true,
Password: "super-secret",
})
apiInfo := s.APIInfo(c)
serverFile := envcmd.ServerFile{
Addresses: apiInfo.Addrs,
CACert: apiInfo.CACert,
Username: user.Name(),
Password: "super-secret",
}
serverFilePath := filepath.Join(c.MkDir(), "server.yaml")
content, err := goyaml.Marshal(serverFile)
c.Assert(err, jc.ErrorIsNil)
err = ioutil.WriteFile(serverFilePath, []byte(content), 0644)
c.Assert(err, jc.ErrorIsNil)
s.run(c, "login", "--server", serverFilePath, "just-a-controller")
// Make sure that the saved server details are sufficient to connect
// to the api server.
api, err := juju.NewAPIFromName("just-a-controller", nil)
c.Assert(err, jc.ErrorIsNil)
api.Close()
}
示例12: TestReadWriteMetadataUnchanged
func (s *metadataHelperSuite) TestReadWriteMetadataUnchanged(c *gc.C) {
metadata := map[string][]*tools.ToolsMetadata{
"released": {{
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, jc.ErrorIsNil)
err = tools.WriteMetadata(stor, metadata, []string{"released"}, tools.DoNotWriteMirrors)
c.Assert(err, jc.ErrorIsNil)
s.PatchValue(tools.WriteMetadataFiles, func(stor storage.Storage, metadataInfo []tools.MetadataFile) error {
// The product data is the same, we only write the indices.
c.Assert(metadataInfo, gc.HasLen, 2)
c.Assert(metadataInfo[0].Path, gc.Equals, "streams/v1/index2.json")
c.Assert(metadataInfo[1].Path, gc.Equals, "streams/v1/index.json")
return nil
})
err = tools.WriteMetadata(stor, metadata, []string{"released"}, tools.DoNotWriteMirrors)
c.Assert(err, jc.ErrorIsNil)
}
示例13: writeMetadataMultipleStream
func (*metadataHelperSuite) writeMetadataMultipleStream(c *gc.C) (storage.StorageReader, map[string][]*tools.ToolsMetadata) {
metadata := map[string][]*tools.ToolsMetadata{
"released": {{
Release: "precise",
Version: "1.2.3",
Arch: "amd64",
Path: "path1",
}},
"proposed": {{
Release: "raring",
Version: "1.2.3",
Arch: "amd64",
Path: "path2",
}},
}
stor, err := filestorage.NewFileStorageWriter(c.MkDir())
c.Assert(err, jc.ErrorIsNil)
out, err := tools.ReadAllMetadata(stor)
c.Assert(out, gc.HasLen, 0)
c.Assert(err, jc.ErrorIsNil) // non-existence is not an error
err = tools.WriteMetadata(stor, metadata, []string{"released", "proposed"}, tools.DoNotWriteMirrors)
c.Assert(err, jc.ErrorIsNil)
return stor, metadata
}
示例14: TestReadWriteMetadataSingleStream
func (*metadataHelperSuite) TestReadWriteMetadataSingleStream(c *gc.C) {
metadata := map[string][]*tools.ToolsMetadata{
"released": {{
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, jc.ErrorIsNil)
out, err := tools.ReadAllMetadata(stor)
c.Assert(err, jc.ErrorIsNil) // non-existence is not an error
c.Assert(out, gc.HasLen, 0)
err = tools.WriteMetadata(stor, metadata, []string{"released"}, tools.DoNotWriteMirrors)
c.Assert(err, jc.ErrorIsNil)
// Read back what was just written.
out, err = tools.ReadAllMetadata(stor)
c.Assert(err, jc.ErrorIsNil)
for _, outMetadata := range out {
for _, md := range outMetadata {
// FullPath is set by ReadAllMetadata.
c.Assert(md.FullPath, gc.Not(gc.Equals), "")
md.FullPath = ""
}
}
c.Assert(out, jc.DeepEquals, metadata)
}
示例15: TestUploadBumpsRevision
func (s *charmsSuite) TestUploadBumpsRevision(c *gc.C) {
// Add the dummy charm with revision 1.
ch := testcharms.Repo.CharmArchive(c.MkDir(), "dummy")
curl := charm.MustParseURL(
fmt.Sprintf("local:quantal/%s-%d", ch.Meta().Name, ch.Revision()),
)
info := state.CharmInfo{
Charm: ch,
ID: curl,
StoragePath: "dummy-storage-path",
SHA256: "dummy-1-sha256",
}
_, err := s.State.AddCharm(info)
c.Assert(err, jc.ErrorIsNil)
// Now try uploading the same revision and verify it gets bumped,
// and the BundleSha256 is calculated.
resp := s.uploadRequest(c, s.charmsURI(c, "?series=quantal"), "application/zip", ch.Path)
expectedURL := charm.MustParseURL("local:quantal/dummy-2")
s.assertUploadResponse(c, resp, expectedURL.String())
sch, err := s.State.Charm(expectedURL)
c.Assert(err, jc.ErrorIsNil)
c.Assert(sch.URL(), gc.DeepEquals, expectedURL)
c.Assert(sch.Revision(), gc.Equals, 2)
c.Assert(sch.IsUploaded(), jc.IsTrue)
// No more checks for the hash here, because it is
// verified in TestUploadRespectsLocalRevision.
c.Assert(sch.BundleSha256(), gc.Not(gc.Equals), "")
}