1package awsat
2
3import (
4	"testing"
5
6	"github.com/aws/aws-sdk-go/service/ec2"
7)
8
9func TestRouteTable(t *testing.T) {
10	t.Run("create", func(t *testing.T) {
11		Template("create routetable vpc=vpc-1234").
12			Mock(&ec2Mock{
13				CreateRouteTableFunc: func(param0 *ec2.CreateRouteTableInput) (*ec2.CreateRouteTableOutput, error) {
14					return &ec2.CreateRouteTableOutput{RouteTable: &ec2.RouteTable{RouteTableId: String("new-routetable-id")}}, nil
15				},
16			}).ExpectInput("CreateRouteTable", &ec2.CreateRouteTableInput{VpcId: String("vpc-1234")}).
17			ExpectCommandResult("new-routetable-id").ExpectCalls("CreateRouteTable").Run(t)
18	})
19
20	t.Run("delete", func(t *testing.T) {
21		Template("delete routetable id=rt-1234").
22			Mock(&ec2Mock{
23				DeleteRouteTableFunc: func(param0 *ec2.DeleteRouteTableInput) (*ec2.DeleteRouteTableOutput, error) {
24					return nil, nil
25				},
26			}).ExpectInput("DeleteRouteTable", &ec2.DeleteRouteTableInput{RouteTableId: String("rt-1234")}).
27			ExpectCalls("DeleteRouteTable").Run(t)
28	})
29
30	t.Run("attach", func(t *testing.T) {
31		Template("attach routetable id=my-rt-id subnet=my-subnet-id").
32			Mock(&ec2Mock{
33				AssociateRouteTableFunc: func(param0 *ec2.AssociateRouteTableInput) (*ec2.AssociateRouteTableOutput, error) {
34					return &ec2.AssociateRouteTableOutput{AssociationId: String("new-assoc-id")}, nil
35				},
36			}).ExpectInput("AssociateRouteTable", &ec2.AssociateRouteTableInput{
37			RouteTableId: String("my-rt-id"),
38			SubnetId:     String("my-subnet-id"),
39		}).ExpectCommandResult("new-assoc-id").ExpectCalls("AssociateRouteTable").Run(t)
40	})
41
42	t.Run("detach", func(t *testing.T) {
43		Template("detach routetable association=assoc-2345").
44			Mock(&ec2Mock{
45				DisassociateRouteTableFunc: func(param0 *ec2.DisassociateRouteTableInput) (*ec2.DisassociateRouteTableOutput, error) {
46					return nil, nil
47				},
48			}).ExpectInput("DisassociateRouteTable", &ec2.DisassociateRouteTableInput{AssociationId: String("assoc-2345")}).
49			ExpectCalls("DisassociateRouteTable").Run(t)
50	})
51}
52