Skip to content

Commit

Permalink
Attempt to fix some more tests
Browse files Browse the repository at this point in the history
The following fixes tests where it was wrong to assume that you could
craft your way through adding a charm or an application if you didn't
know the series.
  • Loading branch information
SimonRichardson committed Apr 16, 2021
1 parent f0f180e commit 21cf773
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion state/caasmodel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func (s *CAASModelSuite) TestDeployIAASApplication(c *gc.C) {
Charm: ch,
}
_, err := st.AddApplication(args)
c.Assert(err, gc.ErrorMatches, `cannot add application "gitlab": series "bionic" in a kubernetes model not valid`)
c.Assert(err, gc.ErrorMatches, `cannot add application "gitlab": series "bionic" \(OS "Ubuntu"\) not supported by charm, supported series are "kubernetes"`)
}

func (s *CAASModelSuite) TestContainers(c *gc.C) {
Expand Down
8 changes: 4 additions & 4 deletions state/filesystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1293,13 +1293,13 @@ func (s *FilesystemStateSuite) testFilesystemAttachmentParams(
c *gc.C, countMin, countMax int, location string,
expect state.FilesystemAttachmentParams,
) {
ch := s.createStorageCharm(c, "storage-filesystem", charm.Storage{
ch := s.createStorageCharmWithSeries(c, "storage-filesystem", charm.Storage{
Name: "data",
Type: charm.StorageFilesystem,
CountMin: countMin,
CountMax: countMax,
Location: location,
})
}, s.series)
storage := map[string]state.StorageConstraints{
"data": makeStorageCons("rootfs", 1024, 1),
}
Expand Down Expand Up @@ -1399,13 +1399,13 @@ func (s *FilesystemIAASModelSuite) TestFilesystemAttachmentParamsConcurrentRemov
}

func (s *FilesystemStateSuite) TestFilesystemAttachmentParamsLocationStorageDir(c *gc.C) {
ch := s.createStorageCharm(c, "storage-filesystem", charm.Storage{
ch := s.createStorageCharmWithSeries(c, "storage-filesystem", charm.Storage{
Name: "data",
Type: charm.StorageFilesystem,
CountMin: 1,
CountMax: 1,
Location: "/var/lib/juju/storage",
})
}, s.series)
app := s.AddTestingApplication(c, "storage-filesystem", ch)
unit, err := app.AddUnit(state.AddUnitParams{})
if s.series != "kubernetes" {
Expand Down
2 changes: 1 addition & 1 deletion state/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ func (s *ModelSuite) TestDeployCAASApplication(c *gc.C) {
Charm: ch,
}
_, err := s.State.AddApplication(args)
c.Assert(err, gc.ErrorMatches, `cannot add application "gitlab": series "kubernetes" in a non container model not valid`)
c.Assert(err, gc.ErrorMatches, `cannot add application "gitlab": series "kubernetes" \(OS "Kubernetes"\) not supported by charm, supported series are "quantal"`)
}

func (s *ModelSuite) TestAllUnits(c *gc.C) {
Expand Down
11 changes: 10 additions & 1 deletion state/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,28 @@ func (s *StorageStateSuiteBase) setupSingleStorageDetachable(c *gc.C, kind, pool
return app, unit, storageTag
}

func (s *StorageStateSuiteBase) createStorageCharmWithSeries(c *gc.C, charmName string, storageMeta charm.Storage, series string) *state.Charm {
return s.createStorageCharmRevMeta(c, charmName, storageMeta, 1, fmt.Sprintf("series: [%s]", series))
}

func (s *StorageStateSuiteBase) createStorageCharm(c *gc.C, charmName string, storageMeta charm.Storage) *state.Charm {
return s.createStorageCharmRev(c, charmName, storageMeta, 1)
}

func (s *StorageStateSuiteBase) createStorageCharmRev(c *gc.C, charmName string, storageMeta charm.Storage, rev int) *state.Charm {
return s.createStorageCharmRevMeta(c, charmName, storageMeta, rev, "")
}

func (s *StorageStateSuiteBase) createStorageCharmRevMeta(c *gc.C, charmName string, storageMeta charm.Storage, rev int, additionalMeta string) *state.Charm {
meta := fmt.Sprintf(`
name: %s
summary: A charm for testing storage
description: ditto
%s
storage:
%s:
type: %s
`, charmName, storageMeta.Name, storageMeta.Type)
`, charmName, additionalMeta, storageMeta.Name, storageMeta.Type)
if storageMeta.ReadOnly {
meta += " read-only: true\n"
}
Expand Down

0 comments on commit 21cf773

Please sign in to comment.