Skip to content

Commit

Permalink
feat(resources): add domain methods
Browse files Browse the repository at this point in the history
This change adds several domain methods to the resources domain. It
adds:
- StoreResource
- StoreResourceAndIncrementCharmModifiedVersion
- OpenResource
- SetApplicationResource
- SetUnitResource

These methods complete the foundation of the resource domain.

These methods differ from their state counterparts in several ways. In
state, most equivilents of these methods also returned the resource
record, even if they were only setting a resource. Here they do not.
They are designed to each do only one thing, the thing that their name
describes.

In state there was an OpenResource and OpenResourceForUniter. This
seperate method also set the unit resource doc. In the new domain
methods, this linking should be done via the SetUnitResource instead.

In state, the SetResource method did several things. It has now been
factored out into the StoreResource,
StoreResourceAndIncremenetCharmModifiedVersion and SetApplicationResource.
This is to make it clearer what each method does.
  • Loading branch information
Aflynn50 committed Dec 18, 2024
1 parent 6a04a0e commit 6f35cff
Show file tree
Hide file tree
Showing 12 changed files with 2,450 additions and 664 deletions.
8 changes: 8 additions & 0 deletions domain/application/state/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,14 @@ func (s *applicationStateSuite) TestGetCharmModifiedVersion(c *gc.C) {
c.Assert(charmModifiedVersion, gc.Equals, 7)
}

func (s *applicationStateSuite) TestGetCharmModifiedVersionNull(c *gc.C) {
appUUID := s.createApplication(c, "foo", life.Alive)

charmModifiedVersion, err := s.state.GetCharmModifiedVersion(context.Background(), appUUID)
c.Assert(err, jc.ErrorIsNil)
c.Assert(charmModifiedVersion, gc.Equals, 0)
}

func (s *applicationStateSuite) TestGetCharmModifiedVersionApplicationNotFound(c *gc.C) {
_, err := s.state.GetCharmModifiedVersion(context.Background(), applicationtesting.GenApplicationUUID(c))
c.Assert(err, jc.ErrorIs, applicationerrors.ApplicationNotFound)
Expand Down
4 changes: 4 additions & 0 deletions domain/resource/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@ const (
// cannot be found in the relevant resource persistence layer for its
// resource type.
StoredResourceNotFound = errors.ConstError("stored resource not found")

// ResourceAlreadyStored describes an errors where the resource has already
// been stored.
ResourceAlreadyStored = errors.ConstError("resource already found in storage")
)
159 changes: 78 additions & 81 deletions domain/resource/service/package_mock_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions domain/resource/service/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

//go:generate go run go.uber.org/mock/mockgen -typed -package service -destination package_mock_test.go github.com/juju/juju/domain/resource/service State,ResourceStoreGetter
//go:generate go run go.uber.org/mock/mockgen -typed -package service -destination resource_store_mock_test.go github.com/juju/juju/core/resource/store ResourceStore

func TestPackage(t *testing.T) {
gc.TestingT(t)
Expand Down
Loading

0 comments on commit 6f35cff

Please sign in to comment.