Skip to content

Commit

Permalink
Lint etc
Browse files Browse the repository at this point in the history
  • Loading branch information
t0yv0 committed Apr 11, 2024
1 parent 65915a7 commit 15521f7
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 26 deletions.
38 changes: 19 additions & 19 deletions pkg/tests/cross-tests/adapt.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ func (ta *typeAdapter) ToCty() cty.Type {
case t.Is(tftypes.Bool):
return cty.Bool
case t.Is(tftypes.List{}):
return cty.List(FromType(t.(tftypes.List).ElementType).ToCty())
return cty.List(fromType(t.(tftypes.List).ElementType).ToCty())
case t.Is(tftypes.Set{}):
return cty.Set(FromType(t.(tftypes.Set).ElementType).ToCty())
return cty.Set(fromType(t.(tftypes.Set).ElementType).ToCty())
case t.Is(tftypes.Map{}):
return cty.Map(FromType(t.(tftypes.Map).ElementType).ToCty())
return cty.Map(fromType(t.(tftypes.Map).ElementType).ToCty())
case t.Is(tftypes.Object{}):
fields := map[string]cty.Type{}
for k, v := range t.(tftypes.Object).AttributeTypes {
fields[k] = FromType(v).ToCty()
fields[k] = fromType(v).ToCty()
}
return cty.Object(fields)
default:
Expand All @@ -57,7 +57,7 @@ func (ta *typeAdapter) NewValue(value any) tftypes.Value {
case []any:
values := []tftypes.Value{}
for _, el := range v {
values = append(values, FromType(elT).NewValue(el))
values = append(values, fromType(elT).NewValue(el))
}
return tftypes.NewValue(t, values)
}
Expand All @@ -67,7 +67,7 @@ func (ta *typeAdapter) NewValue(value any) tftypes.Value {
case []any:
values := []tftypes.Value{}
for _, el := range v {
values = append(values, FromType(elT).NewValue(el))
values = append(values, fromType(elT).NewValue(el))
}
return tftypes.NewValue(t, values)
}
Expand All @@ -77,7 +77,7 @@ func (ta *typeAdapter) NewValue(value any) tftypes.Value {
case map[string]any:
values := map[string]tftypes.Value{}
for k, el := range v {
values[k] = FromType(elT).NewValue(el)
values[k] = fromType(elT).NewValue(el)
}
return tftypes.NewValue(t, values)
}
Expand All @@ -87,15 +87,15 @@ func (ta *typeAdapter) NewValue(value any) tftypes.Value {
case map[string]any:
values := map[string]tftypes.Value{}
for k, el := range v {
values[k] = FromType(aT[k]).NewValue(el)
values[k] = fromType(aT[k]).NewValue(el)
}
return tftypes.NewValue(t, values)
}
}
return tftypes.NewValue(t, value)
}

func FromType(t tftypes.Type) *typeAdapter {
func fromType(t tftypes.Type) *typeAdapter {
return &typeAdapter{t}
}

Expand All @@ -108,9 +108,9 @@ func (va *valueAdapter) ToCty() cty.Value {
t := v.Type()
switch {
case v.IsNull():
return cty.NullVal(FromType(t).ToCty())
return cty.NullVal(fromType(t).ToCty())
case !v.IsKnown():
return cty.UnknownVal(FromType(t).ToCty())
return cty.UnknownVal(fromType(t).ToCty())
case t.Is(tftypes.String):
var s string
err := v.As(&s)
Expand All @@ -131,35 +131,35 @@ func (va *valueAdapter) ToCty() cty.Value {
err := v.As(&vals)
contract.AssertNoErrorf(err, "unexpected error converting list")
if len(vals) == 0 {
return cty.ListValEmpty(FromType(t).ToCty())
return cty.ListValEmpty(fromType(t).ToCty())
}
outVals := make([]cty.Value, len(vals))
for i, el := range vals {
outVals[i] = FromValue(el).ToCty()
outVals[i] = fromValue(el).ToCty()
}
return cty.ListVal(outVals)
case t.Is(tftypes.Set{}):
var vals []tftypes.Value
err := v.As(&vals)
if len(vals) == 0 {
return cty.SetValEmpty(FromType(t).ToCty())
return cty.SetValEmpty(fromType(t).ToCty())
}
contract.AssertNoErrorf(err, "unexpected error converting set")
outVals := make([]cty.Value, len(vals))
for i, el := range vals {
outVals[i] = FromValue(el).ToCty()
outVals[i] = fromValue(el).ToCty()
}
return cty.SetVal(outVals)
case t.Is(tftypes.Map{}):
var vals map[string]tftypes.Value
err := v.As(&vals)
if len(vals) == 0 {
return cty.MapValEmpty(FromType(t).ToCty())
return cty.MapValEmpty(fromType(t).ToCty())
}
contract.AssertNoErrorf(err, "unexpected error converting map")
outVals := make(map[string]cty.Value, len(vals))
for k, el := range vals {
outVals[k] = FromValue(el).ToCty()
outVals[k] = fromValue(el).ToCty()
}
return cty.MapVal(outVals)
case t.Is(tftypes.Object{}):
Expand All @@ -171,7 +171,7 @@ func (va *valueAdapter) ToCty() cty.Value {
contract.AssertNoErrorf(err, "unexpected error converting object")
outVals := make(map[string]cty.Value, len(vals))
for k, el := range vals {
outVals[k] = FromValue(el).ToCty()
outVals[k] = fromValue(el).ToCty()
}
return cty.ObjectVal(outVals)
default:
Expand All @@ -180,6 +180,6 @@ func (va *valueAdapter) ToCty() cty.Value {
}
}

func FromValue(v tftypes.Value) *valueAdapter {
func fromValue(v tftypes.Value) *valueAdapter {
return &valueAdapter{v}
}
2 changes: 1 addition & 1 deletion pkg/tests/cross-tests/pretty.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (pp prettyPrinterForTypes) TypeReferenceString(t tftypes.Type) string {
func (pp prettyPrinterForTypes) TypeReference(w io.Writer, t tftypes.Type) {
switch {
case t.Is(tftypes.Object{}):
fmt.Fprintf(w, pp.TypeLiteral(t.(tftypes.Object)))
fmt.Fprintf(w, "%s", pp.TypeLiteral(t.(tftypes.Object)))
case t.Is(tftypes.List{}):
fmt.Fprintf(w, "tftypes.List{ElementType: ")
pp.TypeReference(w, t.(tftypes.List).ElementType)
Expand Down
2 changes: 1 addition & 1 deletion pkg/tests/cross-tests/rapid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func TestDiffConvergence(outerT *testing.T) {
_, ok := os.Getenv("PULUMI_EXPERIMENTAL")
_, ok := os.LookupEnv("PULUMI_EXPERIMENTAL")
if !ok {
outerT.Skip("TODO - we do not currently pass all cases; using this as an exploration tool")
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/tests/cross-tests/tf_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (d *tfDriver) coalesce(t T, x any) *tftypes.Value {
}
objectType := convert.InferObjectType(sdkv2.NewSchemaMap(d.res.Schema), nil)
t.Logf("infer object type: %v", objectType)
v := FromType(objectType).NewValue(x)
v := fromType(objectType).NewValue(x)
return &v
}

Expand All @@ -137,7 +137,8 @@ func (d *tfDriver) write(
config tftypes.Value,
) {
var buf bytes.Buffer
err := WriteHCL(&buf, resourceSchema, resourceType, resourceName, FromValue(config).ToCty())
err := WriteHCL(&buf, resourceSchema, resourceType, resourceName, fromValue(config).ToCty())
require.NoError(t, err)
t.Logf("HCL: \n%s\n", buf.String())
bytes := buf.Bytes()
err = os.WriteFile(filepath.Join(d.cwd, "test.tf"), bytes, 0600)
Expand Down
2 changes: 1 addition & 1 deletion pkg/tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ replace (
require (
github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0
github.com/hexops/autogold/v2 v2.2.1
github.com/hexops/valast v1.4.4
github.com/pulumi/providertest v0.0.12
github.com/pulumi/pulumi-terraform-bridge/v3 v3.80.0
github.com/stretchr/testify v1.8.4
Expand Down Expand Up @@ -54,7 +55,6 @@ require (
github.com/hashicorp/terraform-registry-address v0.2.3 // indirect
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
github.com/hexops/gotextdiff v1.0.3 // indirect
github.com/hexops/valast v1.4.4 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/iancoleman/strcase v0.2.0 // indirect
github.com/imdario/mergo v0.3.15 // indirect
Expand Down
4 changes: 2 additions & 2 deletions pkg/tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2792,8 +2792,8 @@ github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 h1:vkHw5I/plNdTr435
github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231/go.mod h1:murToZ2N9hNJzewjHBgfFdXhZKjY3z5cYC1VXk+lbFE=
github.com/pulumi/esc v0.6.2 h1:+z+l8cuwIauLSwXQS0uoI3rqB+YG4SzsZYtHfNoXBvw=
github.com/pulumi/esc v0.6.2/go.mod h1:jNnYNjzsOgVTjCp0LL24NsCk8ZJxq4IoLQdCT0X7l8k=
github.com/pulumi/providertest v0.0.11 h1:mg8MQ7Cq7+9XlHIkBD+aCqQO4mwAJEISngZgVdnQUe8=
github.com/pulumi/providertest v0.0.11/go.mod h1:HsxjVsytcMIuNj19w1lT2W0QXY0oReXl1+h6eD2JXP8=
github.com/pulumi/providertest v0.0.12 h1:UjcFQHHs4AGJyJqxhvC2q8yVQ7Li+UyCyP95HZcK03U=
github.com/pulumi/providertest v0.0.12/go.mod h1:REAoaN+hGOtdWJGirfWYqcSjCejlbGfzyVTUuemJTuE=
github.com/pulumi/pulumi-java/pkg v0.10.0 h1:D1i5MiiNrxYr2uJ1szcj1aQwF9DYv7TTsPmajB9dKSw=
github.com/pulumi/pulumi-java/pkg v0.10.0/go.mod h1:xu6UgYtQm+xXOo1/DZNa2CWVPytu+RMkZVTtI7w7ffY=
github.com/pulumi/pulumi-yaml v1.6.0 h1:mb/QkebWXTa1fR+P3ZkCCHGXOYC6iTN8X8By9eNz8xM=
Expand Down

0 comments on commit 15521f7

Please sign in to comment.