当前位置: 首页>>代码示例>>Golang>>正文


Golang backups.ResultFromMetadata函数代码示例

本文整理汇总了Golang中github.com/juju/juju/apiserver/backups.ResultFromMetadata函数的典型用法代码示例。如果您正苦于以下问题:Golang ResultFromMetadata函数的具体用法?Golang ResultFromMetadata怎么用?Golang ResultFromMetadata使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ResultFromMetadata函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestList

func (s *listSuite) TestList(c *gc.C) {
	cleanup := backups.PatchClientFacadeCall(s.client,
		func(req string, paramsIn interface{}, resp interface{}) error {
			c.Check(req, gc.Equals, "List")

			c.Assert(paramsIn, gc.FitsTypeOf, params.BackupsListArgs{})

			if result, ok := resp.(*params.BackupsListResult); ok {
				result.List = make([]params.BackupsMetadataResult, 1)
				result.List[0] = apiserverbackups.ResultFromMetadata(s.Meta)
			} else {
				c.Fatalf("wrong output structure")
			}
			return nil
		},
	)
	defer cleanup()

	result, err := s.client.List()
	c.Assert(err, jc.ErrorIsNil)

	c.Assert(result.List, gc.HasLen, 1)
	resultItem := result.List[0]
	s.checkMetadataResult(c, &resultItem, s.Meta)
}
开发者ID:howbazaar,项目名称:juju,代码行数:25,代码来源:list_test.go

示例2: sendValid

func (s *backupsUploadSuite) sendValid(c *gc.C, id string) *http.Response {
	s.fake.Meta = backups.NewMetadata()
	s.fake.Meta.SetID("<a new backup ID>")

	var parts bytes.Buffer
	writer := multipart.NewWriter(&parts)

	// Set the metadata part.
	s.meta = backups.NewMetadata()
	metaResult := apiserverbackups.ResultFromMetadata(s.meta)
	header := make(textproto.MIMEHeader)
	header.Set("Content-Disposition", `form-data; name="metadata"`)
	header.Set("Content-Type", apihttp.CTypeJSON)
	part, err := writer.CreatePart(header)
	c.Assert(err, jc.ErrorIsNil)
	err = json.NewEncoder(part).Encode(metaResult)
	c.Assert(err, jc.ErrorIsNil)

	// Set the attached part.
	archive := bytes.NewBufferString("<compressed data>")
	part, err = writer.CreateFormFile("attached", "juju-backup.tar.gz")
	c.Assert(err, jc.ErrorIsNil)
	_, err = io.Copy(part, archive)
	c.Assert(err, jc.ErrorIsNil)

	// Send the request.
	ctype := writer.FormDataContentType()
	resp, err := s.authRequest(c, "PUT", s.backupURL(c), ctype, &parts)
	c.Assert(err, jc.ErrorIsNil)
	return resp
}
开发者ID:Pankov404,项目名称:juju,代码行数:31,代码来源:backup_test.go

示例3: TestSuccessfulRequest

func (s *uploadSuite) TestSuccessfulRequest(c *gc.C) {
	data := "<compressed archive data>"
	archive := strings.NewReader(data)

	meta := apiserverbackups.ResultFromMetadata(s.Meta)
	meta.ID = ""
	meta.Stored = time.Time{}
	meta.Size = int64(len(data))

	id, err := s.client.Upload(archive, meta)
	c.Assert(err, jc.ErrorIsNil)

	c.Check(id, gc.Matches, `[-\d]+\.[-0-9a-f]+`)

	// Check the stored contents.
	stored, err := s.client.Download(id)
	c.Assert(err, jc.ErrorIsNil)
	storedData, err := ioutil.ReadAll(stored)
	c.Assert(err, jc.ErrorIsNil)
	c.Check(string(storedData), gc.Equals, data)

	// Check the stored metadata.
	storedMeta, err := s.client.Info(id)
	c.Assert(err, jc.ErrorIsNil)
	meta.ID = id
	meta.Stored = storedMeta.Stored
	c.Check(storedMeta, gc.DeepEquals, &meta)
}
开发者ID:bac,项目名称:juju,代码行数:28,代码来源:upload_test.go

示例4: TestCreate

func (s *createSuite) TestCreate(c *gc.C) {
	cleanup := backups.PatchClientFacadeCall(s.client,
		func(req string, paramsIn interface{}, resp interface{}) error {
			c.Check(req, gc.Equals, "Create")

			c.Assert(paramsIn, gc.FitsTypeOf, params.BackupsCreateArgs{})
			p := paramsIn.(params.BackupsCreateArgs)
			c.Check(p.Notes, gc.Equals, "important")

			if result, ok := resp.(*params.BackupsMetadataResult); ok {
				*result = apiserverbackups.ResultFromMetadata(s.Meta)
				result.Notes = p.Notes
			} else {
				c.Fatalf("wrong output structure")
			}
			return nil
		},
	)
	defer cleanup()

	result, err := s.client.Create("important")
	c.Assert(err, jc.ErrorIsNil)

	meta := backupstesting.UpdateNotes(s.Meta, "important")
	s.checkMetadataResult(c, result, meta)
}
开发者ID:howbazaar,项目名称:juju,代码行数:26,代码来源:create_test.go

示例5: TestInfoMissingFile

func (s *backupsSuite) TestInfoMissingFile(c *gc.C) {
	s.setBackups(c, s.meta, "")
	args := params.BackupsInfoArgs{
		ID: "some-id",
	}
	result, err := s.api.Info(args)
	c.Assert(err, jc.ErrorIsNil)
	expected := backups.ResultFromMetadata(s.meta)

	c.Check(result, gc.DeepEquals, expected)
}
开发者ID:howbazaar,项目名称:juju,代码行数:11,代码来源:info_test.go

示例6: TestInfoOkay

func (s *backupsSuite) TestInfoOkay(c *gc.C) {
	impl := s.setBackups(c, s.meta, "")
	impl.Archive = ioutil.NopCloser(bytes.NewBufferString("spamspamspam"))
	args := params.BackupsInfoArgs{
		ID: "some-id",
	}
	result, err := s.api.Info(args)
	c.Assert(err, jc.ErrorIsNil)
	expected := backups.ResultFromMetadata(s.meta)
	c.Check(result, gc.DeepEquals, expected)
}
开发者ID:howbazaar,项目名称:juju,代码行数:11,代码来源:info_test.go

示例7: TestCreateOkay

func (s *backupsSuite) TestCreateOkay(c *gc.C) {
	s.PatchValue(backups.WaitUntilReady,
		func(*mgo.Session, int) error { return nil },
	)
	s.setBackups(c, s.meta, "")
	var args params.BackupsCreateArgs
	result, err := s.api.Create(args)
	c.Assert(err, jc.ErrorIsNil)
	expected := backups.ResultFromMetadata(s.meta)

	c.Check(result, gc.DeepEquals, expected)
}
开发者ID:imoapps,项目名称:juju,代码行数:12,代码来源:create_test.go

示例8: TestListOkay

func (s *backupsSuite) TestListOkay(c *gc.C) {
	impl := s.setBackups(c, s.meta, "")
	impl.Archive = ioutil.NopCloser(bytes.NewBufferString("spamspamspam"))
	args := params.BackupsListArgs{}
	result, err := s.api.List(args)
	c.Assert(err, jc.ErrorIsNil)

	item := backups.ResultFromMetadata(s.meta)
	expected := params.BackupsListResult{
		List: []params.BackupsMetadataResult{item},
	}

	c.Check(result, gc.DeepEquals, expected)
}
开发者ID:howbazaar,项目名称:juju,代码行数:14,代码来源:list_test.go

示例9: TestFailedRequest

func (s *uploadSuite) TestFailedRequest(c *gc.C) {
	data := "<compressed archive data>"
	archive := strings.NewReader(data)

	meta := apiserverbackups.ResultFromMetadata(s.Meta)
	meta.ID = ""
	meta.Size = int64(len(data))
	// The Model field is required, so zero it so that
	// we'll get an error from the endpoint.
	meta.Model = ""

	id, err := s.client.Upload(archive, meta)
	c.Assert(err, gc.ErrorMatches, `.*while storing backup archive: missing Model$`)
	c.Assert(id, gc.Equals, "")
}
开发者ID:bac,项目名称:juju,代码行数:15,代码来源:upload_test.go

示例10: TestSuccess

func (s *uploadSuite) TestSuccess(c *gc.C) {
	s.setSuccess(c, "<a new backup ID>")

	data := "<compressed archive data>"
	archive := ioutil.NopCloser(bytes.NewBufferString(data))

	meta := apiserverbackups.ResultFromMetadata(s.Meta)
	meta.ID = ""
	meta.Stored = time.Time{}

	id, err := s.client.Upload(archive, meta)
	c.Assert(err, jc.ErrorIsNil)

	c.Check(id, gc.Equals, "<a new backup ID>")
	s.FakeClient.CheckCalledReader(c, "backups", archive, &meta, "juju-backup.tar.gz", "SendHTTPRequestReader")
}
开发者ID:Pankov404,项目名称:juju,代码行数:16,代码来源:upload_test.go

示例11: TestCreateNotes

func (s *backupsSuite) TestCreateNotes(c *gc.C) {
	s.PatchValue(backups.WaitUntilReady,
		func(*mgo.Session, int) error { return nil },
	)
	s.meta.Notes = "this backup is important"
	s.setBackups(c, s.meta, "")
	args := params.BackupsCreateArgs{
		Notes: "this backup is important",
	}
	result, err := s.api.Create(args)
	c.Assert(err, jc.ErrorIsNil)
	expected := backups.ResultFromMetadata(s.meta)
	expected.Notes = "this backup is important"

	c.Check(result, gc.DeepEquals, expected)
}
开发者ID:imoapps,项目名称:juju,代码行数:16,代码来源:create_test.go

示例12: TestInfo

func (s *infoSuite) TestInfo(c *gc.C) {
	cleanup := backups.PatchClientFacadeCall(s.client,
		func(req string, paramsIn interface{}, resp interface{}) error {
			c.Check(req, gc.Equals, "Info")

			c.Assert(paramsIn, gc.FitsTypeOf, params.BackupsInfoArgs{})
			p := paramsIn.(params.BackupsInfoArgs)
			c.Check(p.ID, gc.Equals, "spam")

			if result, ok := resp.(*params.BackupsMetadataResult); ok {
				*result = apiserverbackups.ResultFromMetadata(s.Meta)
			} else {
				c.Fatalf("wrong output structure")
			}
			return nil
		},
	)
	defer cleanup()

	result, err := s.client.Info("spam")
	c.Assert(err, jc.ErrorIsNil)

	s.checkMetadataResult(c, result, s.Meta)
}
开发者ID:howbazaar,项目名称:juju,代码行数:24,代码来源:info_test.go

示例13: metadataResult

func (s *baseSuite) metadataResult() *params.BackupsMetadataResult {
	result := apiserverbackups.ResultFromMetadata(s.Meta)
	return &result
}
开发者ID:imoapps,项目名称:juju,代码行数:4,代码来源:base_test.go

示例14: getArchive

func getArchive(filename string) (rc ArchiveReader, metaResult *params.BackupsMetadataResult, err error) {
	defer func() {
		if err != nil && rc != nil {
			rc.Close()
		}
	}()
	archive, err := os.Open(filename)
	rc = archive
	if err != nil {
		return nil, nil, errors.Trace(err)
	}

	// Extract the metadata.
	ad, err := statebackups.NewArchiveDataReader(archive)
	if err != nil {
		return nil, nil, errors.Trace(err)
	}
	_, err = archive.Seek(0, os.SEEK_SET)
	if err != nil {
		return nil, nil, errors.Trace(err)
	}
	meta, err := ad.Metadata()
	if err != nil {
		if !errors.IsNotFound(err) {
			return nil, nil, errors.Trace(err)
		}
		meta, err = statebackups.BuildMetadata(archive)
		if err != nil {
			return nil, nil, errors.Trace(err)
		}
	}
	// Make sure the file info is set.
	fileMeta, err := statebackups.BuildMetadata(archive)
	if err != nil {
		return nil, nil, errors.Trace(err)
	}
	if meta.Size() == int64(0) {
		if err := meta.SetFileInfo(fileMeta.Size(), "", ""); err != nil {
			return nil, nil, errors.Trace(err)
		}
	}
	if meta.Checksum() == "" {
		err := meta.SetFileInfo(0, fileMeta.Checksum(), fileMeta.ChecksumFormat())
		if err != nil {
			return nil, nil, errors.Trace(err)
		}
	}
	if meta.Finished == nil || meta.Finished.IsZero() {
		meta.Finished = fileMeta.Finished
	}
	_, err = archive.Seek(0, os.SEEK_SET)
	if err != nil {
		return nil, nil, errors.Trace(err)
	}

	// Pack the metadata into a result.
	// TODO(perrito666) change the identity of ResultfromMetadata to
	// return a pointer.
	mResult := apiserverbackups.ResultFromMetadata(meta)
	metaResult = &mResult

	return archive, metaResult, nil
}
开发者ID:makyo,项目名称:juju,代码行数:63,代码来源:backups.go


注:本文中的github.com/juju/juju/apiserver/backups.ResultFromMetadata函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。