예제 #1
0
func TestListAppServices(t *testing.T) {
	h := awsutil.NewHandler([]awsutil.Cycle{
		awsutil.Cycle{
			Request: awsutil.Request{
				RequestURI: "/",
				Operation:  "AmazonEC2ContainerServiceV20141113.ListServices",
				Body:       `{"cluster":"cluster"}`,
			},
			Response: awsutil.Response{
				StatusCode: 200,
				Body:       `{"serviceArns":["arn:aws:ecs:us-east-1:249285743859:service/ae69bb4c-3903-4844-82fe-548ac5b74570--web"]}`,
			},
		},
	})
	m, s := newTestClient(h)
	defer s.Close()

	resp, err := m.ListAppServices(context.Background(), "ae69bb4c-3903-4844-82fe-548ac5b74570", &ecs.ListServicesInput{
		Cluster: aws.String("cluster"),
	})
	if err != nil {
		t.Fatal(err)
	}

	if got := len(resp.ServiceARNs); got != 1 {
		t.Fatalf("Expected 1 service returned; got %d", got)
	}
}
예제 #2
0
func TestRoute53_DeleteCNAME(t *testing.T) {
	h := awsutil.NewHandler([]awsutil.Cycle{
		{
			Request: awsutil.Request{
				RequestURI: "/2013-04-01/hostedzone/FAKEZONE",
				Body:       ``,
			},
			Response: awsutil.Response{
				StatusCode: 200,
				Body: `<?xml version="1.0"?>
<GetHostedZoneResponse xmlns="https://route53.amazonaws.com/doc/2013-04-01/">
	<HostedZone>
		<Id>/hostedzone/FAKEZONE</Id>
		<Name>empire.</Name>
		<CallerReference>FakeReference</CallerReference>
		<Config>
			<Comment>Fake hosted zone comment.</Comment>
			<PrivateZone>true</PrivateZone>
		</Config>
		<ResourceRecordSetCount>2</ResourceRecordSetCount>
	</HostedZone>
	<VPCs>
		<VPC>
			<VPCRegion>us-east-1</VPCRegion>
			<VPCId>vpc-0d9ea668</VPCId>
		</VPC>
	</VPCs>
</GetHostedZoneResponse>`,
			},
		},
		{
			Request: awsutil.Request{
				RequestURI: `/2013-04-01/hostedzone/FAKEZONE/rrset`,
				Body:       `ignore`,
			},
			Response: awsutil.Response{
				StatusCode: 200,
				Body:       ``,
			},
		},
	})

	n, s := newTestRoute53Nameserver(h, "/hostedzone/FAKEZONE")
	defer s.Close()

	if err := n.DeleteCNAME("acme-inc", "123456789.us-east-1.elb.amazonaws.com"); err != nil {
		t.Fatal(err)
	}
}
예제 #3
0
func TestECSManager_Scale(t *testing.T) {
	h := awsutil.NewHandler([]awsutil.Cycle{
		awsutil.Cycle{
			Request: awsutil.Request{
				RequestURI: "/",
				Operation:  "AmazonEC2ContainerServiceV20141113.UpdateService",
				Body:       `{"cluster":"empire","desiredCount":10,"service":"1234--web"}`,
			},
			Response: awsutil.Response{
				StatusCode: 200,
				Body:       ``,
			},
		},
	})
	m, s := newTestECSManager(h)
	defer s.Close()

	if err := m.Scale(context.Background(), "1234", "web", 10); err != nil {
		t.Fatal(err)
	}
}
예제 #4
0
func TestECSManager_Processes(t *testing.T) {
	h := awsutil.NewHandler([]awsutil.Cycle{
		awsutil.Cycle{
			Request: awsutil.Request{
				RequestURI: "/",
				Operation:  "AmazonEC2ContainerServiceV20141113.ListServices",
				Body:       `{"cluster":"empire"}`,
			},
			Response: awsutil.Response{
				StatusCode: 200,
				Body: `{"serviceArns":[
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web1",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web2",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web3",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web4",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web5",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web6",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web7",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web8",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web9",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web10",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web11",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web12",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web13",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web14",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web15",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web16",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web17",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web18",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web19",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web20",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web21"
				]}`,
			},
		},

		awsutil.Cycle{
			Request: awsutil.Request{
				RequestURI: "/",
				Operation:  "AmazonEC2ContainerServiceV20141113.DescribeServices",
				Body: `{"cluster":"empire","services":[
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web1",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web2",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web3",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web4",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web5",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web6",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web7",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web8",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web9",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web10"
				]}`,
			},
			Response: awsutil.Response{
				StatusCode: 200,
				Body:       `{"services":[{"taskDefinition":"1234--web"}]}`,
			},
		},

		awsutil.Cycle{
			Request: awsutil.Request{
				RequestURI: "/",
				Operation:  "AmazonEC2ContainerServiceV20141113.DescribeServices",
				Body: `{"cluster":"empire","services":[
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web11",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web12",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web13",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web14",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web15",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web16",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web17",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web18",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web19",
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web20"
				]}`,
			},
			Response: awsutil.Response{
				StatusCode: 200,
				Body:       `{"services":[{"taskDefinition":"1234--web"}]}`,
			},
		},

		awsutil.Cycle{
			Request: awsutil.Request{
				RequestURI: "/",
				Operation:  "AmazonEC2ContainerServiceV20141113.DescribeServices",
				Body: `{"cluster":"empire","services":[
				"arn:aws:ecs:us-east-1:249285743859:service/1234--web21"
				]}`,
			},
			Response: awsutil.Response{
				StatusCode: 200,
				Body:       `{"services":[{"taskDefinition":"1234--web"}]}`,
			},
		},

		awsutil.Cycle{
			Request: awsutil.Request{
				RequestURI: "/",
				Operation:  "AmazonEC2ContainerServiceV20141113.DescribeTaskDefinition",
				Body:       `{"taskDefinition":"1234--web"}`,
			},
			Response: awsutil.Response{
				StatusCode: 200,
				Body:       `{"taskDefinition":{"containerDefinitions":[{"cpu":128,"command":["acme-inc","web"],"environment":[{"name":"USER","value":"foo"}],"essential":true,"image":"remind101/acme-inc:latest","memory":128,"name":"web"}]}}`,
			},
		},

		awsutil.Cycle{
			Request: awsutil.Request{
				RequestURI: "/",
				Operation:  "AmazonEC2ContainerServiceV20141113.DescribeTaskDefinition",
				Body:       `{"taskDefinition":"1234--web"}`,
			},
			Response: awsutil.Response{
				StatusCode: 200,
				Body:       `{"taskDefinition":{"containerDefinitions":[{"cpu":128,"command":["acme-inc","web"],"environment":[{"name":"USER","value":"foo"}],"essential":true,"image":"remind101/acme-inc:latest","memory":128,"name":"web"}]}}`,
			},
		},

		awsutil.Cycle{
			Request: awsutil.Request{
				RequestURI: "/",
				Operation:  "AmazonEC2ContainerServiceV20141113.DescribeTaskDefinition",
				Body:       `{"taskDefinition":"1234--web"}`,
			},
			Response: awsutil.Response{
				StatusCode: 200,
				Body:       `{"taskDefinition":{"containerDefinitions":[{"cpu":128,"command":["acme-inc","web"],"environment":[{"name":"USER","value":"foo"}],"essential":true,"image":"remind101/acme-inc:latest","memory":128,"name":"web"}]}}`,
			},
		},
	})
	m, s := newTestECSManager(h)
	defer s.Close()

	if _, err := m.Processes(context.Background(), "1234"); err != nil {
		t.Fatal(err)
	}
}
예제 #5
0
func TestECSManager_Submit(t *testing.T) {
	h := awsutil.NewHandler([]awsutil.Cycle{
		awsutil.Cycle{
			Request: awsutil.Request{
				RequestURI: "/",
				Operation:  "AmazonEC2ContainerServiceV20141113.ListServices",
				Body:       `{"cluster":"empire"}`,
			},
			Response: awsutil.Response{
				StatusCode: 200,
				Body:       `{"serviceArns":["arn:aws:ecs:us-east-1:249285743859:service/1234--web"]}`,
			},
		},

		awsutil.Cycle{
			Request: awsutil.Request{
				RequestURI: "/",
				Operation:  "AmazonEC2ContainerServiceV20141113.DescribeServices",
				Body:       `{"cluster":"empire","services":["arn:aws:ecs:us-east-1:249285743859:service/1234--web"]}`,
			},
			Response: awsutil.Response{
				StatusCode: 200,
				Body:       `{"services":[{"taskDefinition":"1234--web"}]}`,
			},
		},

		awsutil.Cycle{
			Request: awsutil.Request{
				RequestURI: "/",
				Operation:  "AmazonEC2ContainerServiceV20141113.DescribeTaskDefinition",
				Body:       `{"taskDefinition":"1234--web"}`,
			},
			Response: awsutil.Response{
				StatusCode: 200,
				Body:       `{"taskDefinition":{"containerDefinitions":[{"cpu":128,"command":["acme-inc","web"],"environment":[{"name":"USER","value":"foo"}],"essential":true,"image":"remind101/acme-inc:latest","memory":128,"name":"web"}]}}`,
			},
		},

		awsutil.Cycle{
			Request: awsutil.Request{
				RequestURI: "/",
				Operation:  "AmazonEC2ContainerServiceV20141113.RegisterTaskDefinition",
				Body:       `{"containerDefinitions":[{"cpu":128,"command":["acme-inc","web"],"environment":[{"name":"USER","value":"foo"}],"essential":true,"image":"remind101/acme-inc:latest","memory":128,"name":"web","portMappings":[{"containerPort":8080,"hostPort":8080}]}],"family":"1234--web"}`,
			},
			Response: awsutil.Response{
				StatusCode: 200,
				Body:       "",
			},
		},

		awsutil.Cycle{
			Request: awsutil.Request{
				RequestURI: "/",
				Operation:  "AmazonEC2ContainerServiceV20141113.UpdateService",
				Body:       `{"cluster":"empire","desiredCount":0,"service":"1234--web","taskDefinition":"1234--web"}`,
			},
			Response: awsutil.Response{
				StatusCode: 200,
				Body:       `{"service": {}}`,
			},
		},
	})
	m, s := newTestECSManager(h)
	defer s.Close()

	if err := m.Submit(context.Background(), fakeApp); err != nil {
		t.Fatal(err)
	}
}
예제 #6
0
func TestECSManager_Instances(t *testing.T) {
	h := awsutil.NewHandler([]awsutil.Cycle{
		awsutil.Cycle{
			Request: awsutil.Request{
				RequestURI: "/",
				Operation:  "AmazonEC2ContainerServiceV20141113.ListServices",
				Body:       `{"cluster":"empire"}`,
			},
			Response: awsutil.Response{
				StatusCode: 200,
				Body:       `{"serviceArns":["arn:aws:ecs:us-east-1:249285743859:service/1234--web"]}`,
			},
		},

		awsutil.Cycle{
			Request: awsutil.Request{
				RequestURI: "/",
				Operation:  "AmazonEC2ContainerServiceV20141113.ListTasks",
				Body:       `{"cluster":"empire","serviceName":"1234--web"}`,
			},
			Response: awsutil.Response{
				StatusCode: 200,
				Body:       `{"taskArns":["arn:aws:ecs:us-east-1:249285743859:task/ae69bb4c-3903-4844-82fe-548ac5b74570"]}`,
			},
		},

		awsutil.Cycle{
			Request: awsutil.Request{
				RequestURI: "/",
				Operation:  "AmazonEC2ContainerServiceV20141113.DescribeTasks",
				Body:       `{"cluster":"empire","tasks":["arn:aws:ecs:us-east-1:249285743859:task/ae69bb4c-3903-4844-82fe-548ac5b74570"]}`,
			},
			Response: awsutil.Response{
				StatusCode: 200,
				Body:       `{"tasks":[{"taskArn":"arn:aws:ecs:us-east-1:249285743859:task/ae69bb4c-3903-4844-82fe-548ac5b74570","taskDefinitionArn":"arn:aws:ecs:us-east-1:249285743859:task-definition/1234--web","lastStatus":"RUNNING"}]}`,
			},
		},

		awsutil.Cycle{
			Request: awsutil.Request{
				RequestURI: "/",
				Operation:  "AmazonEC2ContainerServiceV20141113.DescribeTaskDefinition",
				Body:       `{"taskDefinition":"arn:aws:ecs:us-east-1:249285743859:task-definition/1234--web"}`,
			},
			Response: awsutil.Response{
				StatusCode: 200,
				Body:       `{"taskDefinition":{"containerDefinitions":[{"name":"web","cpu":256,"memory":256,"command":["acme-inc", "web"]}]}}`,
			},
		},
	})
	m, s := newTestECSManager(h)
	defer s.Close()

	instances, err := m.Instances(context.Background(), "1234")
	if err != nil {
		t.Fatal(err)
	}

	if len(instances) != 1 {
		t.Fatal("expected 1 instance")
	}

	i := instances[0]

	if got, want := i.State, "RUNNING"; got != want {
		t.Fatalf("State => %s; want %s", got, want)
	}

	if got, want := i.Process.Command, "acme-inc web"; got != want {
		t.Fatalf("Command => %s; want %s", got, want)
	}

	if got, want := i.Process.Type, "web"; got != want {
		t.Fatalf("Type => %s; want %s", got, want)
	}
}
예제 #7
0
func TestRoute53_zone(t *testing.T) {
	h := awsutil.NewHandler([]awsutil.Cycle{
		{
			Request: awsutil.Request{
				RequestURI: "/2013-04-01/hostedzone/FAKEZONE",
				Body:       ``,
			},
			Response: awsutil.Response{
				StatusCode: 200,
				Body: `<?xml version="1.0"?>
<GetHostedZoneResponse xmlns="https://route53.amazonaws.com/doc/2013-04-01/">
	<HostedZone>
		<Id>/hostedzone/FAKEZONE</Id>
		<Name>empire.</Name>
		<CallerReference>FakeReference</CallerReference>
		<Config>
			<Comment>Fake hosted zone comment.</Comment>
			<PrivateZone>true</PrivateZone>
		</Config>
		<ResourceRecordSetCount>2</ResourceRecordSetCount>
	</HostedZone>
	<VPCs>
		<VPC>
			<VPCRegion>us-east-1</VPCRegion>
			<VPCId>vpc-0d9ea668</VPCId>
		</VPC>
	</VPCs>
</GetHostedZoneResponse>`,
			},
		},
		{
			Request: awsutil.Request{
				RequestURI: "/2013-04-01/hostedzone/FAKEZONE",
				Body:       ``,
			},
			Response: awsutil.Response{
				StatusCode: 200,
				Body: `<?xml version="1.0"?>
<GetHostedZoneResponse xmlns="https://route53.amazonaws.com/doc/2013-04-01/">
	<HostedZone>
		<Id>/hostedzone/FAKEZONE</Id>
		<Name>empire.</Name>
		<CallerReference>FakeReference</CallerReference>
		<Config>
			<Comment>Fake hosted zone comment.</Comment>
			<PrivateZone>true</PrivateZone>
		</Config>
		<ResourceRecordSetCount>2</ResourceRecordSetCount>
	</HostedZone>
	<VPCs>
		<VPC>
			<VPCRegion>us-east-1</VPCRegion>
			<VPCId>vpc-0d9ea668</VPCId>
		</VPC>
	</VPCs>
</GetHostedZoneResponse>`,
			},
		},
	})

	// Test both a full path to a zoneID and just the zoneID itself
	// Route53Nameserver.zone() should be able to handle both.
	zoneIDs := []string{"/hostedzone/FAKEZONE", "FAKEZONE"}
	for _, zid := range zoneIDs {
		n, s := newTestRoute53Nameserver(h, zid)
		defer s.Close()

		zone, err := n.zone()
		if err != nil {
			t.Fatal(err)
		}

		if *zone.ID != "/hostedzone/FAKEZONE" {
			t.Fatalf("Got wrong zone ID: %s\n", *zone.ID)
		}
	}
}