Skip to content

Commit

Permalink
Additional tests to cover selecting next release.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonRichardson committed Feb 23, 2022
1 parent 143a762 commit 73ba4e9
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/charm/repository/charmhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ func (c *CharmHubRepository) selectNextBasesFromReleases(releases []transport.Re
// If the user passed in a branch, but not enough information about the
// arch and series, then we can help by giving a better error message.
if origin.Channel != nil && origin.Channel.Branch != "" {
return nil, errors.Errorf("ambiguous arch and series with channel track/risk/branch. specify both arch and series along with channel.")
return nil, errors.Errorf("ambiguous arch and series with channel track/risk/branch. specify both arch and series along with channel")
}
// If the origin is empty, then we want to help the user out
// by display a series of suggestions to try.
Expand Down
66 changes: 66 additions & 0 deletions core/charm/repository/charmhub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ func (refreshConfigSuite) TestRefreshByID(c *gc.C) {

type selectNextBaseSuite struct {
testing.IsolationSuite
logger *mocks.MockLogger
}

var _ = gc.Suite(&selectNextBaseSuite{})
Expand Down Expand Up @@ -773,6 +774,71 @@ func (selectNextBaseSuite) TestSelectNextBaseWithValidBases(c *gc.C) {
}})
}

func (selectNextBaseSuite) TestSelectNextBasesFromReleasesNoReleasesError(c *gc.C) {
channel := corecharm.MustParseChannel("stable/foo")
repo := new(CharmHubRepository)
_, err := repo.selectNextBasesFromReleases([]transport.Release{}, corecharm.Origin{
Channel: &channel,
})
c.Assert(err, gc.ErrorMatches, `no releases available`)
}

func (selectNextBaseSuite) TestSelectNextBasesFromReleasesAmbiguousMatchError(c *gc.C) {
channel := corecharm.MustParseChannel("stable/foo")
repo := new(CharmHubRepository)
_, err := repo.selectNextBasesFromReleases([]transport.Release{
{},
}, corecharm.Origin{
Channel: &channel,
})
c.Assert(err, gc.ErrorMatches, `ambiguous arch and series with channel track/risk/branch. specify both arch and series along with channel`)
}

func (s *selectNextBaseSuite) TestSelectNextBasesFromReleasesSuggestionError(c *gc.C) {
defer s.setupMocks(c).Finish()
repo := NewCharmHubRepository(s.logger, nil)

channel := corecharm.MustParseChannel("stable")
_, err := repo.selectNextBasesFromReleases([]transport.Release{{
Base: transport.Base{
Name: "os",
Channel: "series",
Architecture: "arch",
},
Channel: "stable",
}}, corecharm.Origin{
Channel: &channel,
})
c.Assert(err, gc.ErrorMatches, `no charm or bundle matching channel or platform`)
}

func (s *selectNextBaseSuite) TestSelectNextBasesFromReleasesSuggestion(c *gc.C) {
defer s.setupMocks(c).Finish()
repo := NewCharmHubRepository(s.logger, nil)

_, err := repo.selectNextBasesFromReleases([]transport.Release{{
Base: transport.Base{
Name: "os",
Channel: "20.04",
Architecture: "arch",
},
Channel: "stable",
}}, corecharm.Origin{
Platform: corecharm.Platform{
Architecture: "arch",
},
})
c.Assert(err, gc.ErrorMatches, `no charm or bundle matching channel or platform; suggestions: stable with focal`)
}

func (s *selectNextBaseSuite) setupMocks(c *gc.C) *gomock.Controller {
ctrl := gomock.NewController(c)
s.logger = mocks.NewMockLogger(ctrl)
s.logger.EXPECT().Errorf(gomock.Any(), gomock.Any()).AnyTimes()
s.logger.EXPECT().Tracef(gomock.Any(), gomock.Any()).AnyTimes()
return ctrl
}

type composeSuggestionsSuite struct {
testing.IsolationSuite
logger *mocks.MockLogger
Expand Down

0 comments on commit 73ba4e9

Please sign in to comment.