Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8b42001
go mod tidy
Jun 7, 2021
0feb137
Make GetProviderSchema use our schema type.
Jun 7, 2021
9130b47
Stub out a config type.
Jun 7, 2021
19b9daa
Stub out support for getting the tftypes.Type from a schema.
Jun 7, 2021
04cdfca
Start implementing a provider server.
Jun 7, 2021
339c341
More todos
Jun 8, 2021
738689e
Flesh out serving more, add internal/proto6 package.
Jun 9, 2021
a70c606
Fill in rest of schema fields.
Jun 9, 2021
e1d8409
Fill out PlanResourceChange a bit more.
Jun 9, 2021
a3af286
Fill in TODOs.
Jun 11, 2021
7370bea
Populate ARC request values.
Jun 11, 2021
7300730
Debug why we're getting a null state on read resource.
Jun 11, 2021
1ea7759
Final fixes and tweaks to make it actually work.
Jun 11, 2021
72b60f5
Add some unit testing.
Jun 16, 2021
1c84d8d
Add changelog, fix lint and broken test.
Jun 16, 2021
972b552
Return error instead of panicking.
Jun 16, 2021
895395d
Populate response state's schema so it can be set.
Jun 16, 2021
508bc1a
Add State.RemoveResourceFromState.
Jun 16, 2021
475679c
Don't panic reflecting into large numbers.
Jun 16, 2021
715758a
Start testing schema endpoint.
Jun 18, 2021
cdb3072
Test our internal/proto6 package.
Jun 21, 2021
2a31650
Refactor request type tests.
Jun 21, 2021
919e3de
More testing of serve code.
Jun 22, 2021
289de7f
gofmt
Jun 22, 2021
56fb4f2
Test ConfigureProvider.
Jun 22, 2021
b0ead17
Test unknown values in ConfigureProvider.
Jun 22, 2021
f302b9d
Round out testing on read resource for test_one.
Jun 23, 2021
a4907f1
Test resource type two, test read resource diags.
Jun 23, 2021
90dd3f6
Add tests for PlanResourceChange.
Jun 23, 2021
0385632
Begin testing ApplyResourceChange.
Jun 23, 2021
e7bd27a
Test ApplyResourceChange.
Jun 23, 2021
d9ca589
Fix build after ResourceType interface change.
Jun 23, 2021
63d5e62
Finish testing read data source.
Jun 23, 2021
c8dd7af
Update internal/proto6/request_type.go
Jun 24, 2021
030bc75
Update internal/proto6/request_type.go
Jun 24, 2021
aedc8d6
Fix data source signatures.
Jun 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor request type tests.
A little less repetition.
  • Loading branch information
Paddy Carver committed Jun 24, 2021
commit 2a3165067c60d02fac9e9fd92407c4759bef009d
184 changes: 24 additions & 160 deletions internal/proto6/request_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import (
"github.com/hashicorp/terraform-plugin-go/tftypes"
)

func TestIsCreate(t *testing.T) {
func TestRequestType(t *testing.T) {
t.Parallel()

type testCase struct {
req *tfprotov6.ApplyResourceChangeRequest
typ tftypes.Type
expected bool
isCreate bool
isUpdate bool
isDestroy bool
expectedErr string
}

Expand Down Expand Up @@ -49,26 +51,32 @@ func TestIsCreate(t *testing.T) {
PriorState: &nullDV,
PlannedState: &setDV,
},
typ: reqType,
expected: true,
typ: reqType,
isCreate: true,
isUpdate: false,
isDestroy: false,
},
"set-prior-state-set-planned-state": {
req: &tfprotov6.ApplyResourceChangeRequest{
TypeName: "foo",
PriorState: &setDV,
PlannedState: &setDV,
},
typ: reqType,
expected: false,
typ: reqType,
isCreate: false,
isUpdate: true,
isDestroy: false,
},
"set-prior-state-null-planned-state": {
req: &tfprotov6.ApplyResourceChangeRequest{
TypeName: "foo",
PriorState: &setDV,
PlannedState: &nullDV,
},
typ: reqType,
expected: false,
typ: reqType,
isCreate: false,
isUpdate: false,
isDestroy: true,
},
}

Expand All @@ -94,84 +102,12 @@ func TestIsCreate(t *testing.T) {
t.Errorf("Expected error to be %q, got nil", tc.expectedErr)
return
}
if tc.expected != got {
t.Errorf("Expected %v, got %v", tc.expected, got)
if tc.isCreate != got {
t.Errorf("Expected IsCreate to return %v, got %v", tc.isCreate, got)
return
}
})
}
}

func TestIsUpdate(t *testing.T) {
t.Parallel()

type testCase struct {
req *tfprotov6.ApplyResourceChangeRequest
typ tftypes.Type
expected bool
expectedErr string
}

reqType := tftypes.Object{
AttributeTypes: map[string]tftypes.Type{
"a": tftypes.String,
"b": tftypes.Number,
"c": tftypes.Bool,
},
}

setDV, err := tfprotov6.NewDynamicValue(reqType, tftypes.NewValue(reqType, map[string]tftypes.Value{
"a": tftypes.NewValue(tftypes.String, "hello, world"),
"b": tftypes.NewValue(tftypes.Number, 123),
"c": tftypes.NewValue(tftypes.Bool, true),
}))
if err != nil {
t.Errorf("Unexpected error creating set dynamic value: %s", err)
return
}

nullDV, err := tfprotov6.NewDynamicValue(reqType, tftypes.NewValue(reqType, nil))
if err != nil {
t.Errorf("Unexpected error creating null dynamic value: %s", err)
return
}

tests := map[string]testCase{
"null-prior-state-set-planned-state": {
req: &tfprotov6.ApplyResourceChangeRequest{
TypeName: "foo",
PriorState: &nullDV,
PlannedState: &setDV,
},
typ: reqType,
expected: false,
},
"set-prior-state-set-planned-state": {
req: &tfprotov6.ApplyResourceChangeRequest{
TypeName: "foo",
PriorState: &setDV,
PlannedState: &setDV,
},
typ: reqType,
expected: true,
},
"set-prior-state-null-planned-state": {
req: &tfprotov6.ApplyResourceChangeRequest{
TypeName: "foo",
PriorState: &setDV,
PlannedState: &nullDV,
},
typ: reqType,
expected: false,
},
}

for name, tc := range tests {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
t.Parallel()

got, err := IsUpdate(context.Background(), tc.req, tc.typ)
got, err = IsUpdate(context.Background(), tc.req, tc.typ)
if err != nil {
if tc.expectedErr == "" {
t.Errorf("Unexpected error: %s", err)
Expand All @@ -188,84 +124,12 @@ func TestIsUpdate(t *testing.T) {
t.Errorf("Expected error to be %q, got nil", tc.expectedErr)
return
}
if tc.expected != got {
t.Errorf("Expected %v, got %v", tc.expected, got)
if tc.isUpdate != got {
t.Errorf("Expected IsUpdate to return %v, got %v", tc.isUpdate, got)
return
}
})
}
}

func TestIsDestroy(t *testing.T) {
t.Parallel()

type testCase struct {
req *tfprotov6.ApplyResourceChangeRequest
typ tftypes.Type
expected bool
expectedErr string
}

reqType := tftypes.Object{
AttributeTypes: map[string]tftypes.Type{
"a": tftypes.String,
"b": tftypes.Number,
"c": tftypes.Bool,
},
}

setDV, err := tfprotov6.NewDynamicValue(reqType, tftypes.NewValue(reqType, map[string]tftypes.Value{
"a": tftypes.NewValue(tftypes.String, "hello, world"),
"b": tftypes.NewValue(tftypes.Number, 123),
"c": tftypes.NewValue(tftypes.Bool, true),
}))
if err != nil {
t.Errorf("Unexpected error creating set dynamic value: %s", err)
return
}

nullDV, err := tfprotov6.NewDynamicValue(reqType, tftypes.NewValue(reqType, nil))
if err != nil {
t.Errorf("Unexpected error creating null dynamic value: %s", err)
return
}

tests := map[string]testCase{
"null-prior-state-set-planned-state": {
req: &tfprotov6.ApplyResourceChangeRequest{
TypeName: "foo",
PriorState: &nullDV,
PlannedState: &setDV,
},
typ: reqType,
expected: false,
},
"set-prior-state-set-planned-state": {
req: &tfprotov6.ApplyResourceChangeRequest{
TypeName: "foo",
PriorState: &setDV,
PlannedState: &setDV,
},
typ: reqType,
expected: false,
},
"set-prior-state-null-planned-state": {
req: &tfprotov6.ApplyResourceChangeRequest{
TypeName: "foo",
PriorState: &setDV,
PlannedState: &nullDV,
},
typ: reqType,
expected: true,
},
}

for name, tc := range tests {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
t.Parallel()

got, err := IsDestroy(context.Background(), tc.req, tc.typ)
got, err = IsDestroy(context.Background(), tc.req, tc.typ)
if err != nil {
if tc.expectedErr == "" {
t.Errorf("Unexpected error: %s", err)
Expand All @@ -282,8 +146,8 @@ func TestIsDestroy(t *testing.T) {
t.Errorf("Expected error to be %q, got nil", tc.expectedErr)
return
}
if tc.expected != got {
t.Errorf("Expected %v, got %v", tc.expected, got)
if tc.isDestroy != got {
t.Errorf("Expected IsDestroy to return %v, got %v", tc.isDestroy, got)
return
}
})
Expand Down