Skip to content

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.

License

Notifications You must be signed in to change notification settings

dedalqq/omg.testingtools

Repository files navigation

omg.testingTools

Go Go Report Card Coverage Status Go Reference

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

package main

import (
	"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 works

This 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.

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Languages