Exemple #1
0
func (s *ContextSuite) TestContextDownloadUpToDate(c *gc.C) {
	info, reader := newResource(c, s.stub.Stub, "spam", "some data")
	content := internal.Content{
		Data:        reader,
		Size:        info.Size,
		Fingerprint: info.Fingerprint,
	}
	stub := &stubContext{
		internalStub: s.stub,
		StubCloser:   &filetesting.StubCloser{Stub: s.stub.Stub},
	}
	stub.ReturnNewContextDirectorySpec = stub
	stub.ReturnOpenResource = stub
	stub.ReturnResolve = "/var/lib/juju/agents/unit-spam-1/resources/spam/eggs.tgz"
	stub.ReturnInfo = info
	stub.ReturnContent = content
	stub.ReturnIsUpToDate = true
	deps := stub

	path, err := internal.ContextDownload(deps)
	c.Assert(err, jc.ErrorIsNil)

	s.stub.CheckCallNames(c,
		"NewContextDirectorySpec",
		"OpenResource",
		"Info",
		"Resolve",
		"Content",
		"IsUpToDate",
		"CloseAndLog",
	)
	c.Check(path, gc.Equals, "/var/lib/juju/agents/unit-spam-1/resources/spam/eggs.tgz")
}
Exemple #2
0
// Download downloads the named resource and returns the path
// to which it was downloaded. If the resource does not exist or has
// not been uploaded yet then errors.NotFound is returned.
//
// Note that the downloaded file is checked for correctness.
func (c *Context) Download(name string) (string, error) {
	deps := &contextDeps{
		APIClient: c.apiClient,
		name:      name,
		dataDir:   c.dataDir,
	}
	path, err := internal.ContextDownload(deps)
	if err != nil {
		return "", errors.Trace(err)
	}
	return path, nil
}