Skip to content

Commit

Permalink
Renaming BoolExact to Bool, and NullExact to Null (#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
bendbennett committed Jan 23, 2024
1 parent a88a10d commit 6d8f112
Show file tree
Hide file tree
Showing 18 changed files with 124 additions and 124 deletions.
18 changes: 9 additions & 9 deletions knownvalue/bool.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,37 @@ import (
"strconv"
)

var _ Check = boolExact{}
var _ Check = boolValue{}

type boolExact struct {
type boolValue struct {
value bool
}

// CheckValue determines whether the passed value is of type bool, and
// contains a matching bool value.
func (v boolExact) CheckValue(other any) error {
func (v boolValue) CheckValue(other any) error {
otherVal, ok := other.(bool)

if !ok {
return fmt.Errorf("expected bool value for BoolExact check, got: %T", other)
return fmt.Errorf("expected bool value for Bool check, got: %T", other)
}

if otherVal != v.value {
return fmt.Errorf("expected value %t for BoolExact check, got: %t", v.value, otherVal)
return fmt.Errorf("expected value %t for Bool check, got: %t", v.value, otherVal)
}

return nil
}

// String returns the string representation of the bool value.
func (v boolExact) String() string {
func (v boolValue) String() string {
return strconv.FormatBool(v.value)
}

// BoolExact returns a Check for asserting equality between the
// Bool returns a Check for asserting equality between the
// supplied bool and the value passed to the CheckValue method.
func BoolExact(value bool) boolExact {
return boolExact{
func Bool(value bool) boolValue {
return boolValue{
value: value,
}
}
22 changes: 11 additions & 11 deletions knownvalue/bool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,29 @@ func TestBoolValue_CheckValue(t *testing.T) {
expectedError error
}{
"zero-nil": {
self: knownvalue.BoolExact(false),
expectedError: fmt.Errorf("expected bool value for BoolExact check, got: <nil>"),
self: knownvalue.Bool(false),
expectedError: fmt.Errorf("expected bool value for Bool check, got: <nil>"),
},
"zero-other": {
self: knownvalue.BoolExact(false),
self: knownvalue.Bool(false),
other: false, // checking against the underlying value field zero-value
},
"nil": {
self: knownvalue.BoolExact(false),
expectedError: fmt.Errorf("expected bool value for BoolExact check, got: <nil>"),
self: knownvalue.Bool(false),
expectedError: fmt.Errorf("expected bool value for Bool check, got: <nil>"),
},
"wrong-type": {
self: knownvalue.BoolExact(true),
self: knownvalue.Bool(true),
other: 1.23,
expectedError: fmt.Errorf("expected bool value for BoolExact check, got: float64"),
expectedError: fmt.Errorf("expected bool value for Bool check, got: float64"),
},
"not-equal": {
self: knownvalue.BoolExact(true),
self: knownvalue.Bool(true),
other: false,
expectedError: fmt.Errorf("expected value true for BoolExact check, got: false"),
expectedError: fmt.Errorf("expected value true for Bool check, got: false"),
},
"equal": {
self: knownvalue.BoolExact(true),
self: knownvalue.Bool(true),
other: true,
},
}
Expand All @@ -66,7 +66,7 @@ func TestBoolValue_CheckValue(t *testing.T) {
func TestBoolValue_String(t *testing.T) {
t.Parallel()

got := knownvalue.BoolExact(true).String()
got := knownvalue.Bool(true).String()

if diff := cmp.Diff(got, "true"); diff != "" {
t.Errorf("unexpected difference: %s", diff)
Expand Down
16 changes: 8 additions & 8 deletions knownvalue/null.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ import (
"fmt"
)

var _ Check = nullExact{}
var _ Check = null{}

type nullExact struct{}
type null struct{}

// CheckValue determines whether the passed value is nil.
func (v nullExact) CheckValue(other any) error {
func (v null) CheckValue(other any) error {
if other != nil {
return fmt.Errorf("expected value nil for NullExact check, got: %T", other)
return fmt.Errorf("expected value nil for Null check, got: %T", other)
}

return nil
}

// String returns the string representation of null.
func (v nullExact) String() string {
func (v null) String() string {
return "null"
}

// NullExact returns a Check for asserting equality nil
// Null returns a Check for asserting equality nil
// and the value passed to the CheckValue method.
func NullExact() nullExact {
return nullExact{}
func Null() null {
return null{}
}
12 changes: 6 additions & 6 deletions knownvalue/null_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ func TestNullValue_CheckValue(t *testing.T) {
expectedError error
}{
"zero-nil": {
self: knownvalue.NullExact(),
self: knownvalue.Null(),
},
"zero-other": {
self: knownvalue.NullExact(),
self: knownvalue.Null(),
other: nil, // checking against the underlying value field zero-value
},
"not-nil": {
self: knownvalue.NullExact(),
self: knownvalue.Null(),
other: false,
expectedError: fmt.Errorf("expected value nil for NullExact check, got: bool"),
expectedError: fmt.Errorf("expected value nil for Null check, got: bool"),
},
"equal": {
self: knownvalue.NullExact(),
self: knownvalue.Null(),
other: nil,
},
}
Expand All @@ -56,7 +56,7 @@ func TestNullValue_CheckValue(t *testing.T) {
func TestNullValue_String(t *testing.T) {
t.Parallel()

got := knownvalue.NullExact().String()
got := knownvalue.Null().String()

if diff := cmp.Diff(got, "null"); diff != "" {
t.Errorf("unexpected difference: %s", diff)
Expand Down
26 changes: 13 additions & 13 deletions plancheck/expect_known_output_value_at_path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_ResourceNotFound(t *testing.T) {
plancheck.ExpectKnownOutputValueAtPath(
"test_resource_two_output",
tfjsonpath.New("bool_attribute"),
knownvalue.BoolExact(true),
knownvalue.Bool(true),
),
},
},
Expand Down Expand Up @@ -91,22 +91,22 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_AttributeValueNull(t *testing.T)
plancheck.ExpectKnownOutputValueAtPath(
"test_resource_one_output",
tfjsonpath.New("bool_attribute"),
knownvalue.NullExact(),
knownvalue.Null(),
),
plancheck.ExpectKnownOutputValueAtPath(
"test_resource_one_output",
tfjsonpath.New("float_attribute"),
knownvalue.NullExact(),
knownvalue.Null(),
),
plancheck.ExpectKnownOutputValueAtPath(
"test_resource_one_output",
tfjsonpath.New("int_attribute"),
knownvalue.NullExact(),
knownvalue.Null(),
),
plancheck.ExpectKnownOutputValueAtPath(
"test_resource_one_output",
tfjsonpath.New("list_attribute"),
knownvalue.NullExact(),
knownvalue.Null(),
),
plancheck.ExpectKnownOutputValueAtPath(
"test_resource_one_output",
Expand All @@ -116,12 +116,12 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_AttributeValueNull(t *testing.T)
plancheck.ExpectKnownOutputValueAtPath(
"test_resource_one_output",
tfjsonpath.New("map_attribute"),
knownvalue.NullExact(),
knownvalue.Null(),
),
plancheck.ExpectKnownOutputValueAtPath(
"test_resource_one_output",
tfjsonpath.New("set_attribute"),
knownvalue.NullExact(),
knownvalue.Null(),
),
plancheck.ExpectKnownOutputValueAtPath(
"test_resource_one_output",
Expand All @@ -131,7 +131,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_AttributeValueNull(t *testing.T)
plancheck.ExpectKnownOutputValueAtPath(
"test_resource_one_output",
tfjsonpath.New("string_attribute"),
knownvalue.NullExact(),
knownvalue.Null(),
),
},
},
Expand Down Expand Up @@ -171,7 +171,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_Bool(t *testing.T) {
plancheck.ExpectKnownOutputValueAtPath(
"test_resource_one_output",
tfjsonpath.New("bool_attribute"),
knownvalue.BoolExact(true),
knownvalue.Bool(true),
),
},
},
Expand Down Expand Up @@ -252,11 +252,11 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_Bool_KnownValueWrongValue(t *tes
plancheck.ExpectKnownOutputValueAtPath(
"test_resource_one_output",
tfjsonpath.New("bool_attribute"),
knownvalue.BoolExact(false),
knownvalue.Bool(false),
),
},
},
ExpectError: regexp.MustCompile("error checking value for output at path: test_resource_one_output.bool_attribute, err: expected value false for BoolExact check, got: true"),
ExpectError: regexp.MustCompile("error checking value for output at path: test_resource_one_output.bool_attribute, err: expected value false for Bool check, got: true"),
},
},
})
Expand Down Expand Up @@ -1780,10 +1780,10 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_String_KnownValueWrongType(t *te
plancheck.ExpectKnownOutputValueAtPath(
"test_resource_one_output",
tfjsonpath.New("string_attribute"),
knownvalue.BoolExact(true)),
knownvalue.Bool(true)),
},
},
ExpectError: regexp.MustCompile("error checking value for output at path: test_resource_one_output.string_attribute, err: expected bool value for BoolExact check, got: string"),
ExpectError: regexp.MustCompile("error checking value for output at path: test_resource_one_output.string_attribute, err: expected bool value for Bool check, got: string"),
},
},
})
Expand Down
26 changes: 13 additions & 13 deletions plancheck/expect_known_output_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestExpectKnownOutputValue_CheckPlan_OutputNotFound(t *testing.T) {
PreApply: []plancheck.PlanCheck{
plancheck.ExpectKnownOutputValue(
"bool_not_found",
knownvalue.BoolExact(true),
knownvalue.Bool(true),
),
},
},
Expand Down Expand Up @@ -96,39 +96,39 @@ func TestExpectKnownOutputValue_CheckPlan_AttributeValueNull(t *testing.T) {
PreApply: []plancheck.PlanCheck{
plancheck.ExpectKnownOutputValue(
"bool_output",
knownvalue.NullExact(),
knownvalue.Null(),
),
plancheck.ExpectKnownOutputValue(
"float_output",
knownvalue.NullExact(),
knownvalue.Null(),
),
plancheck.ExpectKnownOutputValue(
"int_output",
knownvalue.NullExact(),
knownvalue.Null(),
),
plancheck.ExpectKnownOutputValue(
"list_output",
knownvalue.NullExact(),
knownvalue.Null(),
),
plancheck.ExpectKnownOutputValue(
"list_nested_block_output",
knownvalue.ListExact([]knownvalue.Check{}),
),
plancheck.ExpectKnownOutputValue(
"map_output",
knownvalue.NullExact(),
knownvalue.Null(),
),
plancheck.ExpectKnownOutputValue(
"set_output",
knownvalue.NullExact(),
knownvalue.Null(),
),
plancheck.ExpectKnownOutputValue(
"set_nested_block_output",
knownvalue.SetExact([]knownvalue.Check{}),
),
plancheck.ExpectKnownOutputValue(
"string_output",
knownvalue.NullExact(),
knownvalue.Null(),
),
},
},
Expand Down Expand Up @@ -160,7 +160,7 @@ func TestExpectKnownOutputValue_CheckPlan_Bool(t *testing.T) {
PreApply: []plancheck.PlanCheck{
plancheck.ExpectKnownOutputValue(
"bool_output",
knownvalue.BoolExact(true),
knownvalue.Bool(true),
),
},
},
Expand Down Expand Up @@ -225,11 +225,11 @@ func TestExpectKnownOutputValue_CheckPlan_Bool_KnownValueWrongValue(t *testing.T
PreApply: []plancheck.PlanCheck{
plancheck.ExpectKnownOutputValue(
"bool_output",
knownvalue.BoolExact(false),
knownvalue.Bool(false),
),
},
},
ExpectError: regexp.MustCompile("error checking value for output at path: bool_output, err: expected value false for BoolExact check, got: true"),
ExpectError: regexp.MustCompile("error checking value for output at path: bool_output, err: expected value false for Bool check, got: true"),
},
},
})
Expand Down Expand Up @@ -1481,10 +1481,10 @@ func TestExpectKnownOutputValue_CheckPlan_String_KnownValueWrongType(t *testing.
PreApply: []plancheck.PlanCheck{
plancheck.ExpectKnownOutputValue(
"string_output",
knownvalue.BoolExact(true)),
knownvalue.Bool(true)),
},
},
ExpectError: regexp.MustCompile("error checking value for output at path: string_output, err: expected bool value for BoolExact check, got: string"),
ExpectError: regexp.MustCompile("error checking value for output at path: string_output, err: expected bool value for Bool check, got: string"),
},
},
})
Expand Down
Loading

0 comments on commit 6d8f112

Please sign in to comment.