func captureFilterStdOut(f func(rgtaiface.ResourceGroupsTaggingAPIAPI, io.Reader, io.Reader) error, svc rgtaiface.ResourceGroupsTaggingAPIAPI, v1, v2 io.Reader) (string, error) {
	oldStdOut := os.Stdout
	r, w, err := os.Pipe()
	if err != nil {
		return "", err
	}
	os.Stdout = w
	pipeOut := make(chan string)
	go func() {
		var buf bytes.Buffer
		io.Copy(&buf, r)
		pipeOut <- buf.String()
	}()
	if err := f(svc, v1, v2); err != nil {
		w.Close()
		os.Stdout = oldStdOut
		return "", err
	}
	w.Close()
	os.Stdout = oldStdOut
	return <-pipeOut, nil
}
Set stdout to pipe and capture printed output of a Print event
package main
import (
	"bytes"
	"io"
	"io/ioutil"
	"os"
	"reflect"
	"strings"
	"testing"
	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/request"
	rgta "github.com/aws/aws-sdk-go/service/resourcegroupstaggingapi"
	rgtaiface "github.com/aws/aws-sdk-go/service/resourcegroupstaggingapi/resourcegroupstaggingapiiface"
	"github.com/spf13/viper"
)
type mockRGTAGetResources struct {
	rgtaiface.ResourceGroupsTaggingAPIAPI
	Resp rgta.GetResourcesOutput
}
func (m *mockRGTAGetResources) GetResourcesWithContext(ctx aws.Context, in *rgta.GetResourcesInput, os ...request.Option) (*rgta.GetResourcesOutput, error) {
	return &m.Resp, nil
}