如何测试返回字符串或数字类型的结构属性而不是结构本身的函数?
我正在尝试用块测试块。Lambda CodeTest Code
在下面的块中,我返回*resp。UserPoolClient.ClientSecret 它取消引用 到 ,而不是 .Lambda Codestring*string
当我运行测试时,我相信我得到了一个紧急错误,就像在调试器中一样。*resp.UserPoolClient.ClientSecretnil
我返回的取消引用属性是错误的方法吗?想知道我是否最好只返回整个 resp 对象,而不是取消引用?我这样做是因为我根本不需要修改值,只需要副本可供参考。
Lambda Code
package main
import (
"fmt"
"log"
"os"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-lambda-go/lambda"
"github.com/aws/aws-sdk-go/aws/session"
cidp "github.com/aws/aws-sdk-go/service/cognitoidentityprovider"
cidpif "github.com/aws/aws-sdk-go/service/cognitoidentityprovider/cognitoidentityprovideriface"
util "github.com/sean/repo/internal/util"
)
type application struct {
config configuration
}
type configuration struct {
ClientPoolID string
UserPoolID string
idp cidpif.CognitoIdentityProviderAPI
}
func (app application) getUserPoolClientSecret() (string, error) {
input := &cidp.DescribeUserPoolClientInput{
UserPoolId: aws.String(app.config.UserPoolID),
ClientId: aws.String(app.config.ClientPoolID),
}
resp, err := app.config.idp.DescribeUserPoolClient(input)
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
log.Printf("[ERROR] %v", aerr.Error())
} else {
log.Printf("[ERROR] %v", err.Error())
}
return "", err
}
log.Println("[INFO] Obtained user pool client secret successfully")
return *resp.UserPoolClient.ClientSecret, nil
}
// omitted for brevity
func main() {
config := configuration{
ClientPoolID: os.Getenv("CLIENT_POOL_ID"),
UserPoolID: os.Getenv("USER_POOL_ID"),
idp: cidp.New(session.Must(session.NewSession())),
}
app := application{config: config}
lambda.Start(app.handler) // handler() calls app.getUserPoolClientSecret
}
慕娘9325324
相关分类