Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dedalqq/omg.testingtools
This tool can be useful for writing a tests. If you want change private field in struct from imported libraries than it can help you.
https://github.com/dedalqq/omg.testingtools
go golang reflection testing
Last synced: about 2 months ago
JSON representation
This tool can be useful for writing a tests. If you want change private field in struct from imported libraries than it can help you.
- Host: GitHub
- URL: https://github.com/dedalqq/omg.testingtools
- Owner: dedalqq
- License: mit
- Created: 2021-10-13T13:49:30.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2021-10-14T23:05:20.000Z (about 3 years ago)
- Last Synced: 2024-04-22T13:32:16.401Z (8 months ago)
- Topics: go, golang, reflection, testing
- Language: Go
- Homepage:
- Size: 13.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - omg.testingtools - The simple library for change a values of private fields for testing. (Testing / Testing Frameworks)
- awesome-go-extra - omg.testingtools - 10-13T13:49:30Z|2021-10-14T23:05:20Z| (Testing / Testing Frameworks)
README
# omg.testingTools
[![Go](https://github.com/dedalqq/omg.testingtools/actions/workflows/go.yml/badge.svg)](https://github.com/dedalqq/omg.testingtools/actions/workflows/go.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/dedalqq/omg.testingtools)](https://goreportcard.com/report/github.com/dedalqq/omg.testingtools)
[![Coverage Status](https://coveralls.io/repos/github/dedalqq/omg.testingtools/badge.svg?branch=master)](https://coveralls.io/github/dedalqq/omg.testingtools?branch=master)
[![Go Reference](https://pkg.go.dev/badge/github.com/dedalqq/omg.testingtools.svg)](https://pkg.go.dev/github.com/dedalqq/omg.testingtools)This tool can be useful for writing a tests. If you want change private field in struct from imported libraries than it can help you.
## Example
```go
package mainimport (
"strings"
"github.com/dedalqq/omg.testingtools"
)func TestSomeCase(t *testing.T) {
buffer := strings.Builder{}
testingtools.SetPrivateValue(&buffer, "buf", []byte("data in strings buffer"))
}
```
## How it worksThis function finding needs field via `reflect` then get pointer from field address via `unsafe.Pointer` and write value via variable with the same address as original struct field.