func (i *iamPolicyServerImpl) TestIamPermissions(ctx context.Context, in *iampb.TestIamPermissionsRequest) (*iampb.TestIamPermissionsResponse, error) {
	if in.GetResource() == "" {
		return nil, missingResource
	}
	i.mu.Lock()
	defer i.mu.Unlock()
	if _, ok := i.policies[in.GetResource()]; !ok {
		return nil, resourceDoesNotExist
	}
	return &iampb.TestIamPermissionsResponse{
		Permissions: in.GetPermissions(),
	}, nil
}
TestIamPermissions verifies that the requested resource has been Set at one point, and echoes the back permissions to be tested.
package services
import (
	"context"
	"sync"
	"github.com/golang/protobuf/proto"
	iampb "google.golang.org/genproto/googleapis/iam/v1"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
)
var missingResource error = status.Error(codes.InvalidArgument, "Missing required argument: resource")
var missingPolicy error = status.Error(codes.InvalidArgument, "Missing required argument: policy")
var resourceDoesNotExist error = status.Error(codes.NotFound, "Requested resource has no Policy")
func NewIAMPolicyServer() iampb.IAMPolicyServer {
	return &iamPolicyServerImpl{
		policies: map[string]*iampb.Policy{},
	}
}
type iamPolicyServerImpl struct {
	mu sync.Mutex
	policies map[string]*iampb.Policy
}
func (i *iamPolicyServerImpl) GetIamPolicy(ctx context.Context, in *iampb.GetIamPolicyRequest) (*iampb.Policy, error) {
	if in.GetResource() == "" {
		return nil, missingResource
	}
	i.mu.Lock()
	defer i.mu.Unlock()
	p, ok := i.policies[in.GetResource()]
	if !ok {
		return nil, resourceDoesNotExist
	}
	res := proto.Clone(p)
	return res.(*iampb.Policy), nil
}
func (i *iamPolicyServerImpl) SetIamPolicy(ctx context.Context, in *iampb.SetIamPolicyRequest) (*iampb.Policy, error) {
	if in.GetResource() == "" {
		return nil, missingResource
	}
	if in.GetPolicy() == nil {
		return nil, missingPolicy
	}
	i.mu.Lock()
	defer i.mu.Unlock()
	clone := proto.Clone(in.GetPolicy())
	p := clone.(*iampb.Policy)
	i.policies[in.GetResource()] = p
	return in.GetPolicy(), nil
}