Split Meta back out of StateMeta

Removing the call to StateMeta.Env, so that it doesn't need an embedded
Meta field. Embed Meta and StateMeta separately in all State commands.
This commit is contained in:
James Bardin 2017-03-01 10:10:47 -05:00
parent 4dac986a91
commit 39a5ddd381
15 changed files with 95 additions and 147 deletions

View File

@ -90,7 +90,7 @@ func (c *EnvDeleteCommand) Run(args []string) int {
// Lock the state if we can
lockInfo := state.NewLockInfo()
lockInfo.Operation = "env new"
lockInfo.Operation = "env delete"
lockID, err := clistate.Lock(sMgr, lockInfo, c.Ui, c.Colorize())
if err != nil {
c.Ui.Error(fmt.Sprintf("Error locking state: %s", err))

View File

@ -11,6 +11,7 @@ import (
// StateListCommand is a Command implementation that lists the resources
// within a state file.
type StateListCommand struct {
Meta
StateMeta
}

View File

@ -16,11 +16,9 @@ func TestStateList(t *testing.T) {
p := testProvider()
ui := new(cli.MockUi)
c := &StateListCommand{
StateMeta: StateMeta{
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
}
@ -49,11 +47,9 @@ func TestStateList_backendState(t *testing.T) {
p := testProvider()
ui := new(cli.MockUi)
c := &StateListCommand{
StateMeta: StateMeta{
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
}
@ -77,11 +73,9 @@ func TestStateList_noState(t *testing.T) {
p := testProvider()
ui := new(cli.MockUi)
c := &StateListCommand{
StateMeta: StateMeta{
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
}

View File

@ -11,13 +11,12 @@ import (
)
// StateMeta is the meta struct that should be embedded in state subcommands.
type StateMeta struct {
Meta
}
type StateMeta struct{}
// State returns the state for this meta. This is different then Meta.State
// in the way that backups are done. This configures backups to be timestamped
// rather than just the original state path plus a backup path.
// State returns the state for this meta. This gets the appropriate state from
// the backend, but changes the way that backups are done. This configures
// backups to be timestamped rather than just the original state path plus a
// backup path.
func (c *StateMeta) State(m *Meta) (state.State, error) {
// Load the backend
b, err := m.Backend(nil)
@ -25,7 +24,7 @@ func (c *StateMeta) State(m *Meta) (state.State, error) {
return nil, err
}
env := c.Env()
env := m.Env()
// Get the state
s, err := b.State(env)
if err != nil {

View File

@ -10,6 +10,7 @@ import (
// StateMvCommand is a Command implementation that shows a single resource.
type StateMvCommand struct {
Meta
StateMeta
}

View File

@ -46,11 +46,9 @@ func TestStateMv(t *testing.T) {
p := testProvider()
ui := new(cli.MockUi)
c := &StateMvCommand{
StateMeta: StateMeta{
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
}
@ -115,11 +113,9 @@ func TestStateMv_backupExplicit(t *testing.T) {
p := testProvider()
ui := new(cli.MockUi)
c := &StateMvCommand{
StateMeta: StateMeta{
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
}
@ -172,11 +168,9 @@ func TestStateMv_stateOutNew(t *testing.T) {
p := testProvider()
ui := new(cli.MockUi)
c := &StateMvCommand{
StateMeta: StateMeta{
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
}
@ -246,11 +240,9 @@ func TestStateMv_stateOutExisting(t *testing.T) {
p := testProvider()
ui := new(cli.MockUi)
c := &StateMvCommand{
StateMeta: StateMeta{
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
}
@ -289,11 +281,9 @@ func TestStateMv_noState(t *testing.T) {
p := testProvider()
ui := new(cli.MockUi)
c := &StateMvCommand{
StateMeta: StateMeta{
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
}
@ -352,11 +342,9 @@ func TestStateMv_stateOutNew_count(t *testing.T) {
p := testProvider()
ui := new(cli.MockUi)
c := &StateMvCommand{
StateMeta: StateMeta{
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
}
@ -532,11 +520,9 @@ func TestStateMv_stateOutNew_largeCount(t *testing.T) {
p := testProvider()
ui := new(cli.MockUi)
c := &StateMvCommand{
StateMeta: StateMeta{
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
}
@ -615,11 +601,9 @@ func TestStateMv_stateOutNew_nestedModule(t *testing.T) {
p := testProvider()
ui := new(cli.MockUi)
c := &StateMvCommand{
StateMeta: StateMeta{
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
}

View File

@ -11,6 +11,7 @@ import (
// StatePullCommand is a Command implementation that shows a single resource.
type StatePullCommand struct {
Meta
StateMeta
}

View File

@ -20,11 +20,9 @@ func TestStatePull(t *testing.T) {
p := testProvider()
ui := new(cli.MockUi)
c := &StatePullCommand{
StateMeta: StateMeta{
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
}

View File

@ -11,6 +11,7 @@ import (
// StatePushCommand is a Command implementation that shows a single resource.
type StatePushCommand struct {
Meta
StateMeta
}

View File

@ -20,11 +20,9 @@ func TestStatePush_empty(t *testing.T) {
p := testProvider()
ui := new(cli.MockUi)
c := &StatePushCommand{
StateMeta: StateMeta{
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
}
@ -51,11 +49,9 @@ func TestStatePush_replaceMatch(t *testing.T) {
p := testProvider()
ui := new(cli.MockUi)
c := &StatePushCommand{
StateMeta: StateMeta{
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
}
@ -82,11 +78,9 @@ func TestStatePush_lineageMismatch(t *testing.T) {
p := testProvider()
ui := new(cli.MockUi)
c := &StatePushCommand{
StateMeta: StateMeta{
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
}
@ -113,11 +107,9 @@ func TestStatePush_serialNewer(t *testing.T) {
p := testProvider()
ui := new(cli.MockUi)
c := &StatePushCommand{
StateMeta: StateMeta{
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
}
@ -144,11 +136,9 @@ func TestStatePush_serialOlder(t *testing.T) {
p := testProvider()
ui := new(cli.MockUi)
c := &StatePushCommand{
StateMeta: StateMeta{
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
}

View File

@ -9,6 +9,7 @@ import (
// StateRmCommand is a Command implementation that shows a single resource.
type StateRmCommand struct {
Meta
StateMeta
}

View File

@ -46,11 +46,9 @@ func TestStateRm(t *testing.T) {
p := testProvider()
ui := new(cli.MockUi)
c := &StateRmCommand{
StateMeta: StateMeta{
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
}
@ -114,11 +112,9 @@ func TestStateRm_backupExplicit(t *testing.T) {
p := testProvider()
ui := new(cli.MockUi)
c := &StateRmCommand{
StateMeta: StateMeta{
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
}
@ -150,11 +146,9 @@ func TestStateRm_noState(t *testing.T) {
p := testProvider()
ui := new(cli.MockUi)
c := &StateRmCommand{
StateMeta: StateMeta{
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
}

View File

@ -12,6 +12,7 @@ import (
// StateShowCommand is a Command implementation that shows a single resource.
type StateShowCommand struct {
Meta
StateMeta
}

View File

@ -34,11 +34,9 @@ func TestStateShow(t *testing.T) {
p := testProvider()
ui := new(cli.MockUi)
c := &StateShowCommand{
StateMeta: StateMeta{
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
}
@ -94,11 +92,9 @@ func TestStateShow_multi(t *testing.T) {
p := testProvider()
ui := new(cli.MockUi)
c := &StateShowCommand{
StateMeta: StateMeta{
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
}
@ -118,11 +114,9 @@ func TestStateShow_noState(t *testing.T) {
p := testProvider()
ui := new(cli.MockUi)
c := &StateShowCommand{
StateMeta: StateMeta{
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
}
@ -140,11 +134,9 @@ func TestStateShow_emptyState(t *testing.T) {
p := testProvider()
ui := new(cli.MockUi)
c := &StateShowCommand{
StateMeta: StateMeta{
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
}
@ -171,11 +163,9 @@ func TestStateShow_emptyStateWithModule(t *testing.T) {
p := testProvider()
ui := new(cli.MockUi)
c := &StateShowCommand{
StateMeta: StateMeta{
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
}

View File

@ -46,11 +46,6 @@ func init() {
"debug": struct{}{}, // includes all subcommands
}
// meta struct used in state commands
stateMeta := command.StateMeta{
Meta: meta,
}
Commands = map[string]cli.CommandFactory{
"apply": func() (cli.Command, error) {
return &command.ApplyCommand{
@ -221,44 +216,42 @@ func init() {
},
"state": func() (cli.Command, error) {
return &command.StateCommand{
StateMeta: stateMeta,
}, nil
return &command.StateCommand{}, nil
},
"state list": func() (cli.Command, error) {
return &command.StateListCommand{
StateMeta: stateMeta,
Meta: meta,
}, nil
},
"state rm": func() (cli.Command, error) {
return &command.StateRmCommand{
StateMeta: stateMeta,
Meta: meta,
}, nil
},
"state mv": func() (cli.Command, error) {
return &command.StateMvCommand{
StateMeta: stateMeta,
Meta: meta,
}, nil
},
"state pull": func() (cli.Command, error) {
return &command.StatePullCommand{
StateMeta: stateMeta,
Meta: meta,
}, nil
},
"state push": func() (cli.Command, error) {
return &command.StatePushCommand{
StateMeta: stateMeta,
Meta: meta,
}, nil
},
"state show": func() (cli.Command, error) {
return &command.StateShowCommand{
StateMeta: stateMeta,
Meta: meta,
}, nil
},
}