-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request juju#18386 from Aflynn50/oci-image-resource-store
juju#18386 Add a container image metadata store and state. This holds metadata for oci image resources. This metadata is the content of the resource file that is sent to units. The PR is based on and contains juju#18372. <!-- The PR title should match: <type>(optional <scope>): <description>. Please also ensure all commits in this PR comply with our conventional commits specification: https://docs.google.com/document/d/1SYUo9G7qZ_jdoVXpUVamS5VCgHmtZ0QA-wZxKoMS-C0 --> ## Checklist <!-- If an item is not applicable, use `~strikethrough~`. --> - [x] Code style: imports ordered, good names, simple structure, etc - [x] Comments saying why design decisions were made - [x] Go unit tests, with comments saying what you're testing ## QA steps Unit tests (for now) ## Links <!-- Link to all relevant specification, documentation, bug, issue or JIRA card. --> **Jira card:** [JUJU-7167](https://warthogs.atlassian.net/browse/JUJU-7167) [JUJU-7167]: https://warthogs.atlassian.net/browse/JUJU-7167?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
- Loading branch information
Showing
26 changed files
with
1,099 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright 2024 Canonical Ltd. | ||
// Licensed under the AGPLv3, see LICENCE file for details. | ||
|
||
package containermetadataresource | ||
|
||
import ( | ||
"testing" | ||
|
||
gc "gopkg.in/check.v1" | ||
) | ||
|
||
func TestPackage(t *testing.T) { | ||
gc.TestingT(t) | ||
} |
20 changes: 20 additions & 0 deletions
20
core/resources/containermetadataresource/testing/testing.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2024 Canonical Ltd. | ||
// Licensed under the AGPLv3, see LICENCE file for details. | ||
|
||
package testing | ||
|
||
import ( | ||
jc "github.com/juju/testing/checkers" | ||
gc "gopkg.in/check.v1" | ||
|
||
"github.com/juju/juju/core/resources/containermetadataresource" | ||
) | ||
|
||
// GenContainerMetadataResourceUUID can be used in testing for generating a objectstore UUID | ||
// that is checked for subsequent errors using the test suit's go check | ||
// instance. | ||
func GenContainerMetadataResourceUUID(c *gc.C) containermetadataresource.UUID { | ||
id, err := containermetadataresource.NewUUID() | ||
c.Assert(err, jc.ErrorIsNil) | ||
return id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2024 Canonical Ltd. | ||
// Licensed under the AGPLv3, see LICENCE file for details. | ||
|
||
package containermetadataresource | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/juju/errors" | ||
|
||
"github.com/juju/juju/internal/uuid" | ||
) | ||
|
||
// UUID represents a container metadata resource unique identifier. | ||
type UUID string | ||
|
||
// NewUUID is a convince function for generating a new container metadata resource uuid. | ||
func NewUUID() (UUID, error) { | ||
uuid, err := uuid.NewUUID() | ||
if err != nil { | ||
return UUID(""), err | ||
} | ||
return UUID(uuid.String()), nil | ||
} | ||
|
||
// ParseUUID returns a new UUID from the given string. If the string is not a | ||
// valid uuid an error satisfying [errors.NotValid] will be returned. | ||
func ParseUUID(value string) (UUID, error) { | ||
if !uuid.IsValidUUIDString(value) { | ||
return "", fmt.Errorf("id %q %w", value, errors.NotValid) | ||
} | ||
return UUID(value), nil | ||
} | ||
|
||
// String implements the stringer interface for UUID. | ||
func (u UUID) String() string { | ||
return string(u) | ||
} | ||
|
||
// Validate ensures the consistency of the UUID. If the uuid is invalid an error | ||
// satisfying [errors.NotValid] will be returned. | ||
func (u UUID) Validate() error { | ||
if u == "" { | ||
return fmt.Errorf("%wuuid cannot be empty", errors.Hide(errors.NotValid)) | ||
} | ||
if !uuid.IsValidUUIDString(string(u)) { | ||
return fmt.Errorf("uuid %q %w", u, errors.NotValid) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2024 Canonical Ltd. | ||
// Licensed under the AGPLv3, see LICENCE file for details. | ||
|
||
package containermetadataresource | ||
|
||
import ( | ||
"github.com/juju/errors" | ||
"github.com/juju/testing" | ||
jc "github.com/juju/testing/checkers" | ||
gc "gopkg.in/check.v1" | ||
|
||
"github.com/juju/juju/internal/uuid" | ||
) | ||
|
||
type ContainerMetadataResourceUUIDSuite struct { | ||
testing.IsolationSuite | ||
} | ||
|
||
var _ = gc.Suite(&ContainerMetadataResourceUUIDSuite{}) | ||
|
||
func (*ContainerMetadataResourceUUIDSuite) TestIDValidate(c *gc.C) { | ||
tests := []struct { | ||
uuid string | ||
err error | ||
}{ | ||
{ | ||
uuid: "", | ||
err: errors.NotValid, | ||
}, | ||
{ | ||
uuid: "invalid", | ||
err: errors.NotValid, | ||
}, | ||
{ | ||
uuid: uuid.MustNewUUID().String(), | ||
}, | ||
} | ||
|
||
for i, test := range tests { | ||
c.Logf("test %d: %q", i, test.uuid) | ||
err := UUID(test.uuid).Validate() | ||
|
||
if test.err == nil { | ||
c.Check(err, gc.IsNil) | ||
continue | ||
} | ||
|
||
c.Check(err, jc.ErrorIs, test.err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.