diff --git a/knownvalue/bool.go b/knownvalue/bool.go index f0e3a1f7b..fc2add0c8 100644 --- a/knownvalue/bool.go +++ b/knownvalue/bool.go @@ -8,39 +8,37 @@ import ( "strconv" ) -var _ Check = BoolValue{} +var _ Check = boolValueExact{} -// BoolValue is a Check for asserting equality between the value supplied -// to BoolValueExact and the value passed to the CheckValue method. -type BoolValue struct { +type boolValueExact struct { value bool } // CheckValue determines whether the passed value is of type bool, and // contains a matching bool value. -func (v BoolValue) CheckValue(other any) error { +func (v boolValueExact) CheckValue(other any) error { otherVal, ok := other.(bool) if !ok { - return fmt.Errorf("expected bool value for BoolValue check, got: %T", other) + return fmt.Errorf("expected bool value for BoolValueExact check, got: %T", other) } if otherVal != v.value { - return fmt.Errorf("expected value %t for BoolValue check, got: %t", v.value, otherVal) + return fmt.Errorf("expected value %t for BoolValueExact check, got: %t", v.value, otherVal) } return nil } // String returns the string representation of the bool value. -func (v BoolValue) String() string { +func (v boolValueExact) String() string { return strconv.FormatBool(v.value) } // BoolValueExact returns a Check for asserting equality between the // supplied bool and the value passed to the CheckValue method. -func BoolValueExact(value bool) BoolValue { - return BoolValue{ +func BoolValueExact(value bool) boolValueExact { + return boolValueExact{ value: value, } } diff --git a/knownvalue/bool_test.go b/knownvalue/bool_test.go index 21e9bee7e..bbbf45939 100644 --- a/knownvalue/bool_test.go +++ b/knownvalue/bool_test.go @@ -16,29 +16,31 @@ func TestBoolValue_CheckValue(t *testing.T) { t.Parallel() testCases := map[string]struct { - self knownvalue.BoolValue + self knownvalue.Check other any expectedError error }{ "zero-nil": { - expectedError: fmt.Errorf("expected bool value for BoolValue check, got: "), + self: knownvalue.BoolValueExact(false), + expectedError: fmt.Errorf("expected bool value for BoolValueExact check, got: "), }, "zero-other": { + self: knownvalue.BoolValueExact(false), other: false, // checking against the underlying value field zero-value }, "nil": { self: knownvalue.BoolValueExact(false), - expectedError: fmt.Errorf("expected bool value for BoolValue check, got: "), + expectedError: fmt.Errorf("expected bool value for BoolValueExact check, got: "), }, "wrong-type": { self: knownvalue.BoolValueExact(true), other: 1.23, - expectedError: fmt.Errorf("expected bool value for BoolValue check, got: float64"), + expectedError: fmt.Errorf("expected bool value for BoolValueExact check, got: float64"), }, "not-equal": { self: knownvalue.BoolValueExact(true), other: false, - expectedError: fmt.Errorf("expected value true for BoolValue check, got: false"), + expectedError: fmt.Errorf("expected value true for BoolValueExact check, got: false"), }, "equal": { self: knownvalue.BoolValueExact(true), diff --git a/knownvalue/float64.go b/knownvalue/float64.go index 195ae8c30..5f05415b0 100644 --- a/knownvalue/float64.go +++ b/knownvalue/float64.go @@ -9,45 +9,43 @@ import ( "strconv" ) -var _ Check = Float64Value{} +var _ Check = float64ValueExact{} -// Float64Value is a Check for asserting equality between the value supplied -// to Float64ValueExact and the value passed to the CheckValue method. -type Float64Value struct { +type float64ValueExact struct { value float64 } // CheckValue determines whether the passed value is of type float64, and // contains a matching float64 value. -func (v Float64Value) CheckValue(other any) error { +func (v float64ValueExact) CheckValue(other any) error { jsonNum, ok := other.(json.Number) if !ok { - return fmt.Errorf("expected json.Number value for Float64Value check, got: %T", other) + return fmt.Errorf("expected json.Number value for Float64ValueExact check, got: %T", other) } otherVal, err := jsonNum.Float64() if err != nil { - return fmt.Errorf("expected json.Number to be parseable as float64 value for Float64Value check: %s", err) + return fmt.Errorf("expected json.Number to be parseable as float64 value for Float64ValueExact check: %s", err) } if otherVal != v.value { - return fmt.Errorf("expected value %s for Float64Value check, got: %s", v.String(), strconv.FormatFloat(otherVal, 'f', -1, 64)) + return fmt.Errorf("expected value %s for Float64ValueExact check, got: %s", v.String(), strconv.FormatFloat(otherVal, 'f', -1, 64)) } return nil } // String returns the string representation of the float64 value. -func (v Float64Value) String() string { +func (v float64ValueExact) String() string { return strconv.FormatFloat(v.value, 'f', -1, 64) } // Float64ValueExact returns a Check for asserting equality between the // supplied float64 and the value passed to the CheckValue method. -func Float64ValueExact(value float64) Float64Value { - return Float64Value{ +func Float64ValueExact(value float64) float64ValueExact { + return float64ValueExact{ value: value, } } diff --git a/knownvalue/float64_test.go b/knownvalue/float64_test.go index 7ddbde24f..f5f66c56a 100644 --- a/knownvalue/float64_test.go +++ b/knownvalue/float64_test.go @@ -17,29 +17,31 @@ func TestFloat64Value_CheckValue(t *testing.T) { t.Parallel() testCases := map[string]struct { - self knownvalue.Float64Value + self knownvalue.Check other any expectedError error }{ "zero-nil": { - expectedError: fmt.Errorf("expected json.Number value for Float64Value check, got: "), + self: knownvalue.Float64ValueExact(0), + expectedError: fmt.Errorf("expected json.Number value for Float64ValueExact check, got: "), }, "zero-other": { + self: knownvalue.Float64ValueExact(0), other: json.Number("0.0"), // checking against the underlying value field zero-value }, "nil": { self: knownvalue.Float64ValueExact(1.234), - expectedError: fmt.Errorf("expected json.Number value for Float64Value check, got: "), + expectedError: fmt.Errorf("expected json.Number value for Float64ValueExact check, got: "), }, "wrong-type": { self: knownvalue.Float64ValueExact(1.234), other: json.Number("str"), - expectedError: fmt.Errorf("expected json.Number to be parseable as float64 value for Float64Value check: strconv.ParseFloat: parsing \"str\": invalid syntax"), + expectedError: fmt.Errorf("expected json.Number to be parseable as float64 value for Float64ValueExact check: strconv.ParseFloat: parsing \"str\": invalid syntax"), }, "not-equal": { self: knownvalue.Float64ValueExact(1.234), other: json.Number("4.321"), - expectedError: fmt.Errorf("expected value 1.234 for Float64Value check, got: 4.321"), + expectedError: fmt.Errorf("expected value 1.234 for Float64ValueExact check, got: 4.321"), }, "equal": { self: knownvalue.Float64ValueExact(1.234), diff --git a/knownvalue/int64.go b/knownvalue/int64.go index bf3b5ad48..300fdfdb2 100644 --- a/knownvalue/int64.go +++ b/knownvalue/int64.go @@ -9,45 +9,43 @@ import ( "strconv" ) -var _ Check = Int64Value{} +var _ Check = int64ValueExact{} -// Int64Value is a Check for asserting equality between the value supplied -// to Int64ValueExact and the value passed to the CheckValue method. -type Int64Value struct { +type int64ValueExact struct { value int64 } // CheckValue determines whether the passed value is of type int64, and // contains a matching int64 value. -func (v Int64Value) CheckValue(other any) error { +func (v int64ValueExact) CheckValue(other any) error { jsonNum, ok := other.(json.Number) if !ok { - return fmt.Errorf("expected json.Number value for Int64Value check, got: %T", other) + return fmt.Errorf("expected json.Number value for Int64ValueExact check, got: %T", other) } otherVal, err := jsonNum.Int64() if err != nil { - return fmt.Errorf("expected json.Number to be parseable as int64 value for Int64Value check: %s", err) + return fmt.Errorf("expected json.Number to be parseable as int64 value for Int64ValueExact check: %s", err) } if otherVal != v.value { - return fmt.Errorf("expected value %d for Int64Value check, got: %d", v.value, otherVal) + return fmt.Errorf("expected value %d for Int64ValueExact check, got: %d", v.value, otherVal) } return nil } // String returns the string representation of the int64 value. -func (v Int64Value) String() string { +func (v int64ValueExact) String() string { return strconv.FormatInt(v.value, 10) } // Int64ValueExact returns a Check for asserting equality between the // supplied int64 and the value passed to the CheckValue method. -func Int64ValueExact(value int64) Int64Value { - return Int64Value{ +func Int64ValueExact(value int64) int64ValueExact { + return int64ValueExact{ value: value, } } diff --git a/knownvalue/int64_test.go b/knownvalue/int64_test.go index 0aba7a21e..03527b390 100644 --- a/knownvalue/int64_test.go +++ b/knownvalue/int64_test.go @@ -17,29 +17,31 @@ func TestInt64Value_CheckValue(t *testing.T) { t.Parallel() testCases := map[string]struct { - self knownvalue.Int64Value + self knownvalue.Check other any expectedError error }{ "zero-nil": { - expectedError: fmt.Errorf("expected json.Number value for Int64Value check, got: "), + self: knownvalue.Int64ValueExact(0), + expectedError: fmt.Errorf("expected json.Number value for Int64ValueExact check, got: "), }, "zero-other": { + self: knownvalue.Int64ValueExact(0), other: json.Number("0"), // checking against the underlying value field zero-value }, "nil": { self: knownvalue.Int64ValueExact(1234), - expectedError: fmt.Errorf("expected json.Number value for Int64Value check, got: "), + expectedError: fmt.Errorf("expected json.Number value for Int64ValueExact check, got: "), }, "wrong-type": { self: knownvalue.Int64ValueExact(1234), other: json.Number("str"), - expectedError: fmt.Errorf("expected json.Number to be parseable as int64 value for Int64Value check: strconv.ParseInt: parsing \"str\": invalid syntax"), + expectedError: fmt.Errorf("expected json.Number to be parseable as int64 value for Int64ValueExact check: strconv.ParseInt: parsing \"str\": invalid syntax"), }, "not-equal": { self: knownvalue.Int64ValueExact(1234), other: json.Number("4321"), - expectedError: fmt.Errorf("expected value 1234 for Int64Value check, got: 4321"), + expectedError: fmt.Errorf("expected value 1234 for Int64ValueExact check, got: 4321"), }, "equal": { self: knownvalue.Int64ValueExact(1234), diff --git a/knownvalue/list.go b/knownvalue/list.go index a14967b72..9d89cbdc4 100644 --- a/knownvalue/list.go +++ b/knownvalue/list.go @@ -7,21 +7,19 @@ import ( "fmt" ) -var _ Check = ListValue{} +var _ Check = listValueExact{} -// ListValue is a Check for asserting equality between the value supplied -// to ListValueExact and the value passed to the CheckValue method. -type ListValue struct { +type listValueExact struct { value []Check } // CheckValue determines whether the passed value is of type []any, and // contains matching slice entries in the same sequence. -func (v ListValue) CheckValue(other any) error { +func (v listValueExact) CheckValue(other any) error { otherVal, ok := other.([]any) if !ok { - return fmt.Errorf("expected []any value for ListValue check, got: %T", other) + return fmt.Errorf("expected []any value for ListValueExact check, got: %T", other) } if len(otherVal) != len(v.value) { @@ -36,7 +34,7 @@ func (v ListValue) CheckValue(other any) error { actualElements = "element" } - return fmt.Errorf("expected %d %s for ListValue check, got %d %s", len(v.value), expectedElements, len(otherVal), actualElements) + return fmt.Errorf("expected %d %s for ListValueExact check, got %d %s", len(v.value), expectedElements, len(otherVal), actualElements) } for i := 0; i < len(v.value); i++ { @@ -49,7 +47,7 @@ func (v ListValue) CheckValue(other any) error { } // String returns the string representation of the value. -func (v ListValue) String() string { +func (v listValueExact) String() string { var listVals []string for _, val := range v.value { @@ -62,8 +60,8 @@ func (v ListValue) String() string { // ListValueExact returns a Check for asserting equality between the // supplied []Check and the value passed to the CheckValue method. // This is an order-dependent check. -func ListValueExact(value []Check) ListValue { - return ListValue{ +func ListValueExact(value []Check) listValueExact { + return listValueExact{ value: value, } } diff --git a/knownvalue/list_elements.go b/knownvalue/list_elements.go index ffb4b1eea..8e524e11d 100644 --- a/knownvalue/list_elements.go +++ b/knownvalue/list_elements.go @@ -8,21 +8,19 @@ import ( "strconv" ) -var _ Check = ListElements{} +var _ Check = listElementsExact{} -// ListElements is a Check for asserting equality between the value supplied -// to ListElementsExact and the value passed to the CheckValue method. -type ListElements struct { +type listElementsExact struct { num int } // CheckValue verifies that the passed value is a list, map, object, // or set, and contains a matching number of elements. -func (v ListElements) CheckValue(other any) error { +func (v listElementsExact) CheckValue(other any) error { otherVal, ok := other.([]any) if !ok { - return fmt.Errorf("expected []any value for ListElements check, got: %T", other) + return fmt.Errorf("expected []any value for ListElementsExact check, got: %T", other) } if len(otherVal) != v.num { @@ -37,21 +35,21 @@ func (v ListElements) CheckValue(other any) error { actualElements = "element" } - return fmt.Errorf("expected %d %s for ListElements check, got %d %s", v.num, expectedElements, len(otherVal), actualElements) + return fmt.Errorf("expected %d %s for ListElementsExact check, got %d %s", v.num, expectedElements, len(otherVal), actualElements) } return nil } // String returns the string representation of the value. -func (v ListElements) String() string { +func (v listElementsExact) String() string { return strconv.FormatInt(int64(v.num), 10) } // ListElementsExact returns a Check for asserting that -// a list num elements. -func ListElementsExact(num int) ListElements { - return ListElements{ +// a list has num elements. +func ListElementsExact(num int) listElementsExact { + return listElementsExact{ num: num, } } diff --git a/knownvalue/list_elements_test.go b/knownvalue/list_elements_test.go index 242b13f61..d48196510 100644 --- a/knownvalue/list_elements_test.go +++ b/knownvalue/list_elements_test.go @@ -16,29 +16,31 @@ func TestListElements_CheckValue(t *testing.T) { t.Parallel() testCases := map[string]struct { - self knownvalue.ListElements + self knownvalue.Check other any expectedError error }{ "zero-nil": { - expectedError: fmt.Errorf("expected []any value for ListElements check, got: "), + self: knownvalue.ListElementsExact(0), + expectedError: fmt.Errorf("expected []any value for ListElementsExact check, got: "), }, "zero-other": { + self: knownvalue.ListElementsExact(0), other: []any{}, // checking against the underlying value field zero-value }, "nil": { self: knownvalue.ListElementsExact(3), - expectedError: fmt.Errorf("expected []any value for ListElements check, got: "), + expectedError: fmt.Errorf("expected []any value for ListElementsExact check, got: "), }, "wrong-type": { self: knownvalue.ListElementsExact(3), other: 1.234, - expectedError: fmt.Errorf("expected []any value for ListElements check, got: float64"), + expectedError: fmt.Errorf("expected []any value for ListElementsExact check, got: float64"), }, "empty": { self: knownvalue.ListElementsExact(3), other: []any{}, - expectedError: fmt.Errorf("expected 3 elements for ListElements check, got 0 elements"), + expectedError: fmt.Errorf("expected 3 elements for ListElementsExact check, got 0 elements"), }, "wrong-length": { self: knownvalue.ListElementsExact(3), @@ -46,7 +48,7 @@ func TestListElements_CheckValue(t *testing.T) { int64(123), int64(456), }, - expectedError: fmt.Errorf("expected 3 elements for ListElements check, got 2 elements"), + expectedError: fmt.Errorf("expected 3 elements for ListElementsExact check, got 2 elements"), }, "equal": { self: knownvalue.ListElementsExact(3), diff --git a/knownvalue/list_partial.go b/knownvalue/list_partial.go index 0c6c075ea..1bd333ae3 100644 --- a/knownvalue/list_partial.go +++ b/knownvalue/list_partial.go @@ -10,18 +10,15 @@ import ( "strings" ) -var _ Check = ListValuePartial{} +var _ Check = listValuePartial{} -// ListValuePartial is a Check for asserting partial equality between the -// value supplied to ListValuePartialMatch and the value passed to the -// CheckValue method. -type ListValuePartial struct { +type listValuePartial struct { value map[int]Check } // CheckValue determines whether the passed value is of type []any, and // contains matching slice entries in the same sequence. -func (v ListValuePartial) CheckValue(other any) error { +func (v listValuePartial) CheckValue(other any) error { otherVal, ok := other.([]any) if !ok { @@ -52,7 +49,7 @@ func (v ListValuePartial) CheckValue(other any) error { } // String returns the string representation of the value. -func (v ListValuePartial) String() string { +func (v listValuePartial) String() string { var b bytes.Buffer b.WriteString("[") @@ -80,13 +77,13 @@ func (v ListValuePartial) String() string { return b.String() } -// ListValuePartialMatch returns a Check for asserting partial equality between the +// ListValuePartial returns a Check for asserting partial equality between the // supplied map[int]Check and the value passed to the CheckValue method. The // map keys represent the zero-ordered element indices within the list that is // being checked. Only the elements at the indices defined within the // supplied map[int]Check are checked. -func ListValuePartialMatch(value map[int]Check) ListValuePartial { - return ListValuePartial{ +func ListValuePartial(value map[int]Check) listValuePartial { + return listValuePartial{ value: value, } } diff --git a/knownvalue/list_partial_test.go b/knownvalue/list_partial_test.go index d2f640b1c..c32f5bbde 100644 --- a/knownvalue/list_partial_test.go +++ b/knownvalue/list_partial_test.go @@ -17,18 +17,20 @@ func TestListValuePartial_CheckValue(t *testing.T) { t.Parallel() testCases := map[string]struct { - self knownvalue.ListValuePartial + self knownvalue.Check other any expectedError error }{ "zero-nil": { + self: knownvalue.ListValuePartial(map[int]knownvalue.Check{}), expectedError: fmt.Errorf("expected []any value for ListValuePartial check, got: "), }, "zero-other": { + self: knownvalue.ListValuePartial(map[int]knownvalue.Check{}), other: []any{}, // checking against the underlying value field zero-value }, "nil": { - self: knownvalue.ListValuePartialMatch(map[int]knownvalue.Check{ + self: knownvalue.ListValuePartial(map[int]knownvalue.Check{ 0: knownvalue.Float64ValueExact(1.23), 2: knownvalue.Float64ValueExact(4.56), 3: knownvalue.Float64ValueExact(7.89), @@ -36,7 +38,7 @@ func TestListValuePartial_CheckValue(t *testing.T) { expectedError: fmt.Errorf("expected []any value for ListValuePartial check, got: "), }, "wrong-type": { - self: knownvalue.ListValuePartialMatch(map[int]knownvalue.Check{ + self: knownvalue.ListValuePartial(map[int]knownvalue.Check{ 0: knownvalue.Float64ValueExact(1.23), 2: knownvalue.Float64ValueExact(4.56), 3: knownvalue.Float64ValueExact(7.89), @@ -45,7 +47,7 @@ func TestListValuePartial_CheckValue(t *testing.T) { expectedError: fmt.Errorf("expected []any value for ListValuePartial check, got: float64"), }, "empty": { - self: knownvalue.ListValuePartialMatch(map[int]knownvalue.Check{ + self: knownvalue.ListValuePartial(map[int]knownvalue.Check{ 0: knownvalue.Float64ValueExact(1.23), 2: knownvalue.Float64ValueExact(4.56), 3: knownvalue.Float64ValueExact(7.89), @@ -54,7 +56,7 @@ func TestListValuePartial_CheckValue(t *testing.T) { expectedError: fmt.Errorf("missing element index 0 for ListValuePartial check"), }, "wrong-length": { - self: knownvalue.ListValuePartialMatch(map[int]knownvalue.Check{ + self: knownvalue.ListValuePartial(map[int]knownvalue.Check{ 0: knownvalue.Float64ValueExact(1.23), 2: knownvalue.Float64ValueExact(4.56), 3: knownvalue.Float64ValueExact(7.89), @@ -66,7 +68,7 @@ func TestListValuePartial_CheckValue(t *testing.T) { expectedError: fmt.Errorf("missing element index 2 for ListValuePartial check"), }, "not-equal": { - self: knownvalue.ListValuePartialMatch(map[int]knownvalue.Check{ + self: knownvalue.ListValuePartial(map[int]knownvalue.Check{ 0: knownvalue.Float64ValueExact(1.23), 2: knownvalue.Float64ValueExact(4.56), 3: knownvalue.Float64ValueExact(7.89), @@ -77,10 +79,10 @@ func TestListValuePartial_CheckValue(t *testing.T) { json.Number("6.54"), json.Number("5.46"), }, - expectedError: fmt.Errorf("list element 2: expected value 4.56 for Float64Value check, got: 6.54"), + expectedError: fmt.Errorf("list element 2: expected value 4.56 for Float64ValueExact check, got: 6.54"), }, "wrong-order": { - self: knownvalue.ListValuePartialMatch(map[int]knownvalue.Check{ + self: knownvalue.ListValuePartial(map[int]knownvalue.Check{ 0: knownvalue.Float64ValueExact(1.23), 2: knownvalue.Float64ValueExact(4.56), 3: knownvalue.Float64ValueExact(7.89), @@ -91,10 +93,10 @@ func TestListValuePartial_CheckValue(t *testing.T) { json.Number("7.89"), json.Number("4.56"), }, - expectedError: fmt.Errorf("list element 2: expected value 4.56 for Float64Value check, got: 7.89"), + expectedError: fmt.Errorf("list element 2: expected value 4.56 for Float64ValueExact check, got: 7.89"), }, "equal": { - self: knownvalue.ListValuePartialMatch(map[int]knownvalue.Check{ + self: knownvalue.ListValuePartial(map[int]knownvalue.Check{ 0: knownvalue.Float64ValueExact(1.23), 2: knownvalue.Float64ValueExact(4.56), 3: knownvalue.Float64ValueExact(7.89), @@ -126,7 +128,7 @@ func TestListValuePartial_CheckValue(t *testing.T) { func TestListValuePartialPartial_String(t *testing.T) { t.Parallel() - got := knownvalue.ListValuePartialMatch(map[int]knownvalue.Check{ + got := knownvalue.ListValuePartial(map[int]knownvalue.Check{ 0: knownvalue.Float64ValueExact(1.23), 2: knownvalue.Float64ValueExact(4.56), 3: knownvalue.Float64ValueExact(7.89), diff --git a/knownvalue/list_test.go b/knownvalue/list_test.go index 34c74752b..1563b473b 100644 --- a/knownvalue/list_test.go +++ b/knownvalue/list_test.go @@ -17,14 +17,16 @@ func TestListValue_CheckValue(t *testing.T) { t.Parallel() testCases := map[string]struct { - self knownvalue.ListValue + self knownvalue.Check other any expectedError error }{ "zero-nil": { - expectedError: fmt.Errorf("expected []any value for ListValue check, got: "), + self: knownvalue.ListValueExact([]knownvalue.Check{}), + expectedError: fmt.Errorf("expected []any value for ListValueExact check, got: "), }, "zero-other": { + self: knownvalue.ListValueExact([]knownvalue.Check{}), other: []any{}, // checking against the underlying value field zero-value }, "nil": { @@ -33,7 +35,7 @@ func TestListValue_CheckValue(t *testing.T) { knownvalue.Int64ValueExact(456), knownvalue.Int64ValueExact(789), }), - expectedError: fmt.Errorf("expected []any value for ListValue check, got: "), + expectedError: fmt.Errorf("expected []any value for ListValueExact check, got: "), }, "wrong-type": { self: knownvalue.ListValueExact([]knownvalue.Check{ @@ -42,7 +44,7 @@ func TestListValue_CheckValue(t *testing.T) { knownvalue.Int64ValueExact(789), }), other: 1.234, - expectedError: fmt.Errorf("expected []any value for ListValue check, got: float64"), + expectedError: fmt.Errorf("expected []any value for ListValueExact check, got: float64"), }, "empty": { self: knownvalue.ListValueExact([]knownvalue.Check{ @@ -51,7 +53,7 @@ func TestListValue_CheckValue(t *testing.T) { knownvalue.Int64ValueExact(789), }), other: []any{}, - expectedError: fmt.Errorf("expected 3 elements for ListValue check, got 0 elements"), + expectedError: fmt.Errorf("expected 3 elements for ListValueExact check, got 0 elements"), }, "wrong-length": { self: knownvalue.ListValueExact([]knownvalue.Check{ @@ -63,7 +65,7 @@ func TestListValue_CheckValue(t *testing.T) { int64(123), int64(456), }, - expectedError: fmt.Errorf("expected 3 elements for ListValue check, got 2 elements"), + expectedError: fmt.Errorf("expected 3 elements for ListValueExact check, got 2 elements"), }, "not-equal": { self: knownvalue.ListValueExact([]knownvalue.Check{ @@ -76,7 +78,7 @@ func TestListValue_CheckValue(t *testing.T) { json.Number("456"), json.Number("654"), }, - expectedError: fmt.Errorf("list element index 2: expected value 789 for Int64Value check, got: 654"), + expectedError: fmt.Errorf("list element index 2: expected value 789 for Int64ValueExact check, got: 654"), }, "wrong-order": { self: knownvalue.ListValueExact([]knownvalue.Check{ @@ -89,7 +91,7 @@ func TestListValue_CheckValue(t *testing.T) { json.Number("789"), json.Number("456"), }, - expectedError: fmt.Errorf("list element index 1: expected value 456 for Int64Value check, got: 789"), + expectedError: fmt.Errorf("list element index 1: expected value 456 for Int64ValueExact check, got: 789"), }, "equal": { self: knownvalue.ListValueExact([]knownvalue.Check{ diff --git a/knownvalue/map.go b/knownvalue/map.go index b86a8c50f..11f69fef3 100644 --- a/knownvalue/map.go +++ b/knownvalue/map.go @@ -8,21 +8,19 @@ import ( "sort" ) -var _ Check = MapValue{} +var _ Check = mapValueExact{} -// MapValue is a Check for asserting equality between the value supplied -// to MapValueExact and the value passed to the CheckValue method. -type MapValue struct { +type mapValueExact struct { value map[string]Check } // CheckValue determines whether the passed value is of type map[string]any, and // contains matching map entries. -func (v MapValue) CheckValue(other any) error { +func (v mapValueExact) CheckValue(other any) error { otherVal, ok := other.(map[string]any) if !ok { - return fmt.Errorf("expected map[string]any value for MapValue check, got: %T", other) + return fmt.Errorf("expected map[string]any value for MapValueExact check, got: %T", other) } if len(otherVal) != len(v.value) { @@ -37,7 +35,7 @@ func (v MapValue) CheckValue(other any) error { actualElements = "element" } - return fmt.Errorf("expected %d %s for MapValue check, got %d %s", len(v.value), expectedElements, len(otherVal), actualElements) + return fmt.Errorf("expected %d %s for MapValueExact check, got %d %s", len(v.value), expectedElements, len(otherVal), actualElements) } var keys []string @@ -54,7 +52,7 @@ func (v MapValue) CheckValue(other any) error { otherValItem, ok := otherVal[k] if !ok { - return fmt.Errorf("missing element %s for MapValue check", k) + return fmt.Errorf("missing element %s for MapValueExact check", k) } if err := v.value[k].CheckValue(otherValItem); err != nil { @@ -66,7 +64,7 @@ func (v MapValue) CheckValue(other any) error { } // String returns the string representation of the value. -func (v MapValue) String() string { +func (v mapValueExact) String() string { var keys []string for k := range v.value { @@ -88,8 +86,8 @@ func (v MapValue) String() string { // MapValueExact returns a Check for asserting equality between the // supplied map[string]Check and the value passed to the CheckValue method. -func MapValueExact(value map[string]Check) MapValue { - return MapValue{ +func MapValueExact(value map[string]Check) mapValueExact { + return mapValueExact{ value: value, } } diff --git a/knownvalue/map_elements.go b/knownvalue/map_elements.go index 79b617206..4c5b12e1e 100644 --- a/knownvalue/map_elements.go +++ b/knownvalue/map_elements.go @@ -8,21 +8,19 @@ import ( "strconv" ) -var _ Check = MapElements{} +var _ Check = mapElementsExact{} -// MapElements is a Check for asserting equality between the value supplied -// to MapElementsExact and the value passed to the CheckValue method. -type MapElements struct { +type mapElementsExact struct { num int } // CheckValue verifies that the passed value is a list, map, object, // or set, and contains a matching number of elements. -func (v MapElements) CheckValue(other any) error { +func (v mapElementsExact) CheckValue(other any) error { otherVal, ok := other.(map[string]any) if !ok { - return fmt.Errorf("expected map[string]any value for MapElements check, got: %T", other) + return fmt.Errorf("expected map[string]any value for MapElementsExact check, got: %T", other) } if len(otherVal) != v.num { @@ -37,21 +35,21 @@ func (v MapElements) CheckValue(other any) error { actualElements = "element" } - return fmt.Errorf("expected %d %s for MapElements check, got %d %s", v.num, expectedElements, len(otherVal), actualElements) + return fmt.Errorf("expected %d %s for MapElementsExact check, got %d %s", v.num, expectedElements, len(otherVal), actualElements) } return nil } // String returns the string representation of the value. -func (v MapElements) String() string { +func (v mapElementsExact) String() string { return strconv.FormatInt(int64(v.num), 10) } // MapElementsExact returns a Check for asserting that -// a list num elements. -func MapElementsExact(num int) MapElements { - return MapElements{ +// a map has num elements. +func MapElementsExact(num int) mapElementsExact { + return mapElementsExact{ num: num, } } diff --git a/knownvalue/map_elements_test.go b/knownvalue/map_elements_test.go index 82297f623..0dca62afa 100644 --- a/knownvalue/map_elements_test.go +++ b/knownvalue/map_elements_test.go @@ -16,29 +16,31 @@ func TestMapElements_CheckValue(t *testing.T) { t.Parallel() testCases := map[string]struct { - self knownvalue.MapElements + self knownvalue.Check other any expectedError error }{ "zero-nil": { - expectedError: fmt.Errorf("expected map[string]any value for MapElements check, got: "), + self: knownvalue.MapElementsExact(0), + expectedError: fmt.Errorf("expected map[string]any value for MapElementsExact check, got: "), }, "zero-other": { + self: knownvalue.MapElementsExact(0), other: map[string]any{}, // checking against the underlying value field zero-value }, "nil": { self: knownvalue.MapElementsExact(3), - expectedError: fmt.Errorf("expected map[string]any value for MapElements check, got: "), + expectedError: fmt.Errorf("expected map[string]any value for MapElementsExact check, got: "), }, "wrong-type": { self: knownvalue.MapElementsExact(3), other: 1.234, - expectedError: fmt.Errorf("expected map[string]any value for MapElements check, got: float64"), + expectedError: fmt.Errorf("expected map[string]any value for MapElementsExact check, got: float64"), }, "empty": { self: knownvalue.MapElementsExact(3), other: map[string]any{}, - expectedError: fmt.Errorf("expected 3 elements for MapElements check, got 0 elements"), + expectedError: fmt.Errorf("expected 3 elements for MapElementsExact check, got 0 elements"), }, "wrong-length": { self: knownvalue.MapElementsExact(3), @@ -46,7 +48,7 @@ func TestMapElements_CheckValue(t *testing.T) { "one": int64(123), "two": int64(456), }, - expectedError: fmt.Errorf("expected 3 elements for MapElements check, got 2 elements"), + expectedError: fmt.Errorf("expected 3 elements for MapElementsExact check, got 2 elements"), }, "equal": { self: knownvalue.MapElementsExact(3), diff --git a/knownvalue/map_partial.go b/knownvalue/map_partial.go index da620c5b1..1ebcb5338 100644 --- a/knownvalue/map_partial.go +++ b/knownvalue/map_partial.go @@ -8,18 +8,15 @@ import ( "sort" ) -var _ Check = MapValuePartial{} +var _ Check = mapValuePartial{} -// MapValuePartial is a Check for asserting partial equality between the -// value supplied to MapValuePartialMatch and the value passed to the -// CheckValue method. -type MapValuePartial struct { +type mapValuePartial struct { value map[string]Check } // CheckValue determines whether the passed value is of type map[string]any, and // contains matching map entries. -func (v MapValuePartial) CheckValue(other any) error { +func (v mapValuePartial) CheckValue(other any) error { otherVal, ok := other.(map[string]any) if !ok { @@ -52,7 +49,7 @@ func (v MapValuePartial) CheckValue(other any) error { } // String returns the string representation of the value. -func (v MapValuePartial) String() string { +func (v mapValuePartial) String() string { var keys []string for k := range v.value { @@ -72,12 +69,12 @@ func (v MapValuePartial) String() string { return fmt.Sprintf("%v", mapVals) } -// MapValuePartialMatch returns a Check for asserting partial equality between the +// MapValuePartial returns a Check for asserting partial equality between the // supplied map[string]Check and the value passed to the CheckValue method. Only // the elements at the map keys defined within the supplied map[string]Check are // checked. -func MapValuePartialMatch(value map[string]Check) MapValuePartial { - return MapValuePartial{ +func MapValuePartial(value map[string]Check) mapValuePartial { + return mapValuePartial{ value: value, } } diff --git a/knownvalue/map_partial_test.go b/knownvalue/map_partial_test.go index 04a19cfd1..3f500adee 100644 --- a/knownvalue/map_partial_test.go +++ b/knownvalue/map_partial_test.go @@ -17,25 +17,27 @@ func TestMapValuePartial_CheckValue(t *testing.T) { t.Parallel() testCases := map[string]struct { - self knownvalue.MapValuePartial + self knownvalue.Check other any expectedError error }{ "zero-nil": { + self: knownvalue.MapValuePartial(map[string]knownvalue.Check{}), expectedError: fmt.Errorf("expected map[string]any value for MapValuePartial check, got: "), }, "zero-other": { + self: knownvalue.MapValuePartial(map[string]knownvalue.Check{}), other: map[string]any{}, // checking against the underlying value field zero-value }, "nil": { - self: knownvalue.MapValuePartialMatch(map[string]knownvalue.Check{ + self: knownvalue.MapValuePartial(map[string]knownvalue.Check{ "one": knownvalue.Float64ValueExact(1.23), "three": knownvalue.Float64ValueExact(7.89), }), expectedError: fmt.Errorf("expected map[string]any value for MapValuePartial check, got: "), }, "wrong-type": { - self: knownvalue.MapValuePartialMatch(map[string]knownvalue.Check{ + self: knownvalue.MapValuePartial(map[string]knownvalue.Check{ "one": knownvalue.Float64ValueExact(1.23), "three": knownvalue.Float64ValueExact(7.89), }), @@ -43,7 +45,7 @@ func TestMapValuePartial_CheckValue(t *testing.T) { expectedError: fmt.Errorf("expected map[string]any value for MapValuePartial check, got: float64"), }, "empty": { - self: knownvalue.MapValuePartialMatch(map[string]knownvalue.Check{ + self: knownvalue.MapValuePartial(map[string]knownvalue.Check{ "one": knownvalue.Float64ValueExact(1.23), "three": knownvalue.Float64ValueExact(7.89), }), @@ -51,7 +53,7 @@ func TestMapValuePartial_CheckValue(t *testing.T) { expectedError: fmt.Errorf("missing element one for MapValuePartial check"), }, "wrong-length": { - self: knownvalue.MapValuePartialMatch(map[string]knownvalue.Check{ + self: knownvalue.MapValuePartial(map[string]knownvalue.Check{ "one": knownvalue.Float64ValueExact(1.23), "three": knownvalue.Float64ValueExact(7.89), }), @@ -62,7 +64,7 @@ func TestMapValuePartial_CheckValue(t *testing.T) { expectedError: fmt.Errorf("missing element three for MapValuePartial check"), }, "not-equal": { - self: knownvalue.MapValuePartialMatch(map[string]knownvalue.Check{ + self: knownvalue.MapValuePartial(map[string]knownvalue.Check{ "one": knownvalue.Float64ValueExact(1.23), "three": knownvalue.Float64ValueExact(7.89), }), @@ -71,10 +73,10 @@ func TestMapValuePartial_CheckValue(t *testing.T) { "two": json.Number("4.56"), "three": json.Number("6.54"), }, - expectedError: fmt.Errorf("three map element: expected value 7.89 for Float64Value check, got: 6.54"), + expectedError: fmt.Errorf("three map element: expected value 7.89 for Float64ValueExact check, got: 6.54"), }, "wrong-order": { - self: knownvalue.MapValuePartialMatch(map[string]knownvalue.Check{ + self: knownvalue.MapValuePartial(map[string]knownvalue.Check{ "one": knownvalue.Float64ValueExact(1.23), "three": knownvalue.Float64ValueExact(7.89), }), @@ -83,10 +85,10 @@ func TestMapValuePartial_CheckValue(t *testing.T) { "two": json.Number("7.89"), "three": json.Number("4.56"), }, - expectedError: fmt.Errorf("three map element: expected value 7.89 for Float64Value check, got: 4.56"), + expectedError: fmt.Errorf("three map element: expected value 7.89 for Float64ValueExact check, got: 4.56"), }, "key-not-found": { - self: knownvalue.MapValuePartialMatch(map[string]knownvalue.Check{ + self: knownvalue.MapValuePartial(map[string]knownvalue.Check{ "one": knownvalue.Float64ValueExact(1.23), "two": knownvalue.Float64ValueExact(4.56), "three": knownvalue.Float64ValueExact(7.89), @@ -99,7 +101,7 @@ func TestMapValuePartial_CheckValue(t *testing.T) { expectedError: fmt.Errorf("missing element one for MapValuePartial check"), }, "equal": { - self: knownvalue.MapValuePartialMatch(map[string]knownvalue.Check{ + self: knownvalue.MapValuePartial(map[string]knownvalue.Check{ "one": knownvalue.Float64ValueExact(1.23), "three": knownvalue.Float64ValueExact(7.89), }), @@ -129,7 +131,7 @@ func TestMapValuePartial_CheckValue(t *testing.T) { func TestMapValuePartial_String(t *testing.T) { t.Parallel() - got := knownvalue.MapValuePartialMatch(map[string]knownvalue.Check{ + got := knownvalue.MapValuePartial(map[string]knownvalue.Check{ "one": knownvalue.Float64ValueExact(1.23), "three": knownvalue.Float64ValueExact(7.89), }).String() diff --git a/knownvalue/map_test.go b/knownvalue/map_test.go index c022f7eed..c47e516cf 100644 --- a/knownvalue/map_test.go +++ b/knownvalue/map_test.go @@ -17,14 +17,16 @@ func TestMapValue_CheckValue(t *testing.T) { t.Parallel() testCases := map[string]struct { - self knownvalue.MapValue + self knownvalue.Check other any expectedError error }{ "zero-nil": { - expectedError: fmt.Errorf("expected map[string]any value for MapValue check, got: "), + self: knownvalue.MapValueExact(map[string]knownvalue.Check{}), + expectedError: fmt.Errorf("expected map[string]any value for MapValueExact check, got: "), }, "zero-other": { + self: knownvalue.MapValueExact(map[string]knownvalue.Check{}), other: map[string]any{}, // checking against the underlying value field zero-value }, "nil": { @@ -33,7 +35,7 @@ func TestMapValue_CheckValue(t *testing.T) { "two": knownvalue.Float64ValueExact(4.56), "three": knownvalue.Float64ValueExact(7.89), }), - expectedError: fmt.Errorf("expected map[string]any value for MapValue check, got: "), + expectedError: fmt.Errorf("expected map[string]any value for MapValueExact check, got: "), }, "wrong-type": { self: knownvalue.MapValueExact(map[string]knownvalue.Check{ @@ -42,7 +44,7 @@ func TestMapValue_CheckValue(t *testing.T) { "three": knownvalue.Float64ValueExact(7.89), }), other: 1.234, - expectedError: fmt.Errorf("expected map[string]any value for MapValue check, got: float64"), + expectedError: fmt.Errorf("expected map[string]any value for MapValueExact check, got: float64"), }, "empty": { self: knownvalue.MapValueExact(map[string]knownvalue.Check{ @@ -51,7 +53,7 @@ func TestMapValue_CheckValue(t *testing.T) { "three": knownvalue.Float64ValueExact(7.89), }), other: map[string]any{}, - expectedError: fmt.Errorf("expected 3 elements for MapValue check, got 0 elements"), + expectedError: fmt.Errorf("expected 3 elements for MapValueExact check, got 0 elements"), }, "wrong-length": { self: knownvalue.MapValueExact(map[string]knownvalue.Check{ @@ -63,7 +65,7 @@ func TestMapValue_CheckValue(t *testing.T) { "one": json.Number("1.23"), "two": json.Number("4.56"), }, - expectedError: fmt.Errorf("expected 3 elements for MapValue check, got 2 elements"), + expectedError: fmt.Errorf("expected 3 elements for MapValueExact check, got 2 elements"), }, "not-equal": { self: knownvalue.MapValueExact(map[string]knownvalue.Check{ @@ -76,7 +78,7 @@ func TestMapValue_CheckValue(t *testing.T) { "two": json.Number("4.56"), "three": json.Number("6.54"), }, - expectedError: fmt.Errorf("three map element: expected value 7.89 for Float64Value check, got: 6.54"), + expectedError: fmt.Errorf("three map element: expected value 7.89 for Float64ValueExact check, got: 6.54"), }, "wrong-order": { self: knownvalue.MapValueExact(map[string]knownvalue.Check{ @@ -89,7 +91,7 @@ func TestMapValue_CheckValue(t *testing.T) { "two": json.Number("7.89"), "three": json.Number("4.56"), }, - expectedError: fmt.Errorf("three map element: expected value 7.89 for Float64Value check, got: 4.56"), + expectedError: fmt.Errorf("three map element: expected value 7.89 for Float64ValueExact check, got: 4.56"), }, "key-not-found": { self: knownvalue.MapValueExact(map[string]knownvalue.Check{ @@ -102,7 +104,7 @@ func TestMapValue_CheckValue(t *testing.T) { "five": json.Number("7.89"), "six": json.Number("4.56"), }, - expectedError: fmt.Errorf("missing element one for MapValue check"), + expectedError: fmt.Errorf("missing element one for MapValueExact check"), }, "equal": { self: knownvalue.MapValueExact(map[string]knownvalue.Check{ diff --git a/knownvalue/number.go b/knownvalue/number.go index 5f8700e70..98f54e733 100644 --- a/knownvalue/number.go +++ b/knownvalue/number.go @@ -9,49 +9,47 @@ import ( "math/big" ) -var _ Check = NumberValue{} +var _ Check = numberValueExact{} -// NumberValue is a Check for asserting equality between the value supplied -// to NumberValueExact and the value passed to the CheckValue method. -type NumberValue struct { +type numberValueExact struct { value *big.Float } // CheckValue determines whether the passed value is of type *big.Float, and // contains a matching *big.Float value. -func (v NumberValue) CheckValue(other any) error { +func (v numberValueExact) CheckValue(other any) error { if v.value == nil { - return fmt.Errorf("value in NumberValue check is nil") + return fmt.Errorf("value in NumberValueExact check is nil") } jsonNum, ok := other.(json.Number) if !ok { - return fmt.Errorf("expected json.Number value for NumberValue check, got: %T", other) + return fmt.Errorf("expected json.Number value for NumberValueExact check, got: %T", other) } otherVal, _, err := big.ParseFloat(jsonNum.String(), 10, 512, big.ToNearestEven) if err != nil { - return fmt.Errorf("expected json.Number to be parseable as big.Float value for NumberValue check: %s", err) + return fmt.Errorf("expected json.Number to be parseable as big.Float value for NumberValueExact check: %s", err) } if v.value.Cmp(otherVal) != 0 { - return fmt.Errorf("expected value %s for NumberValue check, got: %s", v.String(), otherVal.Text('f', -1)) + return fmt.Errorf("expected value %s for NumberValueExact check, got: %s", v.String(), otherVal.Text('f', -1)) } return nil } // String returns the string representation of the *big.Float value. -func (v NumberValue) String() string { +func (v numberValueExact) String() string { return v.value.Text('f', -1) } // NumberValueExact returns a Check for asserting equality between the // supplied *big.Float and the value passed to the CheckValue method. -func NumberValueExact(value *big.Float) NumberValue { - return NumberValue{ +func NumberValueExact(value *big.Float) numberValueExact { + return numberValueExact{ value: value, } } diff --git a/knownvalue/number_test.go b/knownvalue/number_test.go index 4d3e7b8a9..ca38be97f 100644 --- a/knownvalue/number_test.go +++ b/knownvalue/number_test.go @@ -24,30 +24,32 @@ func TestNumberValue_Equal(t *testing.T) { } testCases := map[string]struct { - self knownvalue.NumberValue + self knownvalue.Check other any expectedError error }{ "zero-nil": { - expectedError: fmt.Errorf("value in NumberValue check is nil"), + self: knownvalue.NumberValueExact(nil), + expectedError: fmt.Errorf("value in NumberValueExact check is nil"), }, "zero-other": { + self: knownvalue.NumberValueExact(nil), other: json.Number("1.797693134862315797693134862315797693134862314"), // checking against the underlying value field zero-value - expectedError: fmt.Errorf("value in NumberValue check is nil"), + expectedError: fmt.Errorf("value in NumberValueExact check is nil"), }, "nil": { self: knownvalue.NumberValueExact(bigFloat), - expectedError: fmt.Errorf("expected json.Number value for NumberValue check, got: "), + expectedError: fmt.Errorf("expected json.Number value for NumberValueExact check, got: "), }, "wrong-type": { self: knownvalue.NumberValueExact(bigFloat), other: json.Number("str"), - expectedError: fmt.Errorf("expected json.Number to be parseable as big.Float value for NumberValue check: number has no digits"), + expectedError: fmt.Errorf("expected json.Number to be parseable as big.Float value for NumberValueExact check: number has no digits"), }, "not-equal": { self: knownvalue.NumberValueExact(bigFloat), other: json.Number("1.797693134862315797693134862315797693134862314"), - expectedError: fmt.Errorf("expected value 1.797693134862315797693134862315797693134862315 for NumberValue check, got: 1.797693134862315797693134862315797693134862314"), + expectedError: fmt.Errorf("expected value 1.797693134862315797693134862315797693134862315 for NumberValueExact check, got: 1.797693134862315797693134862315797693134862314"), }, "equal": { self: knownvalue.NumberValueExact(bigFloat), diff --git a/knownvalue/object.go b/knownvalue/object.go index e8b74a4b5..7caf5a250 100644 --- a/knownvalue/object.go +++ b/knownvalue/object.go @@ -8,21 +8,19 @@ import ( "sort" ) -var _ Check = ObjectValue{} +var _ Check = objectValueExact{} -// ObjectValue is a Check for asserting equality between the value supplied -// to ObjectValueExact and the value passed to the CheckValue method. -type ObjectValue struct { +type objectValueExact struct { value map[string]Check } // CheckValue determines whether the passed value is of type map[string]any, and // contains matching object entries. -func (v ObjectValue) CheckValue(other any) error { +func (v objectValueExact) CheckValue(other any) error { otherVal, ok := other.(map[string]any) if !ok { - return fmt.Errorf("expected map[string]any value for ObjectValue check, got: %T", other) + return fmt.Errorf("expected map[string]any value for ObjectValueExact check, got: %T", other) } if len(otherVal) != len(v.value) { @@ -37,7 +35,7 @@ func (v ObjectValue) CheckValue(other any) error { actualAttributes = "attribute" } - return fmt.Errorf("expected %d %s for ObjectValue check, got %d %s", len(v.value), expectedAttributes, len(otherVal), actualAttributes) + return fmt.Errorf("expected %d %s for ObjectValueExact check, got %d %s", len(v.value), expectedAttributes, len(otherVal), actualAttributes) } var keys []string @@ -54,7 +52,7 @@ func (v ObjectValue) CheckValue(other any) error { otherValItem, ok := otherVal[k] if !ok { - return fmt.Errorf("missing attribute %s for ObjectValue check", k) + return fmt.Errorf("missing attribute %s for ObjectValueExact check", k) } if err := v.value[k].CheckValue(otherValItem); err != nil { @@ -66,7 +64,7 @@ func (v ObjectValue) CheckValue(other any) error { } // String returns the string representation of the value. -func (v ObjectValue) String() string { +func (v objectValueExact) String() string { var keys []string for k := range v.value { @@ -89,8 +87,8 @@ func (v ObjectValue) String() string { // ObjectValueExact returns a Check for asserting equality between the supplied // map[string]Check and the value passed to the CheckValue method. The map // keys represent object attribute names. -func ObjectValueExact(value map[string]Check) ObjectValue { - return ObjectValue{ +func ObjectValueExact(value map[string]Check) objectValueExact { + return objectValueExact{ value: value, } } diff --git a/knownvalue/object_attributes.go b/knownvalue/object_attributes.go index 80de51aa5..b4e03012e 100644 --- a/knownvalue/object_attributes.go +++ b/knownvalue/object_attributes.go @@ -8,21 +8,19 @@ import ( "strconv" ) -var _ Check = ObjectAttributes{} +var _ Check = objectAttributesExact{} -// ObjectAttributes is a Check for asserting equality between the value supplied -// to ObjectAttributesExact and the value passed to the CheckValue method. -type ObjectAttributes struct { +type objectAttributesExact struct { num int } // CheckValue verifies that the passed value is a list, map, object, // or set, and contains a matching number of elements. -func (v ObjectAttributes) CheckValue(other any) error { +func (v objectAttributesExact) CheckValue(other any) error { otherVal, ok := other.(map[string]any) if !ok { - return fmt.Errorf("expected map[string]any value for ObjectAttributes check, got: %T", other) + return fmt.Errorf("expected map[string]any value for ObjectAttributesExact check, got: %T", other) } if len(otherVal) != v.num { @@ -37,21 +35,21 @@ func (v ObjectAttributes) CheckValue(other any) error { actualAttributes = "attribute" } - return fmt.Errorf("expected %d %s for ObjectAttributes check, got %d %s", v.num, expectedAttributes, len(otherVal), actualAttributes) + return fmt.Errorf("expected %d %s for ObjectAttributesExact check, got %d %s", v.num, expectedAttributes, len(otherVal), actualAttributes) } return nil } // String returns the string representation of the value. -func (v ObjectAttributes) String() string { +func (v objectAttributesExact) String() string { return strconv.FormatInt(int64(v.num), 10) } // ObjectAttributesExact returns a Check for asserting that -// a list num elements. -func ObjectAttributesExact(num int) ObjectAttributes { - return ObjectAttributes{ +// an object has num attributes. +func ObjectAttributesExact(num int) objectAttributesExact { + return objectAttributesExact{ num: num, } } diff --git a/knownvalue/object_attributes_test.go b/knownvalue/object_attributes_test.go index 7de835c51..963af7495 100644 --- a/knownvalue/object_attributes_test.go +++ b/knownvalue/object_attributes_test.go @@ -16,29 +16,31 @@ func TestObjectAttributes_CheckValue(t *testing.T) { t.Parallel() testCases := map[string]struct { - self knownvalue.ObjectAttributes + self knownvalue.Check other any expectedError error }{ "zero-nil": { - expectedError: fmt.Errorf("expected map[string]any value for ObjectAttributes check, got: "), + self: knownvalue.ObjectAttributesExact(0), + expectedError: fmt.Errorf("expected map[string]any value for ObjectAttributesExact check, got: "), }, "zero-other": { + self: knownvalue.ObjectAttributesExact(0), other: map[string]any{}, // checking against the underlying value field zero-value }, "nil": { self: knownvalue.ObjectAttributesExact(3), - expectedError: fmt.Errorf("expected map[string]any value for ObjectAttributes check, got: "), + expectedError: fmt.Errorf("expected map[string]any value for ObjectAttributesExact check, got: "), }, "wrong-type": { self: knownvalue.ObjectAttributesExact(3), other: 1.234, - expectedError: fmt.Errorf("expected map[string]any value for ObjectAttributes check, got: float64"), + expectedError: fmt.Errorf("expected map[string]any value for ObjectAttributesExact check, got: float64"), }, "empty": { self: knownvalue.ObjectAttributesExact(3), other: map[string]any{}, - expectedError: fmt.Errorf("expected 3 attributes for ObjectAttributes check, got 0 attributes"), + expectedError: fmt.Errorf("expected 3 attributes for ObjectAttributesExact check, got 0 attributes"), }, "wrong-length": { self: knownvalue.ObjectAttributesExact(3), @@ -46,7 +48,7 @@ func TestObjectAttributes_CheckValue(t *testing.T) { "one": int64(123), "two": int64(456), }, - expectedError: fmt.Errorf("expected 3 attributes for ObjectAttributes check, got 2 attributes"), + expectedError: fmt.Errorf("expected 3 attributes for ObjectAttributesExact check, got 2 attributes"), }, "equal": { self: knownvalue.ObjectAttributesExact(3), diff --git a/knownvalue/object_partial.go b/knownvalue/object_partial.go index f024982b9..662edc735 100644 --- a/knownvalue/object_partial.go +++ b/knownvalue/object_partial.go @@ -8,18 +8,15 @@ import ( "sort" ) -var _ Check = ObjectValuePartial{} +var _ Check = objectValuePartial{} -// ObjectValuePartial is a Check for asserting partial equality between the -// value supplied to ObjectValuePartialMatch and the value passed to the -// CheckValue method. -type ObjectValuePartial struct { +type objectValuePartial struct { value map[string]Check } // CheckValue determines whether the passed value is of type map[string]any, and // contains matching map entries. -func (v ObjectValuePartial) CheckValue(other any) error { +func (v objectValuePartial) CheckValue(other any) error { otherVal, ok := other.(map[string]any) if !ok { @@ -52,7 +49,7 @@ func (v ObjectValuePartial) CheckValue(other any) error { } // String returns the string representation of the value. -func (v ObjectValuePartial) String() string { +func (v objectValuePartial) String() string { var keys []string for k := range v.value { @@ -72,12 +69,12 @@ func (v ObjectValuePartial) String() string { return fmt.Sprintf("%v", mapVals) } -// ObjectValuePartialMatch returns a Check for asserting partial equality between the +// ObjectValuePartial returns a Check for asserting partial equality between the // supplied map[string]Check and the value passed to the CheckValue method. The map // keys represent object attribute names. Only the object attributes defined by the // map keys within the supplied map[string]Check are checked. -func ObjectValuePartialMatch(value map[string]Check) ObjectValuePartial { - return ObjectValuePartial{ +func ObjectValuePartial(value map[string]Check) objectValuePartial { + return objectValuePartial{ value: value, } } diff --git a/knownvalue/object_partial_test.go b/knownvalue/object_partial_test.go index 150487c82..c0169f901 100644 --- a/knownvalue/object_partial_test.go +++ b/knownvalue/object_partial_test.go @@ -17,25 +17,27 @@ func TestObjectValuePartial_CheckValue(t *testing.T) { t.Parallel() testCases := map[string]struct { - self knownvalue.ObjectValuePartial + self knownvalue.Check other any expectedError error }{ "zero-nil": { + self: knownvalue.ObjectValuePartial(map[string]knownvalue.Check{}), expectedError: fmt.Errorf("expected map[string]any value for ObjectValuePartial check, got: "), }, "zero-other": { + self: knownvalue.ObjectValuePartial(map[string]knownvalue.Check{}), other: map[string]any{}, // checking against the underlying value field zero-value }, "nil": { - self: knownvalue.ObjectValuePartialMatch(map[string]knownvalue.Check{ + self: knownvalue.ObjectValuePartial(map[string]knownvalue.Check{ "one": knownvalue.Float64ValueExact(1.23), "three": knownvalue.Float64ValueExact(7.89), }), expectedError: fmt.Errorf("expected map[string]any value for ObjectValuePartial check, got: "), }, "wrong-type": { - self: knownvalue.ObjectValuePartialMatch(map[string]knownvalue.Check{ + self: knownvalue.ObjectValuePartial(map[string]knownvalue.Check{ "one": knownvalue.Float64ValueExact(1.23), "three": knownvalue.Float64ValueExact(7.89), }), @@ -43,7 +45,7 @@ func TestObjectValuePartial_CheckValue(t *testing.T) { expectedError: fmt.Errorf("expected map[string]any value for ObjectValuePartial check, got: float64"), }, "empty": { - self: knownvalue.ObjectValuePartialMatch(map[string]knownvalue.Check{ + self: knownvalue.ObjectValuePartial(map[string]knownvalue.Check{ "one": knownvalue.Float64ValueExact(1.23), "three": knownvalue.Float64ValueExact(7.89), }), @@ -51,7 +53,7 @@ func TestObjectValuePartial_CheckValue(t *testing.T) { expectedError: fmt.Errorf("missing attribute one for ObjectValuePartial check"), }, "wrong-length": { - self: knownvalue.ObjectValuePartialMatch(map[string]knownvalue.Check{ + self: knownvalue.ObjectValuePartial(map[string]knownvalue.Check{ "one": knownvalue.Float64ValueExact(1.23), "three": knownvalue.Float64ValueExact(7.89), }), @@ -62,7 +64,7 @@ func TestObjectValuePartial_CheckValue(t *testing.T) { expectedError: fmt.Errorf("missing attribute three for ObjectValuePartial check"), }, "not-equal": { - self: knownvalue.ObjectValuePartialMatch(map[string]knownvalue.Check{ + self: knownvalue.ObjectValuePartial(map[string]knownvalue.Check{ "one": knownvalue.Float64ValueExact(1.23), "three": knownvalue.Float64ValueExact(7.89), }), @@ -71,10 +73,10 @@ func TestObjectValuePartial_CheckValue(t *testing.T) { "two": json.Number("4.56"), "three": json.Number("6.54"), }, - expectedError: fmt.Errorf("three object attribute: expected value 7.89 for Float64Value check, got: 6.54"), + expectedError: fmt.Errorf("three object attribute: expected value 7.89 for Float64ValueExact check, got: 6.54"), }, "wrong-order": { - self: knownvalue.ObjectValuePartialMatch(map[string]knownvalue.Check{ + self: knownvalue.ObjectValuePartial(map[string]knownvalue.Check{ "one": knownvalue.Float64ValueExact(1.23), "three": knownvalue.Float64ValueExact(7.89), }), @@ -83,10 +85,10 @@ func TestObjectValuePartial_CheckValue(t *testing.T) { "two": json.Number("7.89"), "three": json.Number("4.56"), }, - expectedError: fmt.Errorf("three object attribute: expected value 7.89 for Float64Value check, got: 4.56"), + expectedError: fmt.Errorf("three object attribute: expected value 7.89 for Float64ValueExact check, got: 4.56"), }, "key-not-found": { - self: knownvalue.ObjectValuePartialMatch(map[string]knownvalue.Check{ + self: knownvalue.ObjectValuePartial(map[string]knownvalue.Check{ "one": knownvalue.Float64ValueExact(1.23), "two": knownvalue.Float64ValueExact(4.56), "three": knownvalue.Float64ValueExact(7.89), @@ -99,7 +101,7 @@ func TestObjectValuePartial_CheckValue(t *testing.T) { expectedError: fmt.Errorf("missing attribute one for ObjectValuePartial check"), }, "equal": { - self: knownvalue.ObjectValuePartialMatch(map[string]knownvalue.Check{ + self: knownvalue.ObjectValuePartial(map[string]knownvalue.Check{ "one": knownvalue.Float64ValueExact(1.23), "three": knownvalue.Float64ValueExact(7.89), }), @@ -129,7 +131,7 @@ func TestObjectValuePartial_CheckValue(t *testing.T) { func TestObjectValuePartial_String(t *testing.T) { t.Parallel() - got := knownvalue.ObjectValuePartialMatch(map[string]knownvalue.Check{ + got := knownvalue.ObjectValuePartial(map[string]knownvalue.Check{ "one": knownvalue.Float64ValueExact(1.23), "three": knownvalue.Float64ValueExact(7.89), }).String() diff --git a/knownvalue/object_test.go b/knownvalue/object_test.go index f281e3d6a..b6691c39f 100644 --- a/knownvalue/object_test.go +++ b/knownvalue/object_test.go @@ -17,14 +17,16 @@ func TestObjectValue_CheckValue(t *testing.T) { t.Parallel() testCases := map[string]struct { - self knownvalue.ObjectValue + self knownvalue.Check other any expectedError error }{ "zero-nil": { - expectedError: fmt.Errorf("expected map[string]any value for ObjectValue check, got: "), + self: knownvalue.ObjectValueExact(map[string]knownvalue.Check{}), + expectedError: fmt.Errorf("expected map[string]any value for ObjectValueExact check, got: "), }, "zero-other": { + self: knownvalue.ObjectValueExact(map[string]knownvalue.Check{}), other: map[string]any{}, // checking against the underlying value field zero-value }, "nil": { @@ -33,7 +35,7 @@ func TestObjectValue_CheckValue(t *testing.T) { "two": knownvalue.Float64ValueExact(4.56), "three": knownvalue.Float64ValueExact(7.89), }), - expectedError: fmt.Errorf("expected map[string]any value for ObjectValue check, got: "), + expectedError: fmt.Errorf("expected map[string]any value for ObjectValueExact check, got: "), }, "wrong-type": { self: knownvalue.ObjectValueExact(map[string]knownvalue.Check{ @@ -42,7 +44,7 @@ func TestObjectValue_CheckValue(t *testing.T) { "three": knownvalue.Float64ValueExact(7.89), }), other: 1.234, - expectedError: fmt.Errorf("expected map[string]any value for ObjectValue check, got: float64"), + expectedError: fmt.Errorf("expected map[string]any value for ObjectValueExact check, got: float64"), }, "empty": { self: knownvalue.ObjectValueExact(map[string]knownvalue.Check{ @@ -51,7 +53,7 @@ func TestObjectValue_CheckValue(t *testing.T) { "three": knownvalue.Float64ValueExact(7.89), }), other: map[string]any{}, - expectedError: fmt.Errorf("expected 3 attributes for ObjectValue check, got 0 attributes"), + expectedError: fmt.Errorf("expected 3 attributes for ObjectValueExact check, got 0 attributes"), }, "wrong-length": { self: knownvalue.ObjectValueExact(map[string]knownvalue.Check{ @@ -63,7 +65,7 @@ func TestObjectValue_CheckValue(t *testing.T) { "one": json.Number("1.23"), "two": json.Number("4.56"), }, - expectedError: fmt.Errorf("expected 3 attributes for ObjectValue check, got 2 attributes"), + expectedError: fmt.Errorf("expected 3 attributes for ObjectValueExact check, got 2 attributes"), }, "not-equal": { self: knownvalue.ObjectValueExact(map[string]knownvalue.Check{ @@ -76,7 +78,7 @@ func TestObjectValue_CheckValue(t *testing.T) { "two": json.Number("4.56"), "three": json.Number("6.54"), }, - expectedError: fmt.Errorf("three object attribute: expected value 7.89 for Float64Value check, got: 6.54"), + expectedError: fmt.Errorf("three object attribute: expected value 7.89 for Float64ValueExact check, got: 6.54"), }, "wrong-order": { self: knownvalue.ObjectValueExact(map[string]knownvalue.Check{ @@ -89,7 +91,7 @@ func TestObjectValue_CheckValue(t *testing.T) { "two": json.Number("7.89"), "three": json.Number("4.56"), }, - expectedError: fmt.Errorf("three object attribute: expected value 7.89 for Float64Value check, got: 4.56"), + expectedError: fmt.Errorf("three object attribute: expected value 7.89 for Float64ValueExact check, got: 4.56"), }, "key-not-found": { self: knownvalue.ObjectValueExact(map[string]knownvalue.Check{ @@ -102,7 +104,7 @@ func TestObjectValue_CheckValue(t *testing.T) { "five": json.Number("7.89"), "six": json.Number("4.56"), }, - expectedError: fmt.Errorf("missing attribute one for ObjectValue check"), + expectedError: fmt.Errorf("missing attribute one for ObjectValueExact check"), }, "equal": { self: knownvalue.ObjectValueExact(map[string]knownvalue.Check{ diff --git a/knownvalue/set.go b/knownvalue/set.go index 54996f164..c8c3ada22 100644 --- a/knownvalue/set.go +++ b/knownvalue/set.go @@ -7,21 +7,19 @@ import ( "fmt" ) -var _ Check = SetValue{} +var _ Check = setValueExact{} -// SetValue is a Check for asserting equality between the value supplied -// to SetValueExact and the value passed to the CheckValue method. -type SetValue struct { +type setValueExact struct { value []Check } // CheckValue determines whether the passed value is of type []any, and // contains matching slice entries independent of the sequence. -func (v SetValue) CheckValue(other any) error { +func (v setValueExact) CheckValue(other any) error { otherVal, ok := other.([]any) if !ok { - return fmt.Errorf("expected []any value for SetValue check, got: %T", other) + return fmt.Errorf("expected []any value for SetValueExact check, got: %T", other) } if len(otherVal) != len(v.value) { @@ -36,7 +34,7 @@ func (v SetValue) CheckValue(other any) error { actualElements = "element" } - return fmt.Errorf("expected %d %s for SetValue check, got %d %s", len(v.value), expectedElements, len(otherVal), actualElements) + return fmt.Errorf("expected %d %s for SetValueExact check, got %d %s", len(v.value), expectedElements, len(otherVal), actualElements) } otherValCopy := make([]any, len(otherVal)) @@ -44,7 +42,7 @@ func (v SetValue) CheckValue(other any) error { copy(otherValCopy, otherVal) for i := 0; i < len(v.value); i++ { - err := fmt.Errorf("missing value %s for SetValue check", v.value[i].String()) + err := fmt.Errorf("missing value %s for SetValueExact check", v.value[i].String()) for j := 0; j < len(otherValCopy); j++ { checkValueErr := v.value[i].CheckValue(otherValCopy[j]) @@ -68,7 +66,7 @@ func (v SetValue) CheckValue(other any) error { } // String returns the string representation of the value. -func (v SetValue) String() string { +func (v setValueExact) String() string { var setVals []string for _, val := range v.value { @@ -81,8 +79,8 @@ func (v SetValue) String() string { // SetValueExact returns a Check for asserting equality between the // supplied []Check and the value passed to the CheckValue method. // This is an order-independent check. -func SetValueExact(value []Check) SetValue { - return SetValue{ +func SetValueExact(value []Check) setValueExact { + return setValueExact{ value: value, } } diff --git a/knownvalue/set_elements.go b/knownvalue/set_elements.go index 25312b163..37d5f38ea 100644 --- a/knownvalue/set_elements.go +++ b/knownvalue/set_elements.go @@ -8,21 +8,19 @@ import ( "strconv" ) -var _ Check = SetElements{} +var _ Check = setElementsExact{} -// SetElements is a Check for asserting equality between the value supplied -// to SetElementsExact and the value passed to the CheckValue method. -type SetElements struct { +type setElementsExact struct { num int } // CheckValue verifies that the passed value is a list, map, object, // or set, and contains a matching number of elements. -func (v SetElements) CheckValue(other any) error { +func (v setElementsExact) CheckValue(other any) error { otherVal, ok := other.([]any) if !ok { - return fmt.Errorf("expected []any value for SetElements check, got: %T", other) + return fmt.Errorf("expected []any value for SetElementExact check, got: %T", other) } if len(otherVal) != v.num { @@ -37,21 +35,21 @@ func (v SetElements) CheckValue(other any) error { actualElements = "element" } - return fmt.Errorf("expected %d %s for SetElements check, got %d %s", v.num, expectedElements, len(otherVal), actualElements) + return fmt.Errorf("expected %d %s for SetElementExact check, got %d %s", v.num, expectedElements, len(otherVal), actualElements) } return nil } // String returns the string representation of the value. -func (v SetElements) String() string { +func (v setElementsExact) String() string { return strconv.FormatInt(int64(v.num), 10) } // SetElementsExact returns a Check for asserting that -// a list num elements. -func SetElementsExact(num int) SetElements { - return SetElements{ +// a set has num elements. +func SetElementsExact(num int) setElementsExact { + return setElementsExact{ num: num, } } diff --git a/knownvalue/set_elements_test.go b/knownvalue/set_elements_test.go index 522287dc3..cd2be6e36 100644 --- a/knownvalue/set_elements_test.go +++ b/knownvalue/set_elements_test.go @@ -16,29 +16,31 @@ func TestSetElements_CheckValue(t *testing.T) { t.Parallel() testCases := map[string]struct { - self knownvalue.SetElements + self knownvalue.Check other any expectedError error }{ "zero-nil": { - expectedError: fmt.Errorf("expected []any value for SetElements check, got: "), + self: knownvalue.SetElementsExact(0), + expectedError: fmt.Errorf("expected []any value for SetElementExact check, got: "), }, "zero-other": { + self: knownvalue.SetElementsExact(0), other: []any{}, // checking against the underlying value field zero-value }, "nil": { self: knownvalue.SetElementsExact(3), - expectedError: fmt.Errorf("expected []any value for SetElements check, got: "), + expectedError: fmt.Errorf("expected []any value for SetElementExact check, got: "), }, "wrong-type": { self: knownvalue.SetElementsExact(3), other: 1.234, - expectedError: fmt.Errorf("expected []any value for SetElements check, got: float64"), + expectedError: fmt.Errorf("expected []any value for SetElementExact check, got: float64"), }, "empty": { self: knownvalue.SetElementsExact(3), other: []any{}, - expectedError: fmt.Errorf("expected 3 elements for SetElements check, got 0 elements"), + expectedError: fmt.Errorf("expected 3 elements for SetElementExact check, got 0 elements"), }, "wrong-length": { self: knownvalue.SetElementsExact(3), @@ -46,7 +48,7 @@ func TestSetElements_CheckValue(t *testing.T) { int64(123), int64(456), }, - expectedError: fmt.Errorf("expected 3 elements for SetElements check, got 2 elements"), + expectedError: fmt.Errorf("expected 3 elements for SetElementExact check, got 2 elements"), }, "equal": { self: knownvalue.SetElementsExact(3), diff --git a/knownvalue/set_partial.go b/knownvalue/set_partial.go index 89da7510b..ba9717dc8 100644 --- a/knownvalue/set_partial.go +++ b/knownvalue/set_partial.go @@ -7,18 +7,15 @@ import ( "fmt" ) -var _ Check = SetValuePartial{} +var _ Check = setValuePartial{} -// SetValuePartial is a Check for asserting partial equality between the -// value supplied to SetValuePartialMatch and the value passed to the -// CheckValue method. -type SetValuePartial struct { +type setValuePartial struct { value []Check } // CheckValue determines whether the passed value is of type []any, and // contains matching slice entries in any sequence. -func (v SetValuePartial) CheckValue(other any) error { +func (v setValuePartial) CheckValue(other any) error { otherVal, ok := other.([]any) if !ok { @@ -54,7 +51,7 @@ func (v SetValuePartial) CheckValue(other any) error { } // String returns the string representation of the value. -func (v SetValuePartial) String() string { +func (v setValuePartial) String() string { var setVals []string for _, val := range v.value { @@ -64,12 +61,12 @@ func (v SetValuePartial) String() string { return fmt.Sprintf("%s", setVals) } -// SetValuePartialMatch returns a Check for asserting partial equality between the +// SetValuePartial returns a Check for asserting partial equality between the // supplied []Check and the value passed to the CheckValue method. Only the // elements defined within the supplied []Check are checked. This is an // order-independent check. -func SetValuePartialMatch(value []Check) SetValuePartial { - return SetValuePartial{ +func SetValuePartial(value []Check) setValuePartial { + return setValuePartial{ value: value, } } diff --git a/knownvalue/set_partial_test.go b/knownvalue/set_partial_test.go index 63d02d404..49f15cbdc 100644 --- a/knownvalue/set_partial_test.go +++ b/knownvalue/set_partial_test.go @@ -17,18 +17,20 @@ func TestSetValuePartial_CheckValue(t *testing.T) { t.Parallel() testCases := map[string]struct { - self knownvalue.SetValuePartial + self knownvalue.Check other any expectedError error }{ "zero-nil": { + self: knownvalue.SetValuePartial([]knownvalue.Check{}), expectedError: fmt.Errorf("expected []any value for SetValuePartial check, got: "), }, "zero-other": { + self: knownvalue.SetValuePartial([]knownvalue.Check{}), other: []any{}, // checking against the underlying value field zero-value }, "nil": { - self: knownvalue.SetValuePartialMatch([]knownvalue.Check{ + self: knownvalue.SetValuePartial([]knownvalue.Check{ knownvalue.Float64ValueExact(1.23), knownvalue.Float64ValueExact(4.56), knownvalue.Float64ValueExact(7.89), @@ -36,7 +38,7 @@ func TestSetValuePartial_CheckValue(t *testing.T) { expectedError: fmt.Errorf("expected []any value for SetValuePartial check, got: "), }, "wrong-type": { - self: knownvalue.SetValuePartialMatch([]knownvalue.Check{ + self: knownvalue.SetValuePartial([]knownvalue.Check{ knownvalue.Float64ValueExact(1.23), knownvalue.Float64ValueExact(4.56), knownvalue.Float64ValueExact(7.89), @@ -45,7 +47,7 @@ func TestSetValuePartial_CheckValue(t *testing.T) { expectedError: fmt.Errorf("expected []any value for SetValuePartial check, got: float64"), }, "equal-empty": { - self: knownvalue.SetValuePartialMatch([]knownvalue.Check{ + self: knownvalue.SetValuePartial([]knownvalue.Check{ knownvalue.Float64ValueExact(1.23), knownvalue.Float64ValueExact(4.56), knownvalue.Float64ValueExact(7.89), @@ -54,7 +56,7 @@ func TestSetValuePartial_CheckValue(t *testing.T) { expectedError: fmt.Errorf("missing value 1.23 for SetValuePartial check"), }, "not-equal": { - self: knownvalue.SetValuePartialMatch([]knownvalue.Check{ + self: knownvalue.SetValuePartial([]knownvalue.Check{ knownvalue.Float64ValueExact(1.23), knownvalue.Float64ValueExact(4.56), knownvalue.Float64ValueExact(7.89), @@ -68,7 +70,7 @@ func TestSetValuePartial_CheckValue(t *testing.T) { expectedError: fmt.Errorf("missing value 7.89 for SetValuePartial check"), }, "equal-different-order": { - self: knownvalue.SetValuePartialMatch([]knownvalue.Check{ + self: knownvalue.SetValuePartial([]knownvalue.Check{ knownvalue.Float64ValueExact(1.23), knownvalue.Float64ValueExact(4.56), knownvalue.Float64ValueExact(7.89), @@ -81,7 +83,7 @@ func TestSetValuePartial_CheckValue(t *testing.T) { }, }, "equal-same-order": { - self: knownvalue.SetValuePartialMatch([]knownvalue.Check{ + self: knownvalue.SetValuePartial([]knownvalue.Check{ knownvalue.Float64ValueExact(1.23), knownvalue.Float64ValueExact(4.56), knownvalue.Float64ValueExact(7.89), @@ -113,7 +115,7 @@ func TestSetValuePartial_CheckValue(t *testing.T) { func TestSetValuePartial_String(t *testing.T) { t.Parallel() - got := knownvalue.SetValuePartialMatch([]knownvalue.Check{ + got := knownvalue.SetValuePartial([]knownvalue.Check{ knownvalue.Float64ValueExact(1.23), knownvalue.Float64ValueExact(4.56), knownvalue.Float64ValueExact(7.89), diff --git a/knownvalue/set_test.go b/knownvalue/set_test.go index e89c89386..ebe03ec3d 100644 --- a/knownvalue/set_test.go +++ b/knownvalue/set_test.go @@ -17,14 +17,16 @@ func TestSetValue_CheckValue(t *testing.T) { t.Parallel() testCases := map[string]struct { - self knownvalue.SetValue + self knownvalue.Check other any expectedError error }{ "zero-nil": { - expectedError: fmt.Errorf("expected []any value for SetValue check, got: "), + self: knownvalue.SetValueExact([]knownvalue.Check{}), + expectedError: fmt.Errorf("expected []any value for SetValueExact check, got: "), }, "zero-other": { + self: knownvalue.SetValueExact([]knownvalue.Check{}), other: []any{}, // checking against the underlying value field zero-value }, "nil": { @@ -33,7 +35,7 @@ func TestSetValue_CheckValue(t *testing.T) { knownvalue.Int64ValueExact(456), knownvalue.Int64ValueExact(789), }), - expectedError: fmt.Errorf("expected []any value for SetValue check, got: "), + expectedError: fmt.Errorf("expected []any value for SetValueExact check, got: "), }, "wrong-type": { self: knownvalue.SetValueExact([]knownvalue.Check{ @@ -42,7 +44,7 @@ func TestSetValue_CheckValue(t *testing.T) { knownvalue.Int64ValueExact(789), }), other: 1.234, - expectedError: fmt.Errorf("expected []any value for SetValue check, got: float64"), + expectedError: fmt.Errorf("expected []any value for SetValueExact check, got: float64"), }, "empty": { self: knownvalue.SetValueExact([]knownvalue.Check{ @@ -51,7 +53,7 @@ func TestSetValue_CheckValue(t *testing.T) { knownvalue.Int64ValueExact(789), }), other: []any{}, - expectedError: fmt.Errorf("expected 3 elements for SetValue check, got 0 elements"), + expectedError: fmt.Errorf("expected 3 elements for SetValueExact check, got 0 elements"), }, "wrong-length": { self: knownvalue.SetValueExact([]knownvalue.Check{ @@ -63,7 +65,7 @@ func TestSetValue_CheckValue(t *testing.T) { json.Number("123"), json.Number("456"), }, - expectedError: fmt.Errorf("expected 3 elements for SetValue check, got 2 elements"), + expectedError: fmt.Errorf("expected 3 elements for SetValueExact check, got 2 elements"), }, "not-equal": { self: knownvalue.SetValueExact([]knownvalue.Check{ @@ -76,7 +78,7 @@ func TestSetValue_CheckValue(t *testing.T) { json.Number("456"), json.Number("654"), }, - expectedError: fmt.Errorf("missing value 789 for SetValue check"), + expectedError: fmt.Errorf("missing value 789 for SetValueExact check"), }, "equal-different-order": { self: knownvalue.SetValueExact([]knownvalue.Check{ diff --git a/knownvalue/string.go b/knownvalue/string.go index 7ccc58aca..3686d5dda 100644 --- a/knownvalue/string.go +++ b/knownvalue/string.go @@ -5,39 +5,37 @@ package knownvalue import "fmt" -var _ Check = StringValue{} +var _ Check = stringValueExact{} -// StringValue is a Check for asserting equality between the value -// supplied to StringValueExact and the value passed to the CheckValue method. -type StringValue struct { +type stringValueExact struct { value string } // CheckValue determines whether the passed value is of type string, and // contains a matching sequence of bytes. -func (v StringValue) CheckValue(other any) error { +func (v stringValueExact) CheckValue(other any) error { otherVal, ok := other.(string) if !ok { - return fmt.Errorf("expected string value for StringValue check, got: %T", other) + return fmt.Errorf("expected string value for StringValueExact check, got: %T", other) } if otherVal != v.value { - return fmt.Errorf("expected value %s for StringValue check, got: %s", v.value, otherVal) + return fmt.Errorf("expected value %s for StringValueExact check, got: %s", v.value, otherVal) } return nil } // String returns the string representation of the value. -func (v StringValue) String() string { +func (v stringValueExact) String() string { return v.value } // StringValueExact returns a Check for asserting equality between the // supplied string and a value passed to the CheckValue method. -func StringValueExact(value string) StringValue { - return StringValue{ +func StringValueExact(value string) stringValueExact { + return stringValueExact{ value: value, } } diff --git a/knownvalue/string_test.go b/knownvalue/string_test.go index a08a53ee6..e97feaa92 100644 --- a/knownvalue/string_test.go +++ b/knownvalue/string_test.go @@ -16,29 +16,31 @@ func TestStringValue_CheckValue(t *testing.T) { t.Parallel() testCases := map[string]struct { - self knownvalue.StringValue + self knownvalue.Check other any expectedError error }{ "zero-nil": { - expectedError: fmt.Errorf("expected string value for StringValue check, got: "), + self: knownvalue.StringValueExact(""), + expectedError: fmt.Errorf("expected string value for StringValueExact check, got: "), }, "zero-other": { + self: knownvalue.StringValueExact(""), other: "", // checking against the underlying value field zero-value }, "nil": { self: knownvalue.StringValueExact("str"), - expectedError: fmt.Errorf("expected string value for StringValue check, got: "), + expectedError: fmt.Errorf("expected string value for StringValueExact check, got: "), }, "wrong-type": { self: knownvalue.StringValueExact("str"), other: 1.234, - expectedError: fmt.Errorf("expected string value for StringValue check, got: float64"), + expectedError: fmt.Errorf("expected string value for StringValueExact check, got: float64"), }, "not-equal": { self: knownvalue.StringValueExact("str"), other: "rts", - expectedError: fmt.Errorf("expected value str for StringValue check, got: rts"), + expectedError: fmt.Errorf("expected value str for StringValueExact check, got: rts"), }, "equal": { self: knownvalue.StringValueExact("str"), diff --git a/plancheck/expect_known_output_value_at_path_test.go b/plancheck/expect_known_output_value_at_path_test.go index ba3f2070f..fc44e6e3a 100644 --- a/plancheck/expect_known_output_value_at_path_test.go +++ b/plancheck/expect_known_output_value_at_path_test.go @@ -176,7 +176,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_Bool_KnownValueWrongType(t *test ), }, }, - ExpectError: regexp.MustCompile(`expected json\.Number value for Float64Value check, got: bool`), + ExpectError: regexp.MustCompile(`expected json\.Number value for Float64ValueExact check, got: bool`), }, }, }) @@ -217,7 +217,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_Bool_KnownValueWrongValue(t *tes ), }, }, - ExpectError: regexp.MustCompile("expected value false for BoolValue check, got: true"), + ExpectError: regexp.MustCompile("expected value false for BoolValueExact check, got: true"), }, }, }) @@ -299,7 +299,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_Float64_KnownValueWrongType(t *t ), }, }, - ExpectError: regexp.MustCompile(`expected string value for StringValue check, got: json\.Number`), + ExpectError: regexp.MustCompile(`expected string value for StringValueExact check, got: json\.Number`), }, }, }) @@ -340,7 +340,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_Float64_KnownValueWrongValue(t * ), }, }, - ExpectError: regexp.MustCompile("expected value 3.21 for Float64Value check, got: 1.23"), + ExpectError: regexp.MustCompile("expected value 3.21 for Float64ValueExact check, got: 1.23"), }, }, }) @@ -421,7 +421,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_Int64_KnownValueWrongValue(t *te ), }, }, - ExpectError: regexp.MustCompile("expected value 321 for Int64Value check, got: 123"), + ExpectError: regexp.MustCompile("expected value 321 for Int64ValueExact check, got: 123"), }, }, }) @@ -511,7 +511,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_List_KnownValueWrongType(t *test ), }, }, - ExpectError: regexp.MustCompile(`expected map\[string\]any value for MapValue check, got: \[\]interface {}`), + ExpectError: regexp.MustCompile(`expected map\[string\]any value for MapValueExact check, got: \[\]interface {}`), }, }, }) @@ -558,7 +558,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_List_KnownValueWrongValue(t *tes ), }, }, - ExpectError: regexp.MustCompile(`list element index 0: expected value value3 for StringValue check, got: value1`), + ExpectError: regexp.MustCompile(`list element index 0: expected value value3 for StringValueExact check, got: value1`), }, }, }) @@ -598,7 +598,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_ListPartial(t *testing.T) { plancheck.ExpectKnownOutputValueAtPath( "test_resource_one_output", tfjsonpath.New("list_attribute"), - knownvalue.ListValuePartialMatch(map[int]knownvalue.Check{ + knownvalue.ListValuePartial(map[int]knownvalue.Check{ 0: knownvalue.StringValueExact("value1"), }), ), @@ -645,13 +645,13 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_ListPartial_KnownValueWrongValue plancheck.ExpectKnownOutputValueAtPath( "test_resource_one_output", tfjsonpath.New("list_attribute"), - knownvalue.ListValuePartialMatch(map[int]knownvalue.Check{ + knownvalue.ListValuePartial(map[int]knownvalue.Check{ 0: knownvalue.StringValueExact("value3"), }), ), }, }, - ExpectError: regexp.MustCompile(`list element 0: expected value value3 for StringValue check, got: value1`), + ExpectError: regexp.MustCompile(`list element 0: expected value value3 for StringValueExact check, got: value1`), }, }, }) @@ -738,7 +738,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_ListElements_WrongNum(t *testing ), }, }, - ExpectError: regexp.MustCompile("expected 3 elements for ListElements check, got 2 elements"), + ExpectError: regexp.MustCompile("expected 3 elements for ListElementsExact check, got 2 elements"), }, }, }) @@ -832,7 +832,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_ListNestedBlockPartial(t *testin plancheck.ExpectKnownOutputValueAtPath( "test_resource_one_output", tfjsonpath.New("list_nested_block"), - knownvalue.ListValuePartialMatch(map[int]knownvalue.Check{ + knownvalue.ListValuePartial(map[int]knownvalue.Check{ 1: knownvalue.MapValueExact(map[string]knownvalue.Check{ "list_nested_block_attribute": knownvalue.StringValueExact("rts"), }), @@ -974,7 +974,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_Map_KnownValueWrongType(t *testi ), }, }, - ExpectError: regexp.MustCompile(`expected \[\]any value for ListValue check, got: map\[string\]interface {}`), + ExpectError: regexp.MustCompile(`expected \[\]any value for ListValueExact check, got: map\[string\]interface {}`), }, }, }) @@ -1021,7 +1021,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_Map_KnownValueWrongValue(t *test ), }, }, - ExpectError: regexp.MustCompile(`missing element key3 for MapValue check`), + ExpectError: regexp.MustCompile(`missing element key3 for MapValueExact check`), }, }, }) @@ -1061,7 +1061,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_MapPartial(t *testing.T) { plancheck.ExpectKnownOutputValueAtPath( "test_resource_one_output", tfjsonpath.New("map_attribute"), - knownvalue.MapValuePartialMatch(map[string]knownvalue.Check{ + knownvalue.MapValuePartial(map[string]knownvalue.Check{ "key1": knownvalue.StringValueExact("value1"), }), ), @@ -1106,7 +1106,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_MapPartial_KnownValueWrongValue( plancheck.ExpectKnownOutputValueAtPath( "test_resource_one_output", tfjsonpath.New("map_attribute"), - knownvalue.MapValuePartialMatch(map[string]knownvalue.Check{ + knownvalue.MapValuePartial(map[string]knownvalue.Check{ "key3": knownvalue.StringValueExact("value1"), }), ), @@ -1199,7 +1199,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_MapElements_WrongNum(t *testing. ), }, }, - ExpectError: regexp.MustCompile("expected 3 elements for MapElements check, got 2 elements"), + ExpectError: regexp.MustCompile("expected 3 elements for MapElementsExact check, got 2 elements"), }, }, }) @@ -1292,7 +1292,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_Number_KnownValueWrongValue(t *t ), }, }, - ExpectError: regexp.MustCompile("expected value 321 for NumberValue check, got: 123"), + ExpectError: regexp.MustCompile("expected value 321 for NumberValueExact check, got: 123"), }, }, }) @@ -1385,7 +1385,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_Set_KnownValueWrongValue(t *test ), }, }, - ExpectError: regexp.MustCompile(`missing value value3 for SetValue check`), + ExpectError: regexp.MustCompile(`missing value value3 for SetValueExact check`), }, }, }) @@ -1425,7 +1425,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_SetPartial(t *testing.T) { plancheck.ExpectKnownOutputValueAtPath( "test_resource_one_output", tfjsonpath.New("set_attribute"), - knownvalue.SetValuePartialMatch([]knownvalue.Check{ + knownvalue.SetValuePartial([]knownvalue.Check{ knownvalue.StringValueExact("value2"), }), ), @@ -1470,7 +1470,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_SetPartial_KnownValueWrongValue( plancheck.ExpectKnownOutputValueAtPath( "test_resource_one_output", tfjsonpath.New("set_attribute"), - knownvalue.SetValuePartialMatch([]knownvalue.Check{ + knownvalue.SetValuePartial([]knownvalue.Check{ knownvalue.StringValueExact("value3"), }), ), @@ -1613,7 +1613,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_SetNestedBlockPartial(t *testing plancheck.ExpectKnownOutputValueAtPath( "test_resource_one_output", tfjsonpath.New("set_nested_block"), - knownvalue.SetValuePartialMatch([]knownvalue.Check{ + knownvalue.SetValuePartial([]knownvalue.Check{ knownvalue.MapValueExact(map[string]knownvalue.Check{ "set_nested_block_attribute": knownvalue.StringValueExact("rts"), }), @@ -1744,7 +1744,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_String_KnownValueWrongType(t *te knownvalue.BoolValueExact(true)), }, }, - ExpectError: regexp.MustCompile("expected bool value for BoolValue check, got: string"), + ExpectError: regexp.MustCompile("expected bool value for BoolValueExact check, got: string"), }, }, }) @@ -1784,7 +1784,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_String_KnownValueWrongValue(t *t knownvalue.StringValueExact("rts")), }, }, - ExpectError: regexp.MustCompile("expected value rts for StringValue check, got: str"), + ExpectError: regexp.MustCompile("expected value rts for StringValueExact check, got: str"), }, }, }) @@ -1809,7 +1809,7 @@ func TestExpectKnownOutputValueAtPath_CheckPlan_UnknownAttributeType(t *testing. }, }, }, - expectedErr: fmt.Errorf("unrecognised output type: float32, known value type is knownvalue.Int64Value\n\nThis is an error in plancheck.ExpectKnownOutputValueAtPath.\nPlease report this to the maintainers."), + expectedErr: fmt.Errorf("unrecognised output type: float32, known value type is knownvalue.int64ValueExact\n\nThis is an error in plancheck.ExpectKnownOutputValueAtPath.\nPlease report this to the maintainers."), }, } diff --git a/plancheck/expect_known_output_value_test.go b/plancheck/expect_known_output_value_test.go index 6e6363ffd..88192ede3 100644 --- a/plancheck/expect_known_output_value_test.go +++ b/plancheck/expect_known_output_value_test.go @@ -141,7 +141,7 @@ func TestExpectKnownOutputValue_CheckPlan_Bool_KnownValueWrongType(t *testing.T) ), }, }, - ExpectError: regexp.MustCompile(`expected json\.Number value for Float64Value check, got: bool`), + ExpectError: regexp.MustCompile(`expected json\.Number value for Float64ValueExact check, got: bool`), }, }, }) @@ -174,7 +174,7 @@ func TestExpectKnownOutputValue_CheckPlan_Bool_KnownValueWrongValue(t *testing.T ), }, }, - ExpectError: regexp.MustCompile("expected value false for BoolValue check, got: true"), + ExpectError: regexp.MustCompile("expected value false for BoolValueExact check, got: true"), }, }, }) @@ -240,7 +240,7 @@ func TestExpectKnownOutputValue_CheckPlan_Float64_KnownValueWrongType(t *testing ), }, }, - ExpectError: regexp.MustCompile(`expected string value for StringValue check, got: json\.Number`), + ExpectError: regexp.MustCompile(`expected string value for StringValueExact check, got: json\.Number`), }, }, }) @@ -273,7 +273,7 @@ func TestExpectKnownOutputValue_CheckPlan_Float64_KnownValueWrongValue(t *testin ), }, }, - ExpectError: regexp.MustCompile("expected value 3.21 for Float64Value check, got: 1.23"), + ExpectError: regexp.MustCompile("expected value 3.21 for Float64ValueExact check, got: 1.23"), }, }, }) @@ -338,7 +338,7 @@ func TestExpectKnownOutputValue_CheckPlan_Int64_KnownValueWrongValue(t *testing. ), }, }, - ExpectError: regexp.MustCompile("expected value 321 for Int64Value check, got: 123"), + ExpectError: regexp.MustCompile("expected value 321 for Int64ValueExact check, got: 123"), }, }, }) @@ -412,7 +412,7 @@ func TestExpectKnownOutputValue_CheckPlan_List_KnownValueWrongType(t *testing.T) ), }, }, - ExpectError: regexp.MustCompile(`expected map\[string\]any value for MapValue check, got: \[\]interface {}`), + ExpectError: regexp.MustCompile(`expected map\[string\]any value for MapValueExact check, got: \[\]interface {}`), }, }, }) @@ -451,7 +451,7 @@ func TestExpectKnownOutputValue_CheckPlan_List_KnownValueWrongValue(t *testing.T ), }, }, - ExpectError: regexp.MustCompile(`list element index 0: expected value value3 for StringValue check, got: value1`), + ExpectError: regexp.MustCompile(`list element index 0: expected value value3 for StringValueExact check, got: value1`), }, }, }) @@ -483,7 +483,7 @@ func TestExpectKnownOutputValue_CheckPlan_ListPartial(t *testing.T) { PreApply: []plancheck.PlanCheck{ plancheck.ExpectKnownOutputValue( "list_output", - knownvalue.ListValuePartialMatch(map[int]knownvalue.Check{ + knownvalue.ListValuePartial(map[int]knownvalue.Check{ 0: knownvalue.StringValueExact("value1"), }), ), @@ -522,13 +522,13 @@ func TestExpectKnownOutputValue_CheckPlan_ListPartial_KnownValueWrongValue(t *te PreApply: []plancheck.PlanCheck{ plancheck.ExpectKnownOutputValue( "list_output", - knownvalue.ListValuePartialMatch(map[int]knownvalue.Check{ + knownvalue.ListValuePartial(map[int]knownvalue.Check{ 0: knownvalue.StringValueExact("value3"), }), ), }, }, - ExpectError: regexp.MustCompile(`list element 0: expected value value3 for StringValue check, got: value1`), + ExpectError: regexp.MustCompile(`list element 0: expected value value3 for StringValueExact check, got: value1`), }, }, }) @@ -599,7 +599,7 @@ func TestExpectKnownOutputValue_CheckPlan_ListElements_WrongNum(t *testing.T) { ), }, }, - ExpectError: regexp.MustCompile("expected 3 elements for ListElements check, got 2 elements"), + ExpectError: regexp.MustCompile("expected 3 elements for ListElementsExact check, got 2 elements"), }, }, }) @@ -677,7 +677,7 @@ func TestExpectKnownOutputValue_CheckPlan_ListNestedBlockPartial(t *testing.T) { PreApply: []plancheck.PlanCheck{ plancheck.ExpectKnownOutputValue( "list_nested_block_output", - knownvalue.ListValuePartialMatch(map[int]knownvalue.Check{ + knownvalue.ListValuePartial(map[int]knownvalue.Check{ 1: knownvalue.MapValueExact(map[string]knownvalue.Check{ "list_nested_block_attribute": knownvalue.StringValueExact("rts"), }), @@ -795,7 +795,7 @@ func TestExpectKnownOutputValue_CheckPlan_Map_KnownValueWrongType(t *testing.T) ), }, }, - ExpectError: regexp.MustCompile(`expected \[\]any value for ListValue check, got: map\[string\]interface {}`), + ExpectError: regexp.MustCompile(`expected \[\]any value for ListValueExact check, got: map\[string\]interface {}`), }, }, }) @@ -834,7 +834,7 @@ func TestExpectKnownOutputValue_CheckPlan_Map_KnownValueWrongValue(t *testing.T) ), }, }, - ExpectError: regexp.MustCompile(`missing element key3 for MapValue check`), + ExpectError: regexp.MustCompile(`missing element key3 for MapValueExact check`), }, }, }) @@ -866,7 +866,7 @@ func TestExpectKnownOutputValue_CheckPlan_MapPartial(t *testing.T) { PreApply: []plancheck.PlanCheck{ plancheck.ExpectKnownOutputValue( "map_output", - knownvalue.MapValuePartialMatch(map[string]knownvalue.Check{ + knownvalue.MapValuePartial(map[string]knownvalue.Check{ "key1": knownvalue.StringValueExact("value1"), }), ), @@ -903,7 +903,7 @@ func TestExpectKnownOutputValue_CheckPlan_MapPartial_KnownValueWrongValue(t *tes PreApply: []plancheck.PlanCheck{ plancheck.ExpectKnownOutputValue( "map_output", - knownvalue.MapValuePartialMatch(map[string]knownvalue.Check{ + knownvalue.MapValuePartial(map[string]knownvalue.Check{ "key3": knownvalue.StringValueExact("value1"), }), ), @@ -980,7 +980,7 @@ func TestExpectKnownOutputValue_CheckPlan_MapElements_WrongNum(t *testing.T) { ), }, }, - ExpectError: regexp.MustCompile("expected 3 elements for MapElements check, got 2 elements"), + ExpectError: regexp.MustCompile("expected 3 elements for MapElementsExact check, got 2 elements"), }, }, }) @@ -1057,7 +1057,7 @@ func TestExpectKnownOutputValue_CheckPlan_Number_KnownValueWrongValue(t *testing ), }, }, - ExpectError: regexp.MustCompile("expected value 321 for NumberValue check, got: 123"), + ExpectError: regexp.MustCompile("expected value 321 for NumberValueExact check, got: 123"), }, }, }) @@ -1134,7 +1134,7 @@ func TestExpectKnownOutputValue_CheckPlan_Set_KnownValueWrongValue(t *testing.T) ), }, }, - ExpectError: regexp.MustCompile(`missing value value3 for SetValue check`), + ExpectError: regexp.MustCompile(`missing value value3 for SetValueExact check`), }, }, }) @@ -1166,7 +1166,7 @@ func TestExpectKnownOutputValue_CheckPlan_SetPartial(t *testing.T) { PreApply: []plancheck.PlanCheck{ plancheck.ExpectKnownOutputValue( "set_output", - knownvalue.SetValuePartialMatch([]knownvalue.Check{ + knownvalue.SetValuePartial([]knownvalue.Check{ knownvalue.StringValueExact("value2"), }), ), @@ -1203,7 +1203,7 @@ func TestExpectKnownOutputValue_CheckPlan_SetPartial_KnownValueWrongValue(t *tes PreApply: []plancheck.PlanCheck{ plancheck.ExpectKnownOutputValue( "set_output", - knownvalue.SetValuePartialMatch([]knownvalue.Check{ + knownvalue.SetValuePartial([]knownvalue.Check{ knownvalue.StringValueExact("value3"), }), ), @@ -1322,7 +1322,7 @@ func TestExpectKnownOutputValue_CheckPlan_SetNestedBlockPartial(t *testing.T) { PreApply: []plancheck.PlanCheck{ plancheck.ExpectKnownOutputValue( "set_nested_block_output", - knownvalue.SetValuePartialMatch([]knownvalue.Check{ + knownvalue.SetValuePartial([]knownvalue.Check{ knownvalue.MapValueExact(map[string]knownvalue.Check{ "set_nested_block_attribute": knownvalue.StringValueExact("rts"), }), @@ -1429,7 +1429,7 @@ func TestExpectKnownOutputValue_CheckPlan_String_KnownValueWrongType(t *testing. knownvalue.BoolValueExact(true)), }, }, - ExpectError: regexp.MustCompile("expected bool value for BoolValue check, got: string"), + ExpectError: regexp.MustCompile("expected bool value for BoolValueExact check, got: string"), }, }, }) @@ -1461,7 +1461,7 @@ func TestExpectKnownOutputValue_CheckPlan_String_KnownValueWrongValue(t *testing knownvalue.StringValueExact("rts")), }, }, - ExpectError: regexp.MustCompile("expected value rts for StringValue check, got: str"), + ExpectError: regexp.MustCompile("expected value rts for StringValueExact check, got: str"), }, }, }) @@ -1486,7 +1486,7 @@ func TestExpectKnownOutputValue_CheckPlan_UnknownAttributeType(t *testing.T) { }, }, }, - expectedErr: fmt.Errorf("unrecognised output type: float32, known value type is knownvalue.Int64Value\n\nThis is an error in plancheck.ExpectKnownOutputValue.\nPlease report this to the maintainers."), + expectedErr: fmt.Errorf("unrecognised output type: float32, known value type is knownvalue.int64ValueExact\n\nThis is an error in plancheck.ExpectKnownOutputValue.\nPlease report this to the maintainers."), }, } diff --git a/plancheck/expect_known_value_test.go b/plancheck/expect_known_value_test.go index e4499bc01..05f87d226 100644 --- a/plancheck/expect_known_value_test.go +++ b/plancheck/expect_known_value_test.go @@ -130,7 +130,7 @@ func TestExpectKnownValue_CheckPlan_Bool_KnownValueWrongType(t *testing.T) { ), }, }, - ExpectError: regexp.MustCompile(`expected json\.Number value for Float64Value check, got: bool`), + ExpectError: regexp.MustCompile(`expected json\.Number value for Float64ValueExact check, got: bool`), }, }, }) @@ -160,7 +160,7 @@ func TestExpectKnownValue_CheckPlan_Bool_KnownValueWrongValue(t *testing.T) { ), }, }, - ExpectError: regexp.MustCompile("expected value false for BoolValue check, got: true"), + ExpectError: regexp.MustCompile("expected value false for BoolValueExact check, got: true"), }, }, }) @@ -220,7 +220,7 @@ func TestExpectKnownValue_CheckPlan_Float64_KnownValueWrongType(t *testing.T) { ), }, }, - ExpectError: regexp.MustCompile(`expected string value for StringValue check, got: json\.Number`), + ExpectError: regexp.MustCompile(`expected string value for StringValueExact check, got: json\.Number`), }, }, }) @@ -250,7 +250,7 @@ func TestExpectKnownValue_CheckPlan_Float64_KnownValueWrongValue(t *testing.T) { ), }, }, - ExpectError: regexp.MustCompile("expected value 3.21 for Float64Value check, got: 1.23"), + ExpectError: regexp.MustCompile("expected value 3.21 for Float64ValueExact check, got: 1.23"), }, }, }) @@ -309,7 +309,7 @@ func TestExpectKnownValue_CheckPlan_Int64_KnownValueWrongValue(t *testing.T) { ), }, }, - ExpectError: regexp.MustCompile("expected value 321 for Int64Value check, got: 123"), + ExpectError: regexp.MustCompile("expected value 321 for Int64ValueExact check, got: 123"), }, }, }) @@ -377,7 +377,7 @@ func TestExpectKnownValue_CheckPlan_List_KnownValueWrongType(t *testing.T) { ), }, }, - ExpectError: regexp.MustCompile(`expected map\[string\]any value for MapValue check, got: \[\]interface {}`), + ExpectError: regexp.MustCompile(`expected map\[string\]any value for MapValueExact check, got: \[\]interface {}`), }, }, }) @@ -413,7 +413,7 @@ func TestExpectKnownValue_CheckPlan_List_KnownValueWrongValue(t *testing.T) { ), }, }, - ExpectError: regexp.MustCompile(`list element index 0: expected value value3 for StringValue check, got: value1`), + ExpectError: regexp.MustCompile(`list element index 0: expected value value3 for StringValueExact check, got: value1`), }, }, }) @@ -442,7 +442,7 @@ func TestExpectKnownValue_CheckPlan_ListPartial(t *testing.T) { plancheck.ExpectKnownValue( "test_resource.one", tfjsonpath.New("list_attribute"), - knownvalue.ListValuePartialMatch(map[int]knownvalue.Check{ + knownvalue.ListValuePartial(map[int]knownvalue.Check{ 0: knownvalue.StringValueExact("value1"), }), ), @@ -478,13 +478,13 @@ func TestExpectKnownValue_CheckPlan_ListPartial_KnownValueWrongValue(t *testing. plancheck.ExpectKnownValue( "test_resource.one", tfjsonpath.New("list_attribute"), - knownvalue.ListValuePartialMatch(map[int]knownvalue.Check{ + knownvalue.ListValuePartial(map[int]knownvalue.Check{ 0: knownvalue.StringValueExact("value3"), }), ), }, }, - ExpectError: regexp.MustCompile(`list element 0: expected value value3 for StringValue check, got: value1`), + ExpectError: regexp.MustCompile(`list element 0: expected value value3 for StringValueExact check, got: value1`), }, }, }) @@ -549,7 +549,7 @@ func TestExpectKnownValue_CheckPlan_ListElements_WrongNum(t *testing.T) { ), }, }, - ExpectError: regexp.MustCompile("expected 3 elements for ListElements check, got 2 elements"), + ExpectError: regexp.MustCompile("expected 3 elements for ListElementsExact check, got 2 elements"), }, }, }) @@ -621,7 +621,7 @@ func TestExpectKnownValue_CheckPlan_ListNestedBlockPartial(t *testing.T) { plancheck.ExpectKnownValue( "test_resource.one", tfjsonpath.New("list_nested_block"), - knownvalue.ListValuePartialMatch(map[int]knownvalue.Check{ + knownvalue.ListValuePartial(map[int]knownvalue.Check{ 1: knownvalue.MapValueExact(map[string]knownvalue.Check{ "list_nested_block_attribute": knownvalue.StringValueExact("rts"), }), @@ -730,7 +730,7 @@ func TestExpectKnownValue_CheckPlan_Map_KnownValueWrongType(t *testing.T) { ), }, }, - ExpectError: regexp.MustCompile(`expected \[\]any value for ListValue check, got: map\[string\]interface {}`), + ExpectError: regexp.MustCompile(`expected \[\]any value for ListValueExact check, got: map\[string\]interface {}`), }, }, }) @@ -766,7 +766,7 @@ func TestExpectKnownValue_CheckPlan_Map_KnownValueWrongValue(t *testing.T) { ), }, }, - ExpectError: regexp.MustCompile(`missing element key3 for MapValue check`), + ExpectError: regexp.MustCompile(`missing element key3 for MapValueExact check`), }, }, }) @@ -795,7 +795,7 @@ func TestExpectKnownValue_CheckPlan_MapPartial(t *testing.T) { plancheck.ExpectKnownValue( "test_resource.one", tfjsonpath.New("map_attribute"), - knownvalue.MapValuePartialMatch(map[string]knownvalue.Check{ + knownvalue.MapValuePartial(map[string]knownvalue.Check{ "key1": knownvalue.StringValueExact("value1"), }), ), @@ -829,7 +829,7 @@ func TestExpectKnownValue_CheckPlan_MapPartial_KnownValueWrongValue(t *testing.T plancheck.ExpectKnownValue( "test_resource.one", tfjsonpath.New("map_attribute"), - knownvalue.MapValuePartialMatch(map[string]knownvalue.Check{ + knownvalue.MapValuePartial(map[string]knownvalue.Check{ "key3": knownvalue.StringValueExact("value1"), }), ), @@ -900,7 +900,7 @@ func TestExpectKnownValue_CheckPlan_MapElements_WrongNum(t *testing.T) { ), }, }, - ExpectError: regexp.MustCompile("expected 3 elements for MapElements check, got 2 elements"), + ExpectError: regexp.MustCompile("expected 3 elements for MapElementsExact check, got 2 elements"), }, }, }) @@ -971,7 +971,7 @@ func TestExpectKnownValue_CheckPlan_Number_KnownValueWrongValue(t *testing.T) { ), }, }, - ExpectError: regexp.MustCompile("expected value 321 for NumberValue check, got: 123"), + ExpectError: regexp.MustCompile("expected value 321 for NumberValueExact check, got: 123"), }, }, }) @@ -1042,7 +1042,7 @@ func TestExpectKnownValue_CheckPlan_Set_KnownValueWrongValue(t *testing.T) { ), }, }, - ExpectError: regexp.MustCompile(`missing value value3 for SetValue check`), + ExpectError: regexp.MustCompile(`missing value value3 for SetValueExact check`), }, }, }) @@ -1071,7 +1071,7 @@ func TestExpectKnownValue_CheckPlan_SetPartial(t *testing.T) { plancheck.ExpectKnownValue( "test_resource.one", tfjsonpath.New("set_attribute"), - knownvalue.SetValuePartialMatch([]knownvalue.Check{ + knownvalue.SetValuePartial([]knownvalue.Check{ knownvalue.StringValueExact("value2"), }), ), @@ -1105,7 +1105,7 @@ func TestExpectKnownValue_CheckPlan_SetPartial_KnownValueWrongValue(t *testing.T plancheck.ExpectKnownValue( "test_resource.one", tfjsonpath.New("set_attribute"), - knownvalue.SetValuePartialMatch([]knownvalue.Check{ + knownvalue.SetValuePartial([]knownvalue.Check{ knownvalue.StringValueExact("value3"), }), ), @@ -1215,7 +1215,7 @@ func TestExpectKnownValue_CheckPlan_SetNestedBlockPartial(t *testing.T) { plancheck.ExpectKnownValue( "test_resource.one", tfjsonpath.New("set_nested_block"), - knownvalue.SetValuePartialMatch([]knownvalue.Check{ + knownvalue.SetValuePartial([]knownvalue.Check{ knownvalue.MapValueExact(map[string]knownvalue.Check{ "set_nested_block_attribute": knownvalue.StringValueExact("rts"), }), @@ -1313,7 +1313,7 @@ func TestExpectKnownValue_CheckPlan_String_KnownValueWrongType(t *testing.T) { knownvalue.BoolValueExact(true)), }, }, - ExpectError: regexp.MustCompile("expected bool value for BoolValue check, got: string"), + ExpectError: regexp.MustCompile("expected bool value for BoolValueExact check, got: string"), }, }, }) @@ -1342,7 +1342,7 @@ func TestExpectKnownValue_CheckPlan_String_KnownValueWrongValue(t *testing.T) { knownvalue.StringValueExact("rts")), }, }, - ExpectError: regexp.MustCompile("expected value rts for StringValue check, got: str"), + ExpectError: regexp.MustCompile("expected value rts for StringValueExact check, got: str"), }, }, }) @@ -1372,7 +1372,7 @@ func TestExpectKnownValue_CheckPlan_UnknownAttributeType(t *testing.T) { }, }, }, - expectedErr: fmt.Errorf("unrecognised attribute type: float32, known value type is knownvalue.Int64Value\n\nThis is an error in plancheck.ExpectKnownValue.\nPlease report this to the maintainers."), + expectedErr: fmt.Errorf("unrecognised attribute type: float32, known value type is knownvalue.int64ValueExact\n\nThis is an error in plancheck.ExpectKnownValue.\nPlease report this to the maintainers."), }, }