From 49fe0d5c7f2f7914ba13460db2a0c713d7583354 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 13 Jan 2015 11:54:30 -0800 Subject: [PATCH] config: remove a lot of unused stuff --- config/interpolate.go | 51 ----------------------------- config/interpolate_test.go | 67 -------------------------------------- 2 files changed, 118 deletions(-) diff --git a/config/interpolate.go b/config/interpolate.go index 806bac24de..e6a709d945 100644 --- a/config/interpolate.go +++ b/config/interpolate.go @@ -8,16 +8,6 @@ import ( "github.com/hashicorp/terraform/config/lang/ast" ) -// Interpolation is something that can be contained in a "${}" in a -// configuration value. -// -// Interpolations might be simple variable references, or it might be -// function calls, or even nested function calls. -type Interpolation interface { - Interpolate(map[string]string) (string, error) - Variables() map[string]InterpolatedVariable -} - // An InterpolatedVariable is a variable reference within an interpolation. // // Implementations of this interface represents various sources where @@ -26,18 +16,6 @@ type InterpolatedVariable interface { FullKey() string } -// LiteralInterpolation implements Interpolation for literals. Ex: -// ${"foo"} will equal "foo". -type LiteralInterpolation struct { - Literal string -} - -// VariableInterpolation implements Interpolation for simple variable -// interpolation. Ex: "${var.foo}" or "${aws_instance.foo.bar}" -type VariableInterpolation struct { - Variable InterpolatedVariable -} - // CountVariable is a variable for referencing information about // the count. type CountVariable struct { @@ -114,35 +92,6 @@ func NewInterpolatedVariable(v string) (InterpolatedVariable, error) { } } -func (i *LiteralInterpolation) Interpolate( - map[string]string) (string, error) { - return i.Literal, nil -} - -func (i *LiteralInterpolation) Variables() map[string]InterpolatedVariable { - return nil -} - -func (i *VariableInterpolation) Interpolate( - vs map[string]string) (string, error) { - v, ok := vs[i.Variable.FullKey()] - if !ok { - return "", fmt.Errorf( - "%s: value for variable not found", - i.Variable.FullKey()) - } - - return v, nil -} - -func (i *VariableInterpolation) GoString() string { - return fmt.Sprintf("*%#v", *i) -} - -func (i *VariableInterpolation) Variables() map[string]InterpolatedVariable { - return map[string]InterpolatedVariable{i.Variable.FullKey(): i.Variable} -} - func NewCountVariable(key string) (*CountVariable, error) { var fieldType CountValueType parts := strings.SplitN(key, ".", 2) diff --git a/config/interpolate_test.go b/config/interpolate_test.go index 923ff660d9..46945ee810 100644 --- a/config/interpolate_test.go +++ b/config/interpolate_test.go @@ -122,29 +122,6 @@ func TestNewUserVariable_map(t *testing.T) { } } -func TestLiteralInterpolation_impl(t *testing.T) { - var _ Interpolation = new(LiteralInterpolation) -} - -func TestLiteralInterpolation(t *testing.T) { - i := &LiteralInterpolation{ - Literal: "bar", - } - - if i.Variables() != nil { - t.Fatalf("bad: %#v", i.Variables()) - } - - actual, err := i.Interpolate(nil) - if err != nil { - t.Fatalf("err: %s", err) - } - - if actual != "bar" { - t.Fatalf("bad: %#v", actual) - } -} - func TestResourceVariable_impl(t *testing.T) { var _ InterpolatedVariable = new(ResourceVariable) } @@ -201,50 +178,6 @@ func TestUserVariable_impl(t *testing.T) { var _ InterpolatedVariable = new(UserVariable) } -func TestVariableInterpolation_impl(t *testing.T) { - var _ Interpolation = new(VariableInterpolation) -} - -func TestVariableInterpolation(t *testing.T) { - uv, err := NewUserVariable("var.foo") - if err != nil { - t.Fatalf("err: %s", err) - } - - i := &VariableInterpolation{Variable: uv} - - expected := map[string]InterpolatedVariable{"var.foo": uv} - if !reflect.DeepEqual(i.Variables(), expected) { - t.Fatalf("bad: %#v", i.Variables()) - } - - actual, err := i.Interpolate(map[string]string{ - "var.foo": "bar", - }) - if err != nil { - t.Fatalf("err: %s", err) - } - - if actual != "bar" { - t.Fatalf("bad: %#v", actual) - } -} - -func TestVariableInterpolation_missing(t *testing.T) { - uv, err := NewUserVariable("var.foo") - if err != nil { - t.Fatalf("err: %s", err) - } - - i := &VariableInterpolation{Variable: uv} - _, err = i.Interpolate(map[string]string{ - "var.bar": "bar", - }) - if err == nil { - t.Fatal("should error") - } -} - func TestDetectVariables(t *testing.T) { cases := []struct { Input string