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", ) }
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", ) }
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, }) }