本文整理汇总了Golang中github.com/juju/juju/testing.NewTarFile函数的典型用法代码示例。如果您正苦于以下问题:Golang NewTarFile函数的具体用法?Golang NewTarFile怎么用?Golang NewTarFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewTarFile函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestUploadToolsOtherModel
func (s *clientSuite) TestUploadToolsOtherModel(c *gc.C) {
otherSt, otherAPISt := s.otherModel(c)
defer otherSt.Close()
defer otherAPISt.Close()
client := otherAPISt.Client()
newVersion := version.MustParseBinary("5.4.3-quantal-amd64")
var called bool
// build fake tools
expectedTools, _ := coretesting.TarGz(
coretesting.NewTarFile(jujunames.Jujud, 0777, "jujud contents "+newVersion.String()))
// UploadTools does not use the facades, so instead of patching the
// facade call, we set up a fake endpoint to test.
defer fakeAPIEndpoint(c, client, envEndpoint(c, otherAPISt, "tools"), "POST",
func(w http.ResponseWriter, r *http.Request) {
called = true
c.Assert(r.URL.Query(), gc.DeepEquals, url.Values{
"binaryVersion": []string{"5.4.3-quantal-amd64"},
"series": []string{""},
})
defer r.Body.Close()
obtainedTools, err := ioutil.ReadAll(r.Body)
c.Assert(err, jc.ErrorIsNil)
c.Assert(obtainedTools, gc.DeepEquals, expectedTools)
},
).Close()
// We don't test the error or tools results as we only wish to assert that
// the API client POSTs the tools archive to the correct endpoint.
client.UploadTools(bytes.NewReader(expectedTools), newVersion)
c.Assert(called, jc.IsTrue)
}
示例2: GetMockBuildTools
// GetMockBuildTools returns a sync.BuildAgentTarballFunc implementation which generates
// a fake tools tarball.
func GetMockBuildTools(c *gc.C) sync.BuildAgentTarballFunc {
return func(build bool, forceVersion *version.Number, stream string) (*sync.BuiltAgent, error) {
vers := version.Binary{
Number: jujuversion.Current,
Arch: arch.HostArch(),
Series: series.HostSeries(),
}
if forceVersion != nil {
vers.Number = *forceVersion
}
tgz, checksum := coretesting.TarGz(
coretesting.NewTarFile(names.Jujud, 0777, "jujud contents "+vers.String()))
toolsDir, err := ioutil.TempDir("", "juju-tools-"+stream)
c.Assert(err, jc.ErrorIsNil)
name := "name"
ioutil.WriteFile(filepath.Join(toolsDir, name), tgz, 0777)
return &sync.BuiltAgent{
Dir: toolsDir,
StorageName: name,
Version: vers,
Size: int64(len(tgz)),
Sha256Hash: checksum,
}, nil
}
}
示例3: TestUploadToolsOtherEnvironment
func (s *apiEnvironmentSuite) TestUploadToolsOtherEnvironment(c *gc.C) {
// setup other environment
otherState := s.Factory.MakeModel(c, nil)
defer otherState.Close()
info := s.APIInfo(c)
info.ModelTag = otherState.ModelTag()
otherAPIState, err := api.Open(info, api.DefaultDialOpts())
c.Assert(err, jc.ErrorIsNil)
defer otherAPIState.Close()
otherClient := otherAPIState.Client()
defer otherClient.ClientFacade.Close()
newVersion := version.MustParseBinary("5.4.3-quantal-amd64")
vers := newVersion.String()
// build fake tools
tgz, checksum := coretesting.TarGz(
coretesting.NewTarFile(jujunames.Jujud, 0777, "jujud contents "+vers))
toolsList, err := otherClient.UploadTools(bytes.NewReader(tgz), newVersion)
c.Assert(err, jc.ErrorIsNil)
c.Assert(toolsList, gc.HasLen, 1)
c.Assert(toolsList[0].SHA256, gc.Equals, checksum)
toolStrg, err := otherState.ToolsStorage()
defer toolStrg.Close()
c.Assert(err, jc.ErrorIsNil)
meta, closer, err := toolStrg.Open(vers)
defer closer.Close()
c.Assert(err, jc.ErrorIsNil)
c.Assert(meta.SHA256, gc.Equals, checksum)
c.Assert(meta.Version, gc.Equals, vers)
}
示例4: TestChangeAgentTools
func (t *ToolsSuite) TestChangeAgentTools(c *gc.C) {
files := []*testing.TarFile{
testing.NewTarFile("jujuc", agenttools.DirPerm, "juju executable"),
testing.NewTarFile("jujud", agenttools.DirPerm, "jujuc executable"),
}
data, checksum := testing.TarGz(files...)
testTools := &coretest.Tools{
URL: "http://foo/bar1",
Version: version.MustParseBinary("1.2.3-quantal-amd64"),
Size: int64(len(data)),
SHA256: checksum,
}
err := agenttools.UnpackTools(t.dataDir, testTools, bytes.NewReader(data))
c.Assert(err, jc.ErrorIsNil)
gotTools, err := agenttools.ChangeAgentTools(t.dataDir, "testagent", testTools.Version)
c.Assert(err, jc.ErrorIsNil)
c.Assert(*gotTools, gc.Equals, *testTools)
assertDirNames(c, t.toolsDir(), []string{"1.2.3-quantal-amd64", "testagent"})
assertDirNames(c, agenttools.ToolsDir(t.dataDir, "testagent"), []string{"jujuc", "jujud", agenttools.ToolsFile})
// Upgrade again to check that the link replacement logic works ok.
files2 := []*testing.TarFile{
testing.NewTarFile("quantal", agenttools.DirPerm, "foo content"),
testing.NewTarFile("amd64", agenttools.DirPerm, "bar content"),
}
data2, checksum2 := testing.TarGz(files2...)
tools2 := &coretest.Tools{
URL: "http://foo/bar2",
Version: version.MustParseBinary("1.2.4-quantal-amd64"),
Size: int64(len(data2)),
SHA256: checksum2,
}
err = agenttools.UnpackTools(t.dataDir, tools2, bytes.NewReader(data2))
c.Assert(err, jc.ErrorIsNil)
gotTools, err = agenttools.ChangeAgentTools(t.dataDir, "testagent", tools2.Version)
c.Assert(err, jc.ErrorIsNil)
c.Assert(*gotTools, gc.Equals, *tools2)
assertDirNames(c, t.toolsDir(), []string{"1.2.3-quantal-amd64", "1.2.4-quantal-amd64", "testagent"})
assertDirNames(c, agenttools.ToolsDir(t.dataDir, "testagent"), []string{"quantal", "amd64", agenttools.ToolsFile})
}
示例5: TestUnpackToolsBadChecksum
func (t *ToolsSuite) TestUnpackToolsBadChecksum(c *gc.C) {
data, _ := testing.TarGz(testing.NewTarFile("tools", agenttools.DirPerm, "some data"))
testTools := &coretest.Tools{
URL: "http://foo/bar",
Version: version.MustParseBinary("1.2.3-quantal-amd64"),
Size: int64(len(data)),
SHA256: "1234",
}
err := agenttools.UnpackTools(t.dataDir, testTools, bytes.NewReader(data))
c.Assert(err, gc.ErrorMatches, "tarball sha256 mismatch, expected 1234, got .*")
_, err = os.Stat(t.toolsDir())
c.Assert(err, gc.FitsTypeOf, &os.PathError{})
}
示例6: TestUnpackToolsContents
func (t *ToolsSuite) TestUnpackToolsContents(c *gc.C) {
files := []*testing.TarFile{
testing.NewTarFile("bar", agenttools.DirPerm, "bar contents"),
testing.NewTarFile("foo", agenttools.DirPerm, "foo contents"),
}
data, checksum := testing.TarGz(files...)
testTools := &coretest.Tools{
URL: "http://foo/bar",
Version: version.MustParseBinary("1.2.3-quantal-amd64"),
Size: int64(len(data)),
SHA256: checksum,
}
err := agenttools.UnpackTools(t.dataDir, testTools, bytes.NewReader(data))
c.Assert(err, jc.ErrorIsNil)
assertDirNames(c, t.toolsDir(), []string{"1.2.3-quantal-amd64"})
t.assertToolsContents(c, testTools, files)
// Try to unpack the same version of tools again - it should succeed,
// leaving the original version around.
files2 := []*testing.TarFile{
testing.NewTarFile("bar", agenttools.DirPerm, "bar2 contents"),
testing.NewTarFile("x", agenttools.DirPerm, "x contents"),
}
data2, checksum2 := testing.TarGz(files2...)
tools2 := &coretest.Tools{
URL: "http://arble",
Version: version.MustParseBinary("1.2.3-quantal-amd64"),
Size: int64(len(data2)),
SHA256: checksum2,
}
err = agenttools.UnpackTools(t.dataDir, tools2, bytes.NewReader(data2))
c.Assert(err, jc.ErrorIsNil)
assertDirNames(c, t.toolsDir(), []string{"1.2.3-quantal-amd64"})
t.assertToolsContents(c, testTools, files)
}
示例7: TestUnpackToolsContents
// Copied from environs/agent/tools_test.go
func (s *DiskManagerSuite) TestUnpackToolsContents(c *gc.C) {
files := []*coretesting.TarFile{
coretesting.NewTarFile("bar", 0755, "bar contents"),
coretesting.NewTarFile("foo", 0755, "foo contents"),
}
gzfile, checksum := coretesting.TarGz(files...)
t1 := &coretools.Tools{
URL: "http://foo/bar",
Version: version.MustParseBinary("1.2.3-foo-bar"),
Size: int64(len(gzfile)),
SHA256: checksum,
}
err := s.manager.UnpackTools(t1, bytes.NewReader(gzfile))
c.Assert(err, gc.IsNil)
assertDirNames(c, s.toolsDir(), []string{"1.2.3-foo-bar"})
s.assertToolsContents(c, t1, files)
// Try to unpack the same version of tools again - it should succeed,
// leaving the original version around.
files2 := []*coretesting.TarFile{
coretesting.NewTarFile("bar", 0755, "bar2 contents"),
coretesting.NewTarFile("x", 0755, "x contents"),
}
gzfile2, checksum2 := coretesting.TarGz(files2...)
t2 := &coretools.Tools{
URL: "http://arble",
Version: version.MustParseBinary("1.2.3-foo-bar"),
Size: int64(len(gzfile2)),
SHA256: checksum2,
}
err = s.manager.UnpackTools(t2, bytes.NewReader(gzfile2))
c.Assert(err, gc.IsNil)
assertDirNames(c, s.toolsDir(), []string{"1.2.3-foo-bar"})
s.assertToolsContents(c, t1, files)
}
示例8: uploadFakeToolsVersion
func uploadFakeToolsVersion(stor storage.Storage, vers version.Binary) (*coretools.Tools, error) {
logger.Infof("uploading FAKE tools %s", vers)
tgz, checksum := coretesting.TarGz(
coretesting.NewTarFile("jujud", 0777, "jujud contents "+vers.String()))
size := int64(len(tgz))
name := envtools.StorageName(vers)
if err := stor.Put(name, bytes.NewReader(tgz), size); err != nil {
return nil, err
}
url, err := stor.URL(name)
if err != nil {
return nil, err
}
return &coretools.Tools{URL: url, Version: vers, Size: size, SHA256: checksum}, nil
}
示例9: GetMockBuildTools
// GetMockBuildTools returns a sync.BuildToolsTarballFunc implementation which generates
// a fake tools tarball.
func GetMockBuildTools(c *gc.C) sync.BuildToolsTarballFunc {
return func(forceVersion *version.Number) (*sync.BuiltTools, error) {
vers := version.Current
if forceVersion != nil {
vers.Number = *forceVersion
}
tgz, checksum := coretesting.TarGz(
coretesting.NewTarFile("jujud", 0777, "jujud contents "+vers.String()))
toolsDir, err := ioutil.TempDir("", "juju-tools")
c.Assert(err, gc.IsNil)
name := "name"
ioutil.WriteFile(filepath.Join(toolsDir, name), tgz, 0777)
return &sync.BuiltTools{
Dir: toolsDir,
StorageName: name,
Version: vers,
Size: int64(len(tgz)),
Sha256Hash: checksum,
}, nil
}
}
示例10: makeFakeTools
func makeFakeTools(vers version.Binary) ([]byte, string) {
return coretesting.TarGz(
coretesting.NewTarFile(names.Jujud, 0777, "jujud contents "+vers.String()))
}
示例11: initBadDataTest
func initBadDataTest(name string, mode os.FileMode, contents string, err string) badDataTest {
var result badDataTest
result.data, result.checksum = testing.TarGz(testing.NewTarFile(name, mode, contents))
result.err = err
return result
}