diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 92b4547..1cf5869 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -7,7 +7,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: 1.23.2 + go-version: 1.23.3 cache: false - name: Checkout code @@ -33,7 +33,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: 1.23.2 + go-version: 1.23.3 - name: Checkout code uses: actions/checkout@v4 diff --git a/Makefile b/Makefile index 0d6ac91..32fd511 100644 --- a/Makefile +++ b/Makefile @@ -12,12 +12,12 @@ export GOPATH ?= $(shell $(GO) env GOPATH) export GOBIN ?= $(GOPATH)/bin # Setup go-make version to use desired build and config scripts. -GOMAKE_DEP ?= github.com/tkrop/go-make@v0.0.108 +GOMAKE_DEP ?= github.com/tkrop/go-make@v0.0.114 INSTALL_FLAGS ?= -mod=readonly -buildvcs=auto # Request targets from go-make targets target. TARGETS := $(shell command -v $(GOBIN)/go-make >/dev/null || \ $(GO) install $(INSTALL_FLAGS) $(GOMAKE_DEP) >/dev/stderr && \ - $(GOBIN)/go-make show-targets 2>/dev/null) + MAKEFLAGS="" $(GOBIN)/go-make show-targets 2>/dev/null) # Declare all targets phony to make them available for auto-completion. .PHONY:: $(TARGETS) diff --git a/VERSION b/VERSION index 818944f..df5db66 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.22 +0.0.23 diff --git a/go.mod b/go.mod index 8c7217d..69028f6 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/tkrop/go-testing -go 1.23.2 +go 1.23.3 require ( github.com/golang/mock v1.6.0 @@ -8,7 +8,7 @@ require ( github.com/huandu/go-clone v1.6.0 github.com/stretchr/testify v1.9.0 golang.org/x/text v0.18.0 - golang.org/x/tools v0.26.0 + golang.org/x/tools v0.27.0 ) require ( @@ -17,8 +17,8 @@ require ( github.com/kr/pretty v0.3.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect - golang.org/x/mod v0.21.0 // indirect - golang.org/x/sync v0.8.0 // indirect + golang.org/x/mod v0.22.0 // indirect + golang.org/x/sync v0.9.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 00297b5..e75605a 100644 --- a/go.sum +++ b/go.sum @@ -37,15 +37,15 @@ github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0= -golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= +golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4= +golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= -golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ= +golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -59,8 +59,8 @@ golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ= -golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0= +golang.org/x/tools v0.27.0 h1:qEKojBykQkQ4EynWy4S8Weg69NumxKdn40Fce3uc/8o= +golang.org/x/tools v0.27.0/go.mod h1:sUi0ZgbwW9ZPAq26Ekut+weQPR5eIM6GQLQ1Yjm1H0Q= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/test/README.md b/test/README.md index 0866e06..8e426da 100644 --- a/test/README.md +++ b/test/README.md @@ -191,18 +191,21 @@ hard to recreate. Do not try it. ## Test result builder -Comparing test results is most efficient, when you directly can compare the -actual objects. However, this is sometimes prevented by the objects not being -open for construction and having private states. The `test`-package supports -helpers to construct objects and access private fields using reflection. +Setting up tests and comparing test results is most efficient, when you +directly can set up and compare the actual objects. However, this is sometimes +prevented by the objects not being open for construction and having private +states. -* `test.NewBuilder[...]()` allows constructing new objects from scratch. +To cope with this challenge the `test`-package supports helpers to access, i.e. +read and write, private fields of objects using reflection. + +* `test.NewBuilder[...]()` allows constructing a new object from scratch. * `test.NewGetter(...)` allows reading private fields of an object by name. * `test.NewSetter(...)` allows writing private fields by name, and finally -* `test.Accessor(...)` allows reading and writing of private fields by name. +* `test.NewAccessor(...)` allows reading and writing of private fields by name. -The following example shows how the private properties of a close error can -be set using the `test.NewBuilder[...]()`. +The following example shows a real world example of how the private properties +of a closed error can be set up using the `test.NewBuilder[...]()`. ```go err := test.NewBuilder[viper.ConfigFileNotFoundError](). @@ -210,6 +213,10 @@ be set using the `test.NewBuilder[...]()`. Set("name", "test").Build() ``` +Similar we can set up input objects with private properties to minimize the +dependencies in the test setup, however, using this features exposes the test +to internal changes. + ## Out-of-the-box test patterns