Beispiel #1
0
func (s *DirectorySuite) TestWriteContent(c *gc.C) {
	info, reader := newResource(c, s.stub.Stub, "spam", "some data")
	content := internal.Content{
		Data:        reader,
		Size:        info.Size,
		Fingerprint: info.Fingerprint,
	}
	relPath := info.Path
	stub := &stubDirectory{
		internalStub: s.stub,
	}
	dataDir := "/var/lib/juju/agents/unit-spam-1/resources"
	deps := s.stub
	spec := internal.NewDirectorySpec(dataDir, "eggs", deps)
	dir := internal.NewDirectory(spec, deps)
	s.stub.ResetCalls()

	err := dir.WriteContent(relPath, content)
	c.Assert(err, jc.ErrorIsNil)

	stub.CheckCallNames(c,
		"Join",
		"CreateWriter",
		"WriteContent",
		"CloseAndLog",
	)
}
Beispiel #2
0
func (s *DirectorySuite) TestWrite(c *gc.C) {
	res := resourcetesting.NewResource(c, s.stub.Stub, "spam", "a-application", "some data")
	stub := &stubDirectory{
		internalStub: s.stub,
	}
	stub.ReturnInfo = res.Resource
	opened := stub
	dataDir := "/var/lib/juju/agents/unit-spam-1/resources"
	deps := s.stub
	spec := internal.NewDirectorySpec(dataDir, "eggs", deps)
	s.stub.ResetCalls()
	dir := internal.NewDirectory(spec, deps)

	err := dir.Write(opened)
	c.Assert(err, jc.ErrorIsNil)

	stub.CheckCallNames(c,
		"Info",
		"Content",
		"Join",
		"CreateWriter",
		"WriteContent",
		"CloseAndLog",
	)
}
Beispiel #3
0
func (s *DirectorySpecSuite) TestResolveEmpty(c *gc.C) {
	dataDir := "/var/lib/juju/agents/unit-spam-1/resources"
	deps := s.stub
	spec := internal.NewDirectorySpec(dataDir, "eggs", deps)
	s.stub.ResetCalls()

	resolved := spec.Resolve()

	s.stub.CheckCallNames(c, "Join")
	c.Check(resolved, gc.Equals, dataDir+"/eggs")
}
Beispiel #4
0
func (s *DirectorySpecSuite) TestNewDirectorySpec(c *gc.C) {
	dataDir := "/var/lib/juju/agents/unit-spam-1/resources"
	deps := s.stub

	spec := internal.NewDirectorySpec(dataDir, "eggs", deps)

	s.stub.CheckCallNames(c, "Join")
	c.Check(spec, jc.DeepEquals, &internal.DirectorySpec{
		Name:    "eggs",
		Dirname: dataDir + "/eggs",
		Deps:    deps,
	})
}
Beispiel #5
0
func (s *DirectorySuite) TestNewDirectory(c *gc.C) {
	dataDir := "/var/lib/juju/agents/unit-spam-1/resources"
	deps := s.stub
	spec := internal.NewDirectorySpec(dataDir, "eggs", deps)
	s.stub.ResetCalls()

	dir := internal.NewDirectory(spec, deps)

	s.stub.CheckNoCalls(c)
	c.Check(dir, jc.DeepEquals, &internal.Directory{
		DirectorySpec: spec,
		Deps:          deps,
	})
}
Beispiel #6
0
func (s *DirectorySpecSuite) TestInitialize(c *gc.C) {
	dataDir := "/var/lib/juju/agents/unit-spam-1/resources"
	deps := s.stub
	spec := internal.NewDirectorySpec(dataDir, "eggs", deps)
	s.stub.ResetCalls()

	dir, err := spec.Initialize()
	c.Assert(err, jc.ErrorIsNil)

	s.stub.CheckCallNames(c, "MkdirAll")
	s.stub.CheckCall(c, 0, "MkdirAll", spec.Dirname)
	c.Check(dir, jc.DeepEquals, &internal.Directory{
		DirectorySpec: spec,
		Deps:          deps,
	})
}
func (s *DirectorySpecSuite) TestIsUpToDate(c *gc.C) {
	info, reader := newResource(c, s.stub.Stub, "spam", "some data")
	content := internal.Content{
		Data:        reader,
		Size:        info.Size,
		Fingerprint: info.Fingerprint,
	}
	dataDir := "/var/lib/juju/agents/unit-spam-1/resources"
	deps := s.stub
	spec := internal.NewDirectorySpec(dataDir, "eggs", deps)
	s.stub.ResetCalls()

	isUpToDate, err := spec.IsUpToDate(content)
	c.Assert(err, jc.ErrorIsNil)

	s.stub.CheckNoCalls(c)
	c.Check(isUpToDate, jc.IsFalse) // For now, always...
}
Beispiel #8
0
func (s *DirectorySpecSuite) TestIsUpToDateTrue(c *gc.C) {
	info, reader := newResource(c, s.stub.Stub, "spam", "some data")
	content := internal.Content{
		Data:        reader,
		Size:        info.Size,
		Fingerprint: info.Fingerprint,
	}
	s.stub.ReturnFingerprintMatches = true
	dataDir := "/var/lib/juju/agents/unit-spam-1/resources"
	deps := s.stub
	spec := internal.NewDirectorySpec(dataDir, "eggs", deps)
	s.stub.ResetCalls()

	isUpToDate, err := spec.IsUpToDate(content)
	c.Assert(err, jc.ErrorIsNil)

	s.stub.CheckCallNames(c, "Join", "FingerprintMatches")
	c.Check(isUpToDate, jc.IsTrue)
}
Beispiel #9
0
func (s *DirectorySpecSuite) TestIsUpToDateCalls(c *gc.C) {
	info, reader := newResource(c, s.stub.Stub, "spam", "some data")
	content := internal.Content{
		Data:        reader,
		Size:        info.Size,
		Fingerprint: info.Fingerprint,
	}
	dataDir := "/var/lib/juju/agents/unit-spam-1/resources"
	deps := s.stub
	spec := internal.NewDirectorySpec(dataDir, "eggs", deps)
	s.stub.ResetCalls()

	_, err := spec.IsUpToDate(content)
	c.Assert(err, jc.ErrorIsNil)

	s.stub.CheckCallNames(c, "Join", "FingerprintMatches")
	dirname := s.stub.Join(dataDir, "eggs")
	s.stub.CheckCall(c, 0, "Join", []string{dirname, "eggs"})
	s.stub.CheckCall(c, 1, "FingerprintMatches", s.stub.Join(dirname, "eggs"), info.Fingerprint)
}