Add mocking of launch template id

It is being printed after it is created so we need to mock it to prevent
a nil pointer dereference when the tests are run with the launch
template create request is mocked.
This commit is contained in:
Narthana Epa 2021-01-10 00:00:16 +11:00
parent f7588a3737
commit bb94df2d02
No known key found for this signature in database
GPG Key ID: 7ABC460881544B69
1 changed files with 9 additions and 5 deletions

View File

@ -190,7 +190,7 @@ func (m *runSpotEC2ConnMock) CreateTags(req *ec2.CreateTagsInput) (*ec2.CreateTa
} }
} }
func defaultEc2Mock(instanceId, spotRequestId, volumeId *string) *runSpotEC2ConnMock { func defaultEc2Mock(instanceId, spotRequestId, volumeId, launchTemplateId *string) *runSpotEC2ConnMock {
instance := &ec2.Instance{ instance := &ec2.Instance{
InstanceId: instanceId, InstanceId: instanceId,
SpotInstanceRequestId: spotRequestId, SpotInstanceRequestId: spotRequestId,
@ -205,8 +205,10 @@ func defaultEc2Mock(instanceId, spotRequestId, volumeId *string) *runSpotEC2Conn
return &runSpotEC2ConnMock{ return &runSpotEC2ConnMock{
CreateLaunchTemplateFn: func(in *ec2.CreateLaunchTemplateInput) (*ec2.CreateLaunchTemplateOutput, error) { CreateLaunchTemplateFn: func(in *ec2.CreateLaunchTemplateInput) (*ec2.CreateLaunchTemplateOutput, error) {
return &ec2.CreateLaunchTemplateOutput{ return &ec2.CreateLaunchTemplateOutput{
LaunchTemplate: nil, LaunchTemplate: &ec2.LaunchTemplate{
Warning: nil, LaunchTemplateId: launchTemplateId,
},
Warning: nil,
}, nil }, nil
}, },
CreateFleetFn: func(*ec2.CreateFleetInput) (*ec2.CreateFleetOutput, error) { CreateFleetFn: func(*ec2.CreateFleetInput) (*ec2.CreateFleetOutput, error) {
@ -237,7 +239,8 @@ func TestRun(t *testing.T) {
instanceId := aws.String("test-instance-id") instanceId := aws.String("test-instance-id")
spotRequestId := aws.String("spot-id") spotRequestId := aws.String("spot-id")
volumeId := aws.String("volume-id") volumeId := aws.String("volume-id")
ec2Mock := defaultEc2Mock(instanceId, spotRequestId, volumeId) launchTemplateId := aws.String("launchTemplateId")
ec2Mock := defaultEc2Mock(instanceId, spotRequestId, volumeId, launchTemplateId)
uiMock := packersdk.TestUi(t) uiMock := packersdk.TestUi(t)
@ -329,7 +332,8 @@ func TestRun_NoSpotTags(t *testing.T) {
instanceId := aws.String("test-instance-id") instanceId := aws.String("test-instance-id")
spotRequestId := aws.String("spot-id") spotRequestId := aws.String("spot-id")
volumeId := aws.String("volume-id") volumeId := aws.String("volume-id")
ec2Mock := defaultEc2Mock(instanceId, spotRequestId, volumeId) launchTemplateId := aws.String("lt-id")
ec2Mock := defaultEc2Mock(instanceId, spotRequestId, volumeId, launchTemplateId)
uiMock := packersdk.TestUi(t) uiMock := packersdk.TestUi(t)