Skip to content

Commit

Permalink
showcommit command: add showcommit own structs to ensure compability
Browse files Browse the repository at this point in the history
  • Loading branch information
nam committed Nov 8, 2019
1 parent 9ceaa83 commit 37efe3e
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion api/facadeversions.go
Expand Up @@ -75,7 +75,7 @@ var facadeVersions = map[string]int{
"MigrationStatusWatcher": 1,
"MigrationTarget": 1,
"ModelConfig": 2,
"ModelGeneration": 4,
"ModelGeneration": 3,
"ModelManager": 8,
"ModelUpgrader": 1,
"NotifyWatcher": 1,
Expand Down
6 changes: 3 additions & 3 deletions api/modelgeneration/modelgeneration.go
Expand Up @@ -219,12 +219,12 @@ func generationCommitsFromResults(results params.GenerationCommitResults, format

func generationCommitFromResult(result params.GenerationCommitResult, formatTime func(time.Time) string) model.GenerationCommit {
genCommit := result.GenerationCommit
appChanges := make([]model.GenerationApplication, len(genCommit.Applications))
appChanges := make([]model.GenerationCommitApplication, len(genCommit.Applications))
for i, a := range genCommit.Applications {
app := model.GenerationApplication{
app := model.GenerationCommitApplication{
ApplicationName: a.ApplicationName,
UnitProgress: a.UnitProgress,
ConfigChanges: a.ConfigChanges,
UnitsTracking: a.UnitsTracking,
}
appChanges[i] = app
}
Expand Down
9 changes: 4 additions & 5 deletions cmd/juju/model/listcommits_test.go
Expand Up @@ -4,15 +4,15 @@
package model_test

import (
"fmt"
"github.com/golang/mock/gomock"
"github.com/juju/cmd"
"github.com/juju/cmd/cmdtesting"
jc "github.com/juju/testing/checkers"
"github.com/pkg/errors"
gc "gopkg.in/check.v1"
"regexp"

"github.com/juju/cmd"
"github.com/juju/cmd/cmdtesting"
jc "github.com/juju/testing/checkers"

"github.com/juju/juju/cmd/juju/model"
"github.com/juju/juju/cmd/juju/model/mocks"
coremodel "github.com/juju/juju/core/model"
Expand Down Expand Up @@ -116,7 +116,6 @@ commits:

ctx, err := s.runCommand(c, "--format=yaml")
c.Assert(err, jc.ErrorIsNil)
fmt.Println(cmdtesting.Stdout(ctx))
c.Assert(cmdtesting.Stdout(ctx), gc.Matches, expected)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/juju/model/showcommit.go
Expand Up @@ -170,5 +170,5 @@ type formattedShowCommit struct {
}

type formattedShowCommitApplications struct {
Applications []model.GenerationApplication `json:"applications" yaml:"applications"`
Applications []model.GenerationCommitApplication `json:"applications" yaml:"applications"`
}
42 changes: 15 additions & 27 deletions cmd/juju/model/showcommit_test.go
Expand Up @@ -5,13 +5,14 @@ package model_test

import (
"github.com/golang/mock/gomock"
"github.com/juju/cmd"
"github.com/juju/cmd/cmdtesting"
jc "github.com/juju/testing/checkers"
"github.com/pkg/errors"
gc "gopkg.in/check.v1"
"regexp"

"github.com/juju/cmd"
"github.com/juju/cmd/cmdtesting"
jc "github.com/juju/testing/checkers"

"github.com/juju/juju/cmd/juju/model"
"github.com/juju/juju/cmd/juju/model/mocks"
coremodel "github.com/juju/juju/core/model"
Expand Down Expand Up @@ -53,14 +54,10 @@ func (s *showCommitsSuite) getMockValues() coremodel.GenerationCommit {
CreatedBy: "test-user",
GenerationId: 1,
BranchName: "bla",
Applications: []coremodel.GenerationApplication{{
Applications: []coremodel.GenerationCommitApplication{{
ApplicationName: "redis",
UnitProgress: "1/2",
UnitDetail: &coremodel.GenerationUnits{
UnitsTracking: []string{"redis/0"},
UnitsPending: []string{"redis/1"},
},
ConfigChanges: map[string]interface{}{"databases": 8},
UnitsTracking: []string{"redis/0"},
ConfigChanges: map[string]interface{}{"databases": 8},
}},
}
return values
Expand All @@ -77,15 +74,9 @@ func (s *showCommitsSuite) TestRunCommandJsonOutput(c *gc.C) {
"applications": [
{
"ApplicationName": "redis",
"UnitProgress": "1/2",
"UnitDetail": {
"UnitsTracking": [
"redis/0"
],
"UnitsPending": [
"redis/1"
]
},
"UnitsTracking": [
"redis/0"
],
"ConfigChanges": {
"databases": 8
}
Expand Down Expand Up @@ -115,12 +106,8 @@ branch:
bla:
applications:
- application: redis
progress: 1/2
units:
tracking:
- redis/0
incomplete:
- redis/1
- redis/0
config:
databases: 8
committed-at: "0001-01-01"
Expand All @@ -131,15 +118,16 @@ created-by: test-user
s.api.EXPECT().ShowCommit(gomock.Any(), 1).Return(result, nil)
ctx, err := s.runCommand(c, "1", "--format=yaml")
c.Assert(err, jc.ErrorIsNil)
c.Assert(cmdtesting.Stdout(ctx), gc.Matches, expected)
output := cmdtesting.Stdout(ctx)
c.Assert(output, gc.Matches, expected)
}

func (s *showCommitsSuite) TestRunCommandAPIError(c *gc.C) {
defer s.setup(c).Finish()

s.api.EXPECT().ShowCommit(gomock.Any(), gomock.Any()).Return(nil, errors.New("boom"))
s.api.EXPECT().ShowCommit(gomock.Any(), gomock.Any()).Return(coremodel.GenerationCommit{}, errors.New("boom"))

_, err := s.runCommand(c)
_, err := s.runCommand(c, "1")
c.Assert(err, gc.ErrorMatches, "boom")
}

Expand Down
27 changes: 20 additions & 7 deletions core/model/generation.go
Expand Up @@ -57,6 +57,19 @@ type GenerationApplication struct {
ConfigChanges map[string]interface{} `yaml:"config"`
}

// GenerationCommitApplication represents committed changes to an application
// made under a generation.
type GenerationCommitApplication struct {
// ApplicationsName is the name of the application.
ApplicationName string `yaml:"application"`

// UnitDetail specifies which units are and are not tracking the branch.
UnitsTracking []string `yaml:"units,omitempty"`

// Config changes are the committed changes from the generation
ConfigChanges map[string]interface{} `yaml:"config"`
}

// Generation represents detail of a model generation including config changes.
type Generation struct {
// Created is the formatted time at generation creation.
Expand All @@ -73,26 +86,26 @@ type Generation struct {
// GenerationCommits represents a model generation's commit details.
type GenerationCommit struct {
// BranchName uniquely identifies a branch *amongst in-flight branches*.
BranchName string `json:"branch"`
BranchName string `yaml:"branch"`

// Created is the Unix timestamp at generation creation.
Completed string `json:"completed"`
Completed string `yaml:"completed"`

// Created is the user who created the generation.
CompletedBy string `json:"completed-by"`
CompletedBy string `yaml:"completed-by"`

// Created is the Unix timestamp at generation creation.
Created string `json:"created,omitempty"`
Created string `yaml:"created,omitempty"`

// Created is the user who created the generation.
CreatedBy string `json:"created-by,omitempty"`
CreatedBy string `yaml:"created-by,omitempty"`

// GenerationId is the id .
GenerationId int `json:"generation-id,omitempty"`
GenerationId int `yaml:"generation-id,omitempty"`

// Applications holds the collection of application changes
// made under this generation.
Applications []GenerationApplication `json:"applications,omitempty"`
Applications []GenerationCommitApplication `yaml:"applications,omitempty"`
}

// GenerationSummaries is a type alias for a representation
Expand Down
2 changes: 1 addition & 1 deletion state/modelgeneration.go
Expand Up @@ -828,7 +828,7 @@ func (st *State) getCommittedBranchDoc(id int) (*generationDoc, error) {
return doc, nil
case mgo.ErrNotFound:
mod, _ := st.modelName()
return nil, errors.NotFoundf("generation_id %q in model %q", id, mod)
return nil, errors.NotFoundf("generation_id %d in model %q", id, mod)
default:
mod, _ := st.modelName()
return nil, errors.Annotatef(err, "retrieving generation_id %q in model %q", id, mod)
Expand Down

0 comments on commit 37efe3e

Please sign in to comment.