Skip to content

Commit

Permalink
Replace model life strings with constants (#1112)
Browse files Browse the repository at this point in the history
* Replace model life strings with constants

* Add imports

* Fix test
  • Loading branch information
kian99 authored Dec 7, 2023
1 parent ec6de2d commit 8ad7773
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 66 deletions.
3 changes: 2 additions & 1 deletion internal/db/applicationoffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
qt "github.com/frankban/quicktest"
"github.com/google/go-cmp/cmp/cmpopts"

"github.com/canonical/jimm/internal/constants"
"github.com/canonical/jimm/internal/db"
"github.com/canonical/jimm/internal/dbmodel"
"github.com/canonical/jimm/internal/errors"
Expand Down Expand Up @@ -82,7 +83,7 @@ func initTestEnvironment(c *qt.C, db *db.Database) testEnvironment {
Type: "iaas",
IsController: false,
DefaultSeries: "warty",
Life: "alive",
Life: constants.ALIVE.String(),
Status: dbmodel.Status{
Status: "available",
Since: sql.NullTime{
Expand Down
5 changes: 3 additions & 2 deletions internal/db/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/google/go-cmp/cmp/cmpopts"
jujuparams "github.com/juju/juju/rpc/params"

"github.com/canonical/jimm/internal/constants"
"github.com/canonical/jimm/internal/db"
"github.com/canonical/jimm/internal/dbmodel"
"github.com/canonical/jimm/internal/errors"
Expand Down Expand Up @@ -150,7 +151,7 @@ func (s *dbSuite) TestGetControllerWithModels(c *qt.C) {
Type: "iaas",
IsController: true,
DefaultSeries: "warty",
Life: "alive",
Life: constants.ALIVE.String(),
Status: dbmodel.Status{
Status: "available",
Since: sql.NullTime{
Expand All @@ -174,7 +175,7 @@ func (s *dbSuite) TestGetControllerWithModels(c *qt.C) {
Type: "iaas",
IsController: false,
DefaultSeries: "warty",
Life: "alive",
Life: constants.ALIVE.String(),
Status: dbmodel.Status{
Status: "available",
Since: sql.NullTime{
Expand Down
15 changes: 8 additions & 7 deletions internal/db/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
qt "github.com/frankban/quicktest"
"gorm.io/gorm"

"github.com/canonical/jimm/internal/constants"
"github.com/canonical/jimm/internal/db"
"github.com/canonical/jimm/internal/dbmodel"
"github.com/canonical/jimm/internal/errors"
Expand Down Expand Up @@ -74,7 +75,7 @@ func (s *dbSuite) TestAddModel(c *qt.C) {
CloudCredentialID: cred.ID,
Type: "iaas",
DefaultSeries: "warty",
Life: "alive",
Life: constants.ALIVE.String(),
Status: dbmodel.Status{
Status: "available",
Since: db.Now(),
Expand Down Expand Up @@ -151,7 +152,7 @@ func (s *dbSuite) TestGetModel(c *qt.C) {
CloudCredential: cred,
Type: "iaas",
DefaultSeries: "warty",
Life: "alive",
Life: constants.ALIVE.String(),
Status: dbmodel.Status{
Status: "available",
Since: db.Now(),
Expand Down Expand Up @@ -243,7 +244,7 @@ func (s *dbSuite) TestUpdateModel(c *qt.C) {
CloudCredentialID: cred.ID,
Type: "iaas",
DefaultSeries: "warty",
Life: "alive",
Life: constants.ALIVE.String(),
Status: dbmodel.Status{
Status: "available",
Since: db.Now(),
Expand Down Expand Up @@ -322,7 +323,7 @@ func (s *dbSuite) TestDeleteModel(c *qt.C) {
CloudCredentialID: cred.ID,
Type: "iaas",
DefaultSeries: "warty",
Life: "alive",
Life: constants.ALIVE.String(),
Status: dbmodel.Status{
Status: "available",
Since: db.Now(),
Expand Down Expand Up @@ -406,7 +407,7 @@ func (s *dbSuite) TestGetModelsUsingCredential(c *qt.C) {
CloudCredentialID: cred1.ID,
Type: "iaas",
DefaultSeries: "warty",
Life: "alive",
Life: constants.ALIVE.String(),
Status: dbmodel.Status{
Status: "available",
Since: db.Now(),
Expand All @@ -430,7 +431,7 @@ func (s *dbSuite) TestGetModelsUsingCredential(c *qt.C) {
CloudCredentialID: cred2.ID,
Type: "iaas",
DefaultSeries: "warty",
Life: "alive",
Life: constants.ALIVE.String(),
Status: dbmodel.Status{
Status: "available",
Since: db.Now(),
Expand Down Expand Up @@ -460,7 +461,7 @@ func (s *dbSuite) TestGetModelsUsingCredential(c *qt.C) {
CloudCredentialID: cred1.ID,
Type: "iaas",
DefaultSeries: "warty",
Life: "alive",
Life: constants.ALIVE.String(),
Status: model1.Status,
SLA: dbmodel.SLA{
Level: "unsupported",
Expand Down
22 changes: 12 additions & 10 deletions internal/dbmodel/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import (
"time"

qt "github.com/frankban/quicktest"
"github.com/juju/juju/core/life"
jujuparams "github.com/juju/juju/rpc/params"
"github.com/juju/names/v4"
"gorm.io/gorm"

"github.com/canonical/jimm/internal/constants"
"github.com/canonical/jimm/internal/dbmodel"
)

Expand Down Expand Up @@ -80,7 +82,7 @@ func TestModel(t *testing.T) {
Type: "iaas",
IsController: false,
DefaultSeries: "warty",
Life: "alive",
Life: constants.ALIVE.String(),
Status: dbmodel.Status{
Status: "available",
Since: sql.NullTime{
Expand Down Expand Up @@ -146,7 +148,7 @@ func TestModelUniqueConstraint(t *testing.T) {
Type: "iaas",
IsController: false,
DefaultSeries: "warty",
Life: "alive",
Life: constants.ALIVE.String(),
Status: dbmodel.Status{
Status: "available",
Since: sql.NullTime{
Expand All @@ -173,7 +175,7 @@ func TestModelUniqueConstraint(t *testing.T) {
Type: "iaas",
IsController: false,
DefaultSeries: "jammy",
Life: "alive",
Life: constants.ALIVE.String(),
Status: dbmodel.Status{
Status: "available",
Since: sql.NullTime{
Expand Down Expand Up @@ -220,7 +222,7 @@ func TestToJujuModel(t *testing.T) {
Type: "iaas",
IsController: false,
DefaultSeries: "warty",
Life: "alive",
Life: constants.ALIVE.String(),
Status: dbmodel.Status{
Status: "available",
Since: sql.NullTime{
Expand Down Expand Up @@ -261,7 +263,7 @@ func TestToJujuModelSummary(t *testing.T) {
Type: "iaas",
IsController: false,
DefaultSeries: "warty",
Life: "alive",
Life: constants.ALIVE.String(),
Status: dbmodel.Status{
Status: "available",
Since: sql.NullTime{
Expand Down Expand Up @@ -291,7 +293,7 @@ func TestToJujuModelSummary(t *testing.T) {
CloudRegion: "test-region",
CloudCredentialTag: "cloudcred-test-cloud_bob@external_test-cred",
OwnerTag: "user-bob@external",
Life: "alive",
Life: life.Value(constants.ALIVE.String()),
Status: jujuparams.EntityStatus{
Status: "available",
Since: &now,
Expand Down Expand Up @@ -367,7 +369,7 @@ func TestModelFromJujuModelInfo(t *testing.T) {
CloudCredentialTag: "cloudcred-test-cloud_bob@external_test-cred",
CloudCredentialValidity: nil,
OwnerTag: "user-bob@external",
Life: "alive",
Life: life.Value(constants.ALIVE.String()),
Status: jujuparams.EntityStatus{
Status: "available",
Since: &now,
Expand Down Expand Up @@ -420,7 +422,7 @@ func TestModelFromJujuModelInfo(t *testing.T) {
Type: "iaas",
IsController: false,
DefaultSeries: "warty",
Life: "alive",
Life: constants.ALIVE.String(),
Status: dbmodel.Status{
Status: "available",
Since: sql.NullTime{
Expand All @@ -440,7 +442,7 @@ func TestModelFromJujuModelUpdate(t *testing.T) {

info := jujuparams.ModelUpdate{
Name: "test-model",
Life: "alive",
Life: life.Value(constants.ALIVE.String()),
Status: jujuparams.StatusInfo{
Current: "available",
Since: &now,
Expand All @@ -454,7 +456,7 @@ func TestModelFromJujuModelUpdate(t *testing.T) {
model.FromJujuModelUpdate(info)
c.Assert(model, qt.DeepEquals, dbmodel.Model{
Name: "test-model",
Life: "alive",
Life: constants.ALIVE.String(),
Status: dbmodel.Status{
Status: "available",
Since: sql.NullTime{
Expand Down
13 changes: 7 additions & 6 deletions internal/jimm/applicationoffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"gopkg.in/macaroon.v2"
"gorm.io/gorm"

"github.com/canonical/jimm/internal/constants"
"github.com/canonical/jimm/internal/db"
"github.com/canonical/jimm/internal/dbmodel"
"github.com/canonical/jimm/internal/errors"
Expand Down Expand Up @@ -914,7 +915,7 @@ func TestGetApplicationOffer(t *testing.T) {
Subnets: []jujuparams.Subnet{{
SpaceTag: "test-remote-space",
VLANTag: 1024,
Status: "dead",
Status: constants.DEAD.String(),
}},
}},
Bindings: map[string]string{
Expand Down Expand Up @@ -1094,7 +1095,7 @@ func TestGetApplicationOffer(t *testing.T) {
Subnets: []jujuparams.Subnet{{
SpaceTag: "test-remote-space",
VLANTag: 1024,
Status: "dead",
Status: constants.DEAD.String(),
}},
}},
},
Expand Down Expand Up @@ -1142,7 +1143,7 @@ func TestGetApplicationOffer(t *testing.T) {
Subnets: []jujuparams.Subnet{{
SpaceTag: "test-remote-space",
VLANTag: 1024,
Status: "dead",
Status: constants.DEAD.String(),
}},
}},
},
Expand Down Expand Up @@ -1219,7 +1220,7 @@ func TestOffer(t *testing.T) {
Subnets: []jujuparams.Subnet{{
SpaceTag: "test-remote-space",
VLANTag: 1024,
Status: "alive",
Status: constants.ALIVE.String(),
}},
}},
Bindings: map[string]string{
Expand Down Expand Up @@ -2026,7 +2027,7 @@ func TestOfferAssertOpenFGARelationsExist(t *testing.T) {
Subnets: []jujuparams.Subnet{{
SpaceTag: "test-remote-space",
VLANTag: 1024,
Status: "alive",
Status: constants.ALIVE.String(),
}},
}},
Bindings: map[string]string{
Expand Down Expand Up @@ -2410,7 +2411,7 @@ func TestUpdateOffer(t *testing.T) {
Subnets: []jujuparams.Subnet{{
SpaceTag: "test-remote-space",
VLANTag: 1024,
Status: "dead",
Status: constants.DEAD.String(),
}},
}},
Bindings: map[string]string{
Expand Down
15 changes: 8 additions & 7 deletions internal/jimm/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
semversion "github.com/juju/version"
"gopkg.in/macaroon.v2"

"github.com/canonical/jimm/internal/constants"
"github.com/canonical/jimm/internal/db"
"github.com/canonical/jimm/internal/dbmodel"
"github.com/canonical/jimm/internal/errors"
Expand Down Expand Up @@ -118,7 +119,7 @@ func TestAddController(t *testing.T) {
ms.CloudTag = "cloud-aws"
ms.CloudRegion = "eu-west-1"
ms.OwnerTag = "user-admin"
ms.Life = "alive"
ms.Life = life.Value(constants.ALIVE.String())
ms.Status = jujuparams.EntityStatus{
Status: "available",
}
Expand Down Expand Up @@ -285,7 +286,7 @@ func TestAddControllerWithVault(t *testing.T) {
ms.CloudTag = "cloud-aws"
ms.CloudRegion = "eu-west-1"
ms.OwnerTag = "user-admin"
ms.Life = "alive"
ms.Life = life.Value(constants.ALIVE.String())
ms.Status = jujuparams.EntityStatus{
Status: "available",
}
Expand Down Expand Up @@ -543,7 +544,7 @@ func TestImportModel(t *testing.T) {
ModelUUID: "00000002-0000-0000-0000-000000000001",
Name: "test-model",
Owner: "alice@external",
Life: "alive",
Life: life.Value(constants.ALIVE.String()),
ControllerUUID: "00000001-0000-0000-0000-000000000001",
Status: jujuparams.StatusInfo{
Current: "available",
Expand All @@ -562,15 +563,15 @@ func TestImportModel(t *testing.T) {
Name: "app-1",
Exposed: true,
CharmURL: "cs:app-1",
Life: "alive",
Life: life.Value(constants.ALIVE.String()),
MinUnits: 1,
WorkloadVersion: "2",
},
}, {
Entity: &jujuparams.MachineInfo{
ModelUUID: "00000002-0000-0000-0000-000000000001",
Id: "machine-1",
Life: "alive",
Life: life.Value(constants.ALIVE.String()),
Hostname: "test-machine-1",
},
}, {
Expand Down Expand Up @@ -624,7 +625,7 @@ func TestImportModel(t *testing.T) {
},
Type: "test-type",
DefaultSeries: "test-series",
Life: "alive",
Life: constants.ALIVE.String(),
Status: dbmodel.Status{
Status: "available",
Info: "updated status message",
Expand Down Expand Up @@ -712,7 +713,7 @@ func TestImportModel(t *testing.T) {
},
Type: "test-type",
DefaultSeries: "test-series",
Life: "alive",
Life: constants.ALIVE.String(),
Status: dbmodel.Status{
Status: "available",
Info: "test-info",
Expand Down
3 changes: 2 additions & 1 deletion internal/jimm/model_status_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/juju/juju/core/status"
jujuparams "github.com/juju/juju/rpc/params"

"github.com/canonical/jimm/internal/constants"
"github.com/canonical/jimm/internal/db"
"github.com/canonical/jimm/internal/errors"
"github.com/canonical/jimm/internal/jimm"
Expand Down Expand Up @@ -362,7 +363,7 @@ func TestQueryModelsJq(t *testing.T) {
MountPoint: "/home/ubuntu/myapp/.data",
ReadOnly: false,
},
Life: "alive",
Life: life.Value(constants.ALIVE.String()),
},
},
},
Expand Down
Loading

0 comments on commit 8ad7773

Please sign in to comment.