-
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#18460 from gfouillet/v4/dqlite/resources/stat…
…e-6479-manage-rows juju#18460 Implements function to delete resources. Include service and state layer. * DeleteUnitResource removes the links between a unit and its linked resources * DeleteApplicationResource removes all resources from an application, providing their are not linked to any unit or stored data. > [!NOTE] > Adding resources will be done in another PR, directly in the CreateApplication transaction <!-- Why this change is needed and what it does. --> ## 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 ~- [ ] [Integration tests](https://github.com/juju/juju/tree/main/tests), with comments saying what you're testing~ ~- [ ] [doc.go](https://discourse.charmhub.io/t/readme-in-packages/451) added or updated in changed packages~ ## QA steps None. Unit test should pass and cover usecases. ## Documentation changes None ## Links **Jira card:** JUJU-[6479](https://warthogs.atlassian.net/browse/JUJU-6479)
- Loading branch information
Showing
13 changed files
with
823 additions
and
39 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2024 Canonical Ltd. | ||
// Licensed under the AGPLv3, see LICENCE file for details. | ||
|
||
package resource | ||
|
||
import ( | ||
"github.com/juju/juju/internal/errors" | ||
) | ||
|
||
// These are the valid resource states. | ||
const ( | ||
// StateAvailable represents a resource which will be used by any units at | ||
// this point in time | ||
StateAvailable State = "available" | ||
|
||
// StatePotential indicates there is a different revision of the resource | ||
// available in a repository. Used to let users know a resource can be | ||
// upgraded. | ||
StatePotential State = "potential" | ||
) | ||
|
||
// State identifies the resource state in an application | ||
type State string | ||
|
||
// ParseState converts the provided string into an State. | ||
// If it is not a known state then an error is returned. | ||
func ParseState(value string) (State, error) { | ||
state := State(value) | ||
return state, state.Validate() | ||
} | ||
|
||
// String returns the printable representation of the state. | ||
func (o State) String() string { | ||
return string(o) | ||
} | ||
|
||
// Validate ensures that the state is correct. | ||
func (o State) Validate() error { | ||
if _, ok := map[State]bool{ | ||
StateAvailable: true, | ||
StatePotential: true, | ||
}[o]; !ok { | ||
return errors.Errorf("state %q invalid", o) | ||
} | ||
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,54 @@ | ||
// Copyright 2024 Canonical Ltd. | ||
// Licensed under the AGPLv3, see LICENCE file for details. | ||
|
||
package resource | ||
|
||
import ( | ||
"github.com/juju/testing" | ||
jc "github.com/juju/testing/checkers" | ||
gc "gopkg.in/check.v1" | ||
) | ||
|
||
type StateSuite struct { | ||
testing.IsolationSuite | ||
} | ||
|
||
var _ = gc.Suite(&StateSuite{}) | ||
|
||
func (StateSuite) TestParseStateKnown(c *gc.C) { | ||
recognized := map[string]State{ | ||
"potential": StatePotential, | ||
"available": StateAvailable, | ||
} | ||
for value, expected := range recognized { | ||
state, err := ParseState(value) | ||
|
||
c.Check(err, jc.ErrorIsNil) | ||
c.Check(state, gc.Equals, expected) | ||
} | ||
} | ||
|
||
func (StateSuite) TestParseStateUnknown(c *gc.C) { | ||
_, err := ParseState("<invalid>") | ||
|
||
c.Check(err, gc.ErrorMatches, `.*state "<invalid>" invalid.*`) | ||
} | ||
|
||
func (StateSuite) TestValidateKnown(c *gc.C) { | ||
recognized := []State{ | ||
StatePotential, | ||
StateAvailable, | ||
} | ||
for _, state := range recognized { | ||
err := state.Validate() | ||
|
||
c.Check(err, jc.ErrorIsNil) | ||
} | ||
} | ||
|
||
func (StateSuite) TestValidateUnknown(c *gc.C) { | ||
var state State | ||
err := state.Validate() | ||
|
||
c.Check(err, gc.ErrorMatches, `.*state "" invalid.*`) | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.