testingtools

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2021 License: MIT Imports: 3 Imported by: 0

README

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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetPrivateValue

func SetPrivateValue(obj interface{}, fieldName string, value interface{})

SetPrivateValue sets new a value in to the struct. Use it if you need to get access to private field of the struct from imported package. important: It function must be using only for the tests.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL