Skip to content

Commit

Permalink
Merge pull request #16292 from justinsb/aws_tests_refactor
Browse files Browse the repository at this point in the history
refactor: Introduce runTests helper method into aws tests
  • Loading branch information
k8s-ci-robot authored Jan 29, 2024
2 parents b84ab1e + 4c392ac commit ffbcc52
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 122 deletions.
31 changes: 19 additions & 12 deletions upup/pkg/fi/cloudup/awstasks/egressonlyinternetgateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,7 @@ func TestSharedEgressOnlyInternetGatewayDoesNotRename(t *testing.T) {
allTasks := buildTasks()
eigw1 := allTasks["eigw1"].(*EgressOnlyInternetGateway)

target := &awsup.AWSAPITarget{
Cloud: cloud,
}

context, err := fi.NewCloudupContext(ctx, target, nil, cloud, nil, nil, nil, allTasks)
if err != nil {
t.Fatalf("error building context: %v", err)
}

if err := context.RunTasks(testRunTasksOptions); err != nil {
t.Fatalf("unexpected error during Run: %v", err)
}
runTasks(t, cloud, allTasks)

if fi.ValueOf(eigw1.ID) == "" {
t.Fatalf("ID not set after create")
Expand Down Expand Up @@ -144,3 +133,21 @@ func TestSharedEgressOnlyInternetGatewayDoesNotRename(t *testing.T) {
checkNoChanges(t, ctx, cloud, allTasks)
}
}

func runTasks(t *testing.T, cloud awsup.AWSCloud, allTasks map[string]fi.CloudupTask) {
t.Helper()
ctx := context.TODO()

target := &awsup.AWSAPITarget{
Cloud: cloud,
}

context, err := fi.NewCloudupContext(ctx, target, nil, cloud, nil, nil, nil, allTasks)
if err != nil {
t.Fatalf("error building context: %v", err)
}

if err := context.RunTasks(testRunTasksOptions); err != nil {
t.Fatalf("unexpected error during Run: %v", err)
}
}
13 changes: 1 addition & 12 deletions upup/pkg/fi/cloudup/awstasks/elastic_ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,7 @@ func TestElasticIPCreate(t *testing.T) {
allTasks := buildTasks()
eip1 := allTasks["eip1"].(*ElasticIP)

target := &awsup.AWSAPITarget{
Cloud: cloud,
}

context, err := fi.NewCloudupContext(ctx, target, nil, cloud, nil, nil, nil, allTasks)
if err != nil {
t.Fatalf("error building context: %v", err)
}

if err := context.RunTasks(testRunTasksOptions); err != nil {
t.Fatalf("unexpected error during Run: %v", err)
}
runTasks(t, cloud, allTasks)

if fi.ValueOf(eip1.ID) == "" {
t.Fatalf("ID not set after create")
Expand Down
13 changes: 1 addition & 12 deletions upup/pkg/fi/cloudup/awstasks/internetgateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,7 @@ func TestSharedInternetGatewayDoesNotRename(t *testing.T) {
allTasks := buildTasks()
igw1 := allTasks["igw1"].(*InternetGateway)

target := &awsup.AWSAPITarget{
Cloud: cloud,
}

context, err := fi.NewCloudupContext(ctx, target, nil, cloud, nil, nil, nil, allTasks)
if err != nil {
t.Fatalf("error building context: %v", err)
}

if err := context.RunTasks(testRunTasksOptions); err != nil {
t.Fatalf("unexpected error during Run: %v", err)
}
runTasks(t, cloud, allTasks)

if fi.ValueOf(igw1.ID) == "" {
t.Fatalf("ID not set after create")
Expand Down
13 changes: 1 addition & 12 deletions upup/pkg/fi/cloudup/awstasks/securitygroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,7 @@ func TestSecurityGroupCreate(t *testing.T) {
sg1 := allTasks["sg1"].(*SecurityGroup)
vpc1 := allTasks["vpc1"].(*VPC)

target := &awsup.AWSAPITarget{
Cloud: cloud,
}

context, err := fi.NewCloudupContext(ctx, target, nil, cloud, nil, nil, nil, allTasks)
if err != nil {
t.Fatalf("error building context: %v", err)
}

if err := context.RunTasks(testRunTasksOptions); err != nil {
t.Fatalf("unexpected error during Run: %v", err)
}
runTasks(t, cloud, allTasks)

if fi.ValueOf(sg1.ID) == "" {
t.Fatalf("ID not set after create")
Expand Down
52 changes: 4 additions & 48 deletions upup/pkg/fi/cloudup/awstasks/subnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,7 @@ func TestSubnetCreate(t *testing.T) {
allTasks := buildTasks()
subnet1 := allTasks["subnet1"].(*Subnet)

target := &awsup.AWSAPITarget{
Cloud: cloud,
}

context, err := fi.NewCloudupContext(ctx, target, nil, cloud, nil, nil, nil, allTasks)
if err != nil {
t.Fatalf("error building context: %v", err)
}

if err := context.RunTasks(testRunTasksOptions); err != nil {
t.Fatalf("unexpected error during Run: %v", err)
}
runTasks(t, cloud, allTasks)

if fi.ValueOf(subnet1.ID) == "" {
t.Fatalf("ID not set after create")
Expand Down Expand Up @@ -190,18 +179,7 @@ func TestSubnetCreateIPv6(t *testing.T) {
allTasks := buildTasks()
subnet1 := allTasks["subnet1"].(*Subnet)

target := &awsup.AWSAPITarget{
Cloud: cloud,
}

context, err := fi.NewCloudupContext(ctx, target, nil, cloud, nil, nil, nil, allTasks)
if err != nil {
t.Fatalf("error building context: %v", err)
}

if err := context.RunTasks(testRunTasksOptions); err != nil {
t.Fatalf("unexpected error during Run: %v", err)
}
runTasks(t, cloud, allTasks)

if fi.ValueOf(subnet1.ID) == "" {
t.Fatalf("ID not set after create")
Expand Down Expand Up @@ -290,18 +268,7 @@ func TestSubnetCreateIPv6NetNum(t *testing.T) {
allTasks := buildTasks()
subnet1 := allTasks["subnet1"].(*Subnet)

target := &awsup.AWSAPITarget{
Cloud: cloud,
}

context, err := fi.NewCloudupContext(ctx, target, nil, cloud, nil, nil, nil, allTasks)
if err != nil {
t.Fatalf("error building context: %v", err)
}

if err := context.RunTasks(testRunTasksOptions); err != nil {
t.Fatalf("unexpected error during Run: %v", err)
}
runTasks(t, cloud, allTasks)

if fi.ValueOf(subnet1.ID) == "" {
t.Fatalf("ID not set after create")
Expand Down Expand Up @@ -424,18 +391,7 @@ func TestSharedSubnetCreateDoesNotCreateNew(t *testing.T) {
allTasks := buildTasks()
subnet1 := allTasks["subnet1"].(*Subnet)

target := &awsup.AWSAPITarget{
Cloud: cloud,
}

context, err := fi.NewCloudupContext(ctx, target, nil, cloud, nil, nil, nil, allTasks)
if err != nil {
t.Fatalf("error building context: %v", err)
}

if err := context.RunTasks(testRunTasksOptions); err != nil {
t.Fatalf("unexpected error during Run: %v", err)
}
runTasks(t, cloud, allTasks)

if fi.ValueOf(subnet1.ID) == "" {
t.Fatalf("ID not set after create")
Expand Down
28 changes: 2 additions & 26 deletions upup/pkg/fi/cloudup/awstasks/vpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,7 @@ func TestVPCCreate(t *testing.T) {
allTasks := buildTasks()
vpc1 := allTasks["vpc1"].(*VPC)

target := &awsup.AWSAPITarget{
Cloud: cloud,
}

context, err := fi.NewCloudupContext(ctx, target, nil, cloud, nil, nil, nil, allTasks)
if err != nil {
t.Fatalf("error building context: %v", err)
}

if err := context.RunTasks(testRunTasksOptions); err != nil {
t.Fatalf("unexpected error during Run: %v", err)
}
runTasks(t, cloud, allTasks)

if fi.ValueOf(vpc1.ID) == "" {
t.Fatalf("ID not set after create")
Expand Down Expand Up @@ -134,8 +123,6 @@ func Test4758(t *testing.T) {
}

func TestSharedVPCAdditionalCIDR(t *testing.T) {
ctx := context.TODO()

cloud := awsup.BuildMockAWSCloud("us-east-1", "abc")
c := &mockec2.MockEC2{}
c.CreateVpcWithId(&ec2.CreateVpcInput{
Expand Down Expand Up @@ -177,18 +164,7 @@ func TestSharedVPCAdditionalCIDR(t *testing.T) {
allTasks := buildTasks()
vpc1 := allTasks["vpc-1"].(*VPC)

target := &awsup.AWSAPITarget{
Cloud: cloud,
}

context, err := fi.NewCloudupContext(ctx, target, nil, cloud, nil, nil, nil, allTasks)
if err != nil {
t.Fatalf("error building context: %v", err)
}

if err := context.RunTasks(testRunTasksOptions); err != nil {
t.Fatalf("unexpected error during Run: %v", err)
}
runTasks(t, cloud, allTasks)

if fi.ValueOf(vpc1.ID) == "" {
t.Fatalf("ID not set")
Expand Down

0 comments on commit ffbcc52

Please sign in to comment.