Skip to content

v1.15.0

Latest

Choose a tag to compare

@maxatome maxatome released this 18 Feb 20:51

Features

  • go-testdeep is now dependency-free!
  • add List operator to compare an array or a slice in strict order (can be seen as a lighter alternative to Array and Slice):
    td.Cmp(t, []int{1, 9, 5}, td.List(1, 9, 5))
    // works with slices/arrays of any type
    td.Cmp(t, personSlice, td.List(
      Person{Name: "Bob", Age: 32},
      Person{Name: "Alice", Age: 26},
    ))
  • add Sort operator to sort an array or slice before comparing its content (can be seen as an alternative to Bag):
    td.Cmp(intSlice, td.Sort(-1, []int{4, 5, 9, 10})) // check intSlice content after sorting it in descending order
    // the key(s) on which the sorting applies can be quite complex
    type A struct{ props map[string]int }
    p12 := A{props: map[string]int{"priority": 12}}
    p23 := A{props: map[string]int{"priority": 23}}
    p34 := A{props: map[string]int{"priority": 34}}
    got := []A{p23, p12, p34}
    td.Cmp(t, got, td.Sort("-props[priority]", []A{p34, p23, p12}))
    // can be used inside JSON operator
    got := map[string][]string{"labels": {"c", "a", "b"}}
    td.Cmp(t, got, td.JSON(`{ "labels": Sort(1, ["a", "b", "c"]) }`))
    // or more complex
    td.Cmp(t, got, td.JSON(`{
      "people": Sort([ "-age", "name" ], [ // sort by age desc, then by name asc
        {"name": "Marcel",  "age": 25},
        {"name": "Brian",   "age": 22},
        {"name": "Alice",   "age": 20},
        {"name": "Bob",     "age": 19},
        {"name": "Stephen", "age": 19},
      ])
    }`))
  • add Sorted operator to check an array or slice is sorted, examples:
    td.Cmp(t, aSlice, td.Sorted()) // checks aSlice is sorted in ascending order
    td.Cmp(t, aStructSlice, td.Sorted("-FieldName")) // checks aStructSlice is sorted in descending order
    // can be used inside JSON operator
    got := map[string][]string{"labels": {"a", "b", "c"}}
    td.Cmp(t, got, td.JSON(`{ "labels": Sorted }`))
  • new Must, Must2 & Must3 functions allowing to do:
    // before
    val, err := myfunction()
    td.Require(t).CmpNoError(err)
    // now
    val := td.Must(myfunction())
  • Smuggle fields-path can now contains method calls, allowing to do td.Smuggle("A.B.C.MethodName().D.E", expected) for example, and reference map[string]... using .key instead of [key] before;
  • Map, SubMapOf, SuperMapOf, Array, Slice & SuperSliceOf expectedEntries parameter is now optional or multiple;
  • Flatten now accepts func(T, X...) V|(V, bool) function signatures as well as an int to produce an int range;
  • regexp or shell pattern fields of Struct & SStruct now appear clearly in failure report;
  • tdhttp.TestAPI: add Clone, DefaultRequestParams & AddDefaultRequestParams methods;
  • tdhttp.TestAPI now sets Host field;
  • tdhttp.NewRequest and all other functions + tdhttp.TestAPI methods building HTTP requests also accept hook as func(*http.Request) error;
  • tdhttp.TestAPI: add DefaultHeader & DefaultHook methods to define header values & automatically called hook for each future requests sent by tdhttp.TestAPI;
  • add tdsynctest helper package, a simple wrapper around testing/synctest powered by go-testdeep;
  • new tdutil.CmpValuesFunc function is able to sort []reflect.Value slices thanks to slices.SortFunc;
  • tdutil.SortableValues now uses T.Compare(T) int method when it is available.

Fixes

  • operators errors are no longer hidden when used inside another operator;
  • tdutil internal tests for go1.25 was broken;
  • Grep, Last & First String() method now shows the expected value;
  • in some cases, tests continued after a failure instead of stopping immediately;
  • Grep: if got is a specific named slice type, then expect this type .

What's Changed in details

New Contributors

Full Changelog: v1.14.0...v1.15.0