Thanks to visit codestin.com
Credit goes to github.com

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

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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