我试图有史以来第一次编写一些单元测试,并且我正在使用golang为一个利用aws lambda的副项目做这件事。
下面是两个文件。
main.go
获取包含电子邮件地址的事件,并在认知用户池中创建用户。
main_test.go
应该模拟 中的函数,但是当我尝试运行测试时,我遇到了错误。createUser
main.go
在观看此YouTube视频后,我刚刚将我的代码从全局实例化客户端切换到在awsd工具包接口上使用指针接收器方法。
main.go
package main
import (
"fmt"
"log"
"os"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"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"
lib "github.com/sean/repo/lib"
)
type createUserEvent struct {
EmailAddress string `json:"email_address"`
}
type awsService struct {
cidpif.CognitoIdentityProviderAPI
}
func (c *awsService) createUser(e createUserEvent) error {
input := &cidp.AdminCreateUserInput{
UserPoolId: aws.String(os.Getenv("USER_POOL_ID")),
Username: aws.String(e.EmailAddress),
DesiredDeliveryMediums: []*string{aws.String("EMAIL")},
ForceAliasCreation: aws.Bool(true),
UserAttributes: []*cidp.AttributeType{
{
Name: aws.String("email"),
Value: aws.String(e.EmailAddress),
},
},
}
aluckdog
相关分类