mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-19 17:59:05 -05:00
Fix lint issues in internal/tofu (#2790)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com> Co-authored-by: Martin Atkins <mart@degeneration.co.uk>
This commit is contained in:
@@ -306,7 +306,7 @@ func (c *Context) watchStop(walker *ContextGraphWalker) (chan struct{}, <-chan s
|
||||
// We ignore the error for now since there isn't any reasonable
|
||||
// action to take if there is an error here, since the stop is still
|
||||
// advisory: OpenTofu will exit once the graph node completes.
|
||||
p.Stop()
|
||||
_ = p.Stop()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,7 +323,7 @@ func (c *Context) watchStop(walker *ContextGraphWalker) (chan struct{}, <-chan s
|
||||
// We ignore the error for now since there isn't any reasonable
|
||||
// action to take if there is an error here, since the stop is still
|
||||
// advisory: OpenTofu will exit once the graph node completes.
|
||||
p.Stop()
|
||||
_ = p.Stop()
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -1540,41 +1540,42 @@ output "out" {
|
||||
|
||||
_, diags = ctx.Plan(context.Background(), m, state, opts)
|
||||
assertNoErrors(t, diags)
|
||||
return
|
||||
// TODO: unreachable code
|
||||
otherProvider.ConfigureProviderCalled = false
|
||||
otherProvider.ConfigureProviderFn = func(req providers.ConfigureProviderRequest) (resp providers.ConfigureProviderResponse) {
|
||||
// check that our config is complete, even during a destroy plan
|
||||
expected := cty.ObjectVal(map[string]cty.Value{
|
||||
"local": cty.ListVal([]cty.Value{cty.StringVal("first-ok"), cty.StringVal("second-ok")}),
|
||||
"output": cty.ListVal([]cty.Value{cty.StringVal("first-ok"), cty.StringVal("second-ok")}),
|
||||
"var": cty.MapVal(map[string]cty.Value{
|
||||
"a": cty.StringVal("first"),
|
||||
"b": cty.StringVal("second"),
|
||||
}),
|
||||
})
|
||||
if 1 == 0 {
|
||||
otherProvider.ConfigureProviderCalled = false
|
||||
otherProvider.ConfigureProviderFn = func(req providers.ConfigureProviderRequest) (resp providers.ConfigureProviderResponse) {
|
||||
// check that our config is complete, even during a destroy plan
|
||||
expected := cty.ObjectVal(map[string]cty.Value{
|
||||
"local": cty.ListVal([]cty.Value{cty.StringVal("first-ok"), cty.StringVal("second-ok")}),
|
||||
"output": cty.ListVal([]cty.Value{cty.StringVal("first-ok"), cty.StringVal("second-ok")}),
|
||||
"var": cty.MapVal(map[string]cty.Value{
|
||||
"a": cty.StringVal("first"),
|
||||
"b": cty.StringVal("second"),
|
||||
}),
|
||||
})
|
||||
|
||||
if !req.Config.RawEquals(expected) {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf(
|
||||
`incorrect provider config:
|
||||
if !req.Config.RawEquals(expected) {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf(
|
||||
`incorrect provider config:
|
||||
expected: %#v
|
||||
got: %#v`,
|
||||
expected, req.Config))
|
||||
expected, req.Config))
|
||||
}
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
return resp
|
||||
}
|
||||
opts.Mode = plans.DestroyMode
|
||||
// skip refresh so that we don't configure the provider before the destroy plan
|
||||
opts.SkipRefresh = true
|
||||
|
||||
opts.Mode = plans.DestroyMode
|
||||
// skip refresh so that we don't configure the provider before the destroy plan
|
||||
opts.SkipRefresh = true
|
||||
// destroy only a single instance not included in the moved statements
|
||||
_, diags = ctx.Plan(context.Background(), m, state, opts)
|
||||
assertNoErrors(t, diags)
|
||||
|
||||
// destroy only a single instance not included in the moved statements
|
||||
_, diags = ctx.Plan(context.Background(), m, state, opts)
|
||||
assertNoErrors(t, diags)
|
||||
|
||||
if !otherProvider.ConfigureProviderCalled {
|
||||
t.Fatal("failed to configure provider during destroy plan")
|
||||
if !otherProvider.ConfigureProviderCalled {
|
||||
t.Fatal("failed to configure provider during destroy plan")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -926,7 +926,7 @@ func TestContext2Apply_emptyModule(t *testing.T) {
|
||||
}
|
||||
|
||||
actual := strings.TrimSpace(state.String())
|
||||
actual = strings.Replace(actual, " ", "", -1)
|
||||
actual = strings.ReplaceAll(actual, " ", "")
|
||||
expected := strings.TrimSpace(testTofuApplyEmptyModuleStr)
|
||||
if actual != expected {
|
||||
t.Fatalf("bad: \n%s\nexpect:\n%s", actual, expected)
|
||||
@@ -1938,10 +1938,8 @@ func TestContext2Apply_cancel(t *testing.T) {
|
||||
stopped = true
|
||||
go ctx.Stop()
|
||||
|
||||
for {
|
||||
if ctx.sh.Stopped() {
|
||||
break
|
||||
}
|
||||
for !ctx.sh.Stopped() {
|
||||
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4284,15 +4284,16 @@ output "a" {
|
||||
}
|
||||
for _, diag := range diags {
|
||||
desc := diag.Description()
|
||||
if desc.Summary == "Module output value precondition failed" {
|
||||
switch desc.Summary {
|
||||
case "Module output value precondition failed":
|
||||
if got, want := desc.Detail, "This check failed, but has an invalid error message as described in the other accompanying messages."; !strings.Contains(got, want) {
|
||||
t.Errorf("unexpected detail\ngot: %s\nwant to contain %q", got, want)
|
||||
}
|
||||
} else if desc.Summary == "Error message refers to sensitive values" {
|
||||
case "Error message refers to sensitive values":
|
||||
if got, want := desc.Detail, "The error expression used to explain this condition refers to sensitive values, so OpenTofu will not display the resulting message."; !strings.Contains(got, want) {
|
||||
t.Errorf("unexpected detail\ngot: %s\nwant to contain %q", got, want)
|
||||
}
|
||||
} else {
|
||||
default:
|
||||
t.Errorf("unexpected summary\ngot: %s", desc.Summary)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -677,7 +677,7 @@ func (n *NodeAbstractResourceInstance) readResourceInstanceStateDeposed(evalCtx
|
||||
func graphNodesAreResourceInstancesInDifferentInstancesOfSameModule(a, b dag.Vertex) bool {
|
||||
aRI, aOK := a.(GraphNodeResourceInstance)
|
||||
bRI, bOK := b.(GraphNodeResourceInstance)
|
||||
if !(aOK && bOK) {
|
||||
if !aOK || !bOK {
|
||||
return false
|
||||
}
|
||||
aModInst := aRI.ResourceInstanceAddr().Module
|
||||
|
||||
@@ -2353,7 +2353,8 @@ func (n *NodeAbstractResourceInstance) applyProvisioners(ctx EvalContext, state
|
||||
|
||||
// The output function
|
||||
outputFn := func(msg string) {
|
||||
ctx.Hook(func(h Hook) (HookAction, error) {
|
||||
// Given that we return nil below, this will never error
|
||||
_ = ctx.Hook(func(h Hook) (HookAction, error) {
|
||||
h.ProvisionOutput(n.Addr, prov.Type, msg)
|
||||
return HookActionContinue, nil
|
||||
})
|
||||
@@ -2372,7 +2373,8 @@ func (n *NodeAbstractResourceInstance) applyProvisioners(ctx EvalContext, state
|
||||
// provisioners ought not to be logging anyway.
|
||||
if _, hasSensitive := configMarks[marks.Sensitive]; hasSensitive {
|
||||
outputFn = func(msg string) {
|
||||
ctx.Hook(func(h Hook) (HookAction, error) {
|
||||
// Given that we return nil below, this will never error
|
||||
_ = ctx.Hook(func(h Hook) (HookAction, error) {
|
||||
h.ProvisionOutput(n.Addr, prov.Type, "(output suppressed due to sensitive value in config)")
|
||||
return HookActionContinue, nil
|
||||
})
|
||||
@@ -2500,7 +2502,8 @@ func (n *NodeAbstractResourceInstance) apply(
|
||||
// such a rare error, we can just drop the raw GoString values in here
|
||||
// to make sure we have something to debug with.
|
||||
var unknownPaths []string
|
||||
cty.Transform(configVal, func(p cty.Path, v cty.Value) (cty.Value, error) {
|
||||
// We don't care about the error return here as it's only to help build a more detailed error message
|
||||
_, _ = cty.Transform(configVal, func(p cty.Path, v cty.Value) (cty.Value, error) {
|
||||
if !v.IsKnown() {
|
||||
unknownPaths = append(unknownPaths, fmt.Sprintf("%#v", p))
|
||||
}
|
||||
@@ -2641,7 +2644,8 @@ func (n *NodeAbstractResourceInstance) apply(
|
||||
// To generate better error messages, we'll go for a walk through the
|
||||
// value and make a separate diagnostic for each unknown value we
|
||||
// find.
|
||||
cty.Walk(newVal, func(path cty.Path, val cty.Value) (bool, error) {
|
||||
// We don't care about the error return here as it's only to help build a more detailed error message
|
||||
_ = cty.Walk(newVal, func(path cty.Path, val cty.Value) (bool, error) {
|
||||
if !val.IsKnown() {
|
||||
pathStr := tfdiags.FormatCtyPath(path)
|
||||
diags = diags.Append(tfdiags.Sourceless(
|
||||
|
||||
@@ -353,7 +353,7 @@ func TestNodeAbstractResource_ReadResourceInstanceState(t *testing.T) {
|
||||
|
||||
expected := test.ExpectedInstanceId
|
||||
|
||||
if !(got != nil && got.Value.GetAttr("id") == cty.StringVal(expected)) {
|
||||
if got == nil || got.Value.GetAttr("id") != cty.StringVal(expected) {
|
||||
t.Fatalf("[%s] Expected output with ID %#v, got: %#v", test.Name, expected, got)
|
||||
}
|
||||
})
|
||||
@@ -401,7 +401,7 @@ func TestNodeAbstractResource_ReadResourceInstanceState(t *testing.T) {
|
||||
|
||||
expected := test.ExpectedInstanceId
|
||||
|
||||
if !(got != nil && got.Value.GetAttr("id") == cty.StringVal(expected)) {
|
||||
if got == nil || got.Value.GetAttr("id") != cty.StringVal(expected) {
|
||||
t.Fatalf("[%s] Expected output with ID %#v, got: %#v", test.Name, expected, got)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -155,7 +155,7 @@ func TestNodeValidatableResource_ValidateProvisioner__connectionInvalid(t *testi
|
||||
}
|
||||
|
||||
errStr := diags.Err().Error()
|
||||
if !(strings.Contains(errStr, "bananananananana") && strings.Contains(errStr, "bazaz")) {
|
||||
if !strings.Contains(errStr, "bananananananana") || !strings.Contains(errStr, "bazaz") {
|
||||
t.Fatalf("wrong errors %q; want something about each of our invalid connInfo keys", errStr)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,11 +53,12 @@ func (t *AttachResourceConfigTransformer) Transform(_ context.Context, g *Graph)
|
||||
continue
|
||||
}
|
||||
var m map[string]*configs.Resource
|
||||
if addr.Resource.Mode == addrs.ManagedResourceMode {
|
||||
switch addr.Resource.Mode {
|
||||
case addrs.ManagedResourceMode:
|
||||
m = config.Module.ManagedResources
|
||||
} else if addr.Resource.Mode == addrs.DataResourceMode {
|
||||
case addrs.DataResourceMode:
|
||||
m = config.Module.DataResources
|
||||
} else {
|
||||
default:
|
||||
panic("unknown resource mode: " + addr.Resource.Mode.String())
|
||||
}
|
||||
coord := addr.Resource.String()
|
||||
|
||||
@@ -58,7 +58,9 @@ func TestModuleTransformAttachConfigTransformer(t *testing.T) {
|
||||
for _, attr := range attrs {
|
||||
val, _ := attr.Expr.Value(nil)
|
||||
var target int
|
||||
gocty.FromCtyValue(val, &target)
|
||||
if err := gocty.FromCtyValue(val, &target); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
values[attr.Name] = target
|
||||
}
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ func (t *DiffTransformer) Transform(_ context.Context, g *Graph) error {
|
||||
// A deposed instance may only have a change of Delete, Forget or NoOp.
|
||||
// A NoOp can happen if the provider shows it no longer exists during
|
||||
// the most recent ReadResource operation.
|
||||
if dk != states.NotDeposed && !(rc.Action == plans.Delete || rc.Action == plans.NoOp || rc.Action == plans.Forget) {
|
||||
if dk != states.NotDeposed && rc.Action != plans.Delete && rc.Action != plans.NoOp && rc.Action != plans.Forget {
|
||||
diags = diags.Append(tfdiags.Sourceless(
|
||||
tfdiags.Error,
|
||||
"Invalid planned change for deposed object",
|
||||
|
||||
Reference in New Issue
Block a user