core: tweaks from code review
This commit is contained in:
parent
6e13aacefa
commit
f1c9e32fa0
|
@ -22,7 +22,8 @@ func (n *EvalReadState) Eval(ctx EvalContext) (interface{}, error) {
|
||||||
type EvalReadStateTainted struct {
|
type EvalReadStateTainted struct {
|
||||||
Name string
|
Name string
|
||||||
Output **InstanceState
|
Output **InstanceState
|
||||||
// Index indicates which instance in the Tainted list to target, or -1 for the last item.
|
// Index indicates which instance in the Tainted list to target, or -1 for
|
||||||
|
// the last item.
|
||||||
Index int
|
Index int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +47,8 @@ func (n *EvalReadStateTainted) Eval(ctx EvalContext) (interface{}, error) {
|
||||||
type EvalReadStateDeposed struct {
|
type EvalReadStateDeposed struct {
|
||||||
Name string
|
Name string
|
||||||
Output **InstanceState
|
Output **InstanceState
|
||||||
// Index indicates which instance in the Deposed list to target, or -1 for the last item.
|
// Index indicates which instance in the Deposed list to target, or -1 for
|
||||||
|
// the last item.
|
||||||
Index int
|
Index int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +74,7 @@ func readInstanceFromState(
|
||||||
ctx EvalContext,
|
ctx EvalContext,
|
||||||
resourceName string,
|
resourceName string,
|
||||||
output **InstanceState,
|
output **InstanceState,
|
||||||
reader func(*ResourceState) (*InstanceState, error),
|
readerFn func(*ResourceState) (*InstanceState, error),
|
||||||
) (*InstanceState, error) {
|
) (*InstanceState, error) {
|
||||||
state, lock := ctx.State()
|
state, lock := ctx.State()
|
||||||
|
|
||||||
|
@ -93,7 +95,7 @@ func readInstanceFromState(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use the delegate function to get the instance state from the resource state
|
// Use the delegate function to get the instance state from the resource state
|
||||||
is, err := reader(rs)
|
is, err := readerFn(rs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -224,7 +226,7 @@ func writeInstanceToState(
|
||||||
resourceName string,
|
resourceName string,
|
||||||
resourceType string,
|
resourceType string,
|
||||||
dependencies []string,
|
dependencies []string,
|
||||||
writer func(*ResourceState) error,
|
writerFn func(*ResourceState) error,
|
||||||
) (*InstanceState, error) {
|
) (*InstanceState, error) {
|
||||||
state, lock := ctx.State()
|
state, lock := ctx.State()
|
||||||
if state == nil {
|
if state == nil {
|
||||||
|
@ -251,7 +253,7 @@ func writeInstanceToState(
|
||||||
rs.Type = resourceType
|
rs.Type = resourceType
|
||||||
rs.Dependencies = dependencies
|
rs.Dependencies = dependencies
|
||||||
|
|
||||||
if err := writer(rs); err != nil {
|
if err := writerFn(rs); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,8 +363,9 @@ func (n *EvalUndeposeState) Eval(ctx EvalContext) (interface{}, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Undepose
|
// Undepose
|
||||||
rs.Primary = rs.Deposed[len(rs.Deposed)-1]
|
idx := len(rs.Deposed) - 1
|
||||||
rs.Deposed = rs.Deposed[:len(rs.Deposed)-1]
|
rs.Primary = rs.Deposed[idx]
|
||||||
|
rs.Deposed[idx] = nil
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,13 +169,10 @@ func TestEvalWriteState(t *testing.T) {
|
||||||
t.Fatalf("Got err: %#v", err)
|
t.Fatalf("Got err: %#v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
rs := state.ModuleByPath(ctx.Path()).Resources["restype.resname"]
|
checkStateString(t, state, `
|
||||||
if rs.Type != "restype" {
|
restype.resname:
|
||||||
t.Fatalf("expected type 'restype': %#v", rs)
|
ID = i-abc123
|
||||||
}
|
`)
|
||||||
if rs.Primary.ID != "i-abc123" {
|
|
||||||
t.Fatalf("expected primary instance to have ID 'i-abc123': %#v", rs)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEvalWriteStateTainted(t *testing.T) {
|
func TestEvalWriteStateTainted(t *testing.T) {
|
||||||
|
@ -197,10 +194,11 @@ func TestEvalWriteStateTainted(t *testing.T) {
|
||||||
t.Fatalf("Got err: %#v", err)
|
t.Fatalf("Got err: %#v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
rs := state.ModuleByPath(ctx.Path()).Resources["restype.resname"]
|
checkStateString(t, state, `
|
||||||
if len(rs.Tainted) != 1 || rs.Tainted[0].ID != "i-abc123" {
|
restype.resname: (1 tainted)
|
||||||
t.Fatalf("expected tainted instance to have ID 'i-abc123': %#v", rs)
|
ID = <not created>
|
||||||
}
|
Tainted ID 1 = i-abc123
|
||||||
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEvalWriteStateDeposed(t *testing.T) {
|
func TestEvalWriteStateDeposed(t *testing.T) {
|
||||||
|
@ -222,8 +220,9 @@ func TestEvalWriteStateDeposed(t *testing.T) {
|
||||||
t.Fatalf("Got err: %#v", err)
|
t.Fatalf("Got err: %#v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
rs := state.ModuleByPath(ctx.Path()).Resources["restype.resname"]
|
checkStateString(t, state, `
|
||||||
if len(rs.Deposed) != 1 || rs.Deposed[0].ID != "i-abc123" {
|
restype.resname: (1 deposed)
|
||||||
t.Fatalf("expected deposed instance to have ID 'i-abc123': %#v", rs)
|
ID = <not created>
|
||||||
}
|
Deposed ID 1 = i-abc123
|
||||||
|
`)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue