Skip to content

Commit

Permalink
refactor: ops (#23)
Browse files Browse the repository at this point in the history
* refactor: ops

* test: coverage+

* test: fix TestKey

* test: ops coverage

* test: remove check testdata

* test: ops copver 100

* docs: more docs
  • Loading branch information
matt-FFFFFF authored May 16, 2023
1 parent f7c4470 commit 05315d1
Show file tree
Hide file tree
Showing 15 changed files with 689 additions and 759 deletions.
10 changes: 10 additions & 0 deletions check/inplan.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ func (p PlanType) NumberOfResourcesEquals(expected int) *testerror.Error {
}
return nil
}

// That returns a ThatType which can be used for more fluent assertions for a given resource.
func (p PlanType) That(resourceName string) ThatType {
t := ThatType{
Plan: p.Plan,
ResourceName: resourceName,
}
t.exists()
return t
}
38 changes: 34 additions & 4 deletions check/inplan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,50 @@ import (

"github.com/gruntwork-io/terratest/modules/terraform"
tfjson "github.com/hashicorp/terraform-json"
"github.com/stretchr/testify/assert"
)

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

pt := mockPlanType()
pt.NumberOfResourcesEquals(2).ErrorIsNil(t)
err := pt.NumberOfResourcesEquals(2).AsError()
assert.NoError(t, err)
err = pt.NumberOfResourcesEquals(1).AsError()
assert.ErrorContains(t, err, "expected 1 resources, got")
}

func TestNumberOfResourcesInPlanWithError(t *testing.T) {
func TestInPlan(t *testing.T) {
t.Parallel()
ps := mockPlanStruct()
ip := InPlan(ps)
assert.Equal(t, ps, ip.Plan)
}

pt := mockPlanType()
pt.NumberOfResourcesEquals(1).ErrorContains(t, "expected 1 resources, got")
func TestThat(t *testing.T) {
t.Parallel()

mock := mockPlanType()
t.Run("Exists", func(t *testing.T) {
t.Parallel()
tt := mock.That("test_resource")
assert.True(t, tt.exists())
})

t.Run("NotExists", func(t *testing.T) {
t.Parallel()
tt := mock.That("not_exist")
assert.False(t, tt.exists())
})
}

func mockPlanStruct() *terraform.PlanStruct {
return &terraform.PlanStruct{
ResourcePlannedValuesMap: map[string]*tfjson.StateResource{
"test_resource": {},
"test_resource2": {},
},
}
}

func mockPlanType() PlanType {
Expand Down
183 changes: 0 additions & 183 deletions check/key.go

This file was deleted.

Loading

0 comments on commit 05315d1

Please sign in to comment.