From a7f948ab901355bd6fa813afd09c1d6ceb627365 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Thu, 6 Sep 2018 16:54:33 -0700 Subject: [PATCH] core: Fix TestContext2Apply_unstable We now handle impure functions by having them return an unknown value during plan, since we can't predict what the value will be during apply. This test was assuming the old behavior. --- terraform/context_apply_test.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index 689278690..1741a9fa7 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -102,8 +102,9 @@ func TestContext2Apply_unstable(t *testing.T) { if err != nil { t.Fatal(err) } - randomVal := rd.After.GetAttr("random").AsString() - t.Logf("plan-time value is %q", randomVal) + if rd.After.GetAttr("random").IsKnown() { + t.Fatalf("Attribute 'random' has known value %#v; should be unknown in plan", rd.After.GetAttr("random")) + } state, diags := ctx.Apply() if diags.HasErrors() { @@ -118,12 +119,12 @@ func TestContext2Apply_unstable(t *testing.T) { } rs, err := rss.Current.Decode(schema.ImpliedType()) - if got, want := rs.Value.GetAttr("random").AsString(), randomVal; got != want { - // FIXME: We actually currently have a bug where we re-interpolate - // the config during apply and end up with a random result, so this - // check fails. This check _should not_ fail, so we should fix this - // up in a later release. - //t.Errorf("wrong random value %q; want %q", got, want) + got := rs.Value.GetAttr("random") + if !got.IsKnown() { + t.Fatalf("random is still unknown after apply") + } + if got, want := len(got.AsString()), 1; got != want { + t.Fatalf("random string has wrong length %d; want %d", got, want) } }