本文整理汇总了Golang中github.com/aws/amazon-ecs-agent/agent/ec2.NewBlackholeEC2MetadataClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewBlackholeEC2MetadataClient函数的具体用法?Golang NewBlackholeEC2MetadataClient怎么用?Golang NewBlackholeEC2MetadataClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewBlackholeEC2MetadataClient函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestSubmitContainerStateChangeLongReason
func TestSubmitContainerStateChangeLongReason(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
client, _, mockSubmitStateClient := NewMockClient(mockCtrl, ec2.NewBlackholeEC2MetadataClient())
exitCode := 20
trimmedReason := strings.Repeat("a", api.EcsMaxReasonLength)
reason := strings.Repeat("a", api.EcsMaxReasonLength+1)
mockSubmitStateClient.EXPECT().SubmitContainerStateChange(&containerSubmitInputMatcher{
ecs.SubmitContainerStateChangeInput{
Cluster: strptr(configuredCluster),
Task: strptr("arn"),
ContainerName: strptr("cont"),
Status: strptr("STOPPED"),
ExitCode: int64ptr(&exitCode),
Reason: strptr(trimmedReason),
NetworkBindings: []*ecs.NetworkBinding{},
},
})
err := client.SubmitContainerStateChange(api.ContainerStateChange{
TaskArn: "arn",
ContainerName: "cont",
Status: api.ContainerStopped,
ExitCode: &exitCode,
Reason: reason,
})
if err != nil {
t.Errorf("Unable to submit container state change: %v", err)
}
}
示例2: TestTrimWhitespace
func TestTrimWhitespace(t *testing.T) {
os.Setenv("ECS_CLUSTER", "default \r")
os.Setenv("ECS_ENGINE_AUTH_TYPE", "dockercfg\r")
cfg, err := NewConfig(ec2.NewBlackholeEC2MetadataClient())
if err != nil {
t.Fatal(err)
}
if cfg.Cluster != "default" {
t.Error("Wrong cluster: " + cfg.Cluster)
}
if cfg.EngineAuthType != "dockercfg" {
t.Error("Wrong auth type: " + cfg.EngineAuthType)
}
cfg = &Config{
Cluster: " asdf ",
AWSRegion: " us-east-1\r\t",
DataDir: "/trailing/space/directory ",
}
cfg.trimWhitespace()
if !reflect.DeepEqual(cfg, &Config{Cluster: "asdf", AWSRegion: "us-east-1", DataDir: "/trailing/space/directory "}) {
t.Error("Did not match expected", *cfg)
}
}
示例3: TestConfigDefault
func TestConfigDefault(t *testing.T) {
os.Unsetenv("ECS_DISABLE_METRICS")
os.Unsetenv("ECS_RESERVED_PORTS")
os.Unsetenv("ECS_RESERVED_MEMORY")
os.Unsetenv("ECS_DISABLE_PRIVILEGED")
os.Unsetenv("ECS_AVAILABLE_LOGGING_DRIVERS")
os.Unsetenv("ECS_ENGINE_TASK_CLEANUP_WAIT_DURATION")
os.Unsetenv("ECS_ENABLE_TASK_IAM_ROLE")
os.Unsetenv("ECS_ENABLE_TASK_IAM_ROLE_NETWORK_HOST")
os.Unsetenv("ECS_CONTAINER_STOP_TIMEOUT")
os.Unsetenv("ECS_AUDIT_LOGFILE")
os.Unsetenv("ECS_AUDIT_LOGFILE_DISABLED")
cfg, err := NewConfig(ec2.NewBlackholeEC2MetadataClient())
if err != nil {
t.Fatal(err)
}
if cfg.DockerEndpoint != "unix:///var/run/docker.sock" {
t.Error("Default docker endpoint set incorrectly")
}
if cfg.DataDir != "/data/" {
t.Error("Default datadir set incorrectly")
}
if cfg.DisableMetrics {
t.Errorf("Default disablemetrics set incorrectly: %v", cfg.DisableMetrics)
}
if len(cfg.ReservedPorts) != 5 {
t.Error("Default resered ports set incorrectly")
}
if cfg.ReservedMemory != 0 {
t.Errorf("Default reserved memory set incorrectly: %v", cfg.ReservedMemory)
}
expectedTimeout, _ := time.ParseDuration("30s")
if cfg.DockerStopTimeout != expectedTimeout {
t.Error("Default docker stop container timeout set incorrectly", cfg.DockerStopTimeout)
}
if cfg.PrivilegedDisabled {
t.Errorf("Default PrivilegedDisabled set incorrectly: %v", cfg.PrivilegedDisabled)
}
if !reflect.DeepEqual(cfg.AvailableLoggingDrivers, []dockerclient.LoggingDriver{dockerclient.JsonFileDriver}) {
t.Errorf("Default logging drivers set incorrectly: %v", cfg.AvailableLoggingDrivers)
}
if cfg.TaskCleanupWaitDuration != 3*time.Hour {
t.Errorf("Defualt task cleanup wait duration set incorrectly: %v", cfg.TaskCleanupWaitDuration)
}
if cfg.TaskIAMRoleEnabled {
t.Error("TaskIAMRoleEnabled set incorrectly")
}
if cfg.TaskIAMRoleEnabledForNetworkHost {
t.Error("TaskIAMRoleEnabledForNetworkHost set incorrectly")
}
if cfg.CredentialsAuditLogDisabled {
t.Error("CredentialsAuditLogDisabled set incorrectly")
}
if cfg.CredentialsAuditLogFile != defaultCredentialsAuditLogFile {
t.Error("CredentialsAuditLogFile default is set incorrectly")
}
}
示例4: TestConfigBoolean
func TestConfigBoolean(t *testing.T) {
os.Setenv("ECS_DISABLE_METRICS", "true")
cfg, err := NewConfig(ec2.NewBlackholeEC2MetadataClient())
if err != nil {
t.Fatal(err)
}
if !cfg.DisableMetrics {
t.Error("DisableMetrics not set to true")
}
}
示例5: TestDiscoverNilTelemetryEndpoint
func TestDiscoverNilTelemetryEndpoint(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
client, mc, _ := NewMockClient(mockCtrl, ec2.NewBlackholeEC2MetadataClient())
pollEndpoint := "http://127.0.0.1"
mc.EXPECT().DiscoverPollEndpoint(gomock.Any()).Return(&ecs.DiscoverPollEndpointOutput{Endpoint: &pollEndpoint}, nil)
_, err := client.DiscoverTelemetryEndpoint("containerInstance")
if err == nil {
t.Error("Expected error getting telemetry endpoint with old response")
}
}
示例6: TestTaskIAMRoleEnabled
func TestTaskIAMRoleEnabled(t *testing.T) {
os.Setenv("ECS_ENABLE_TASK_IAM_ROLE", "true")
cfg, err := NewConfig(ec2.NewBlackholeEC2MetadataClient())
if err != nil {
t.Fatal(err)
}
if !cfg.TaskIAMRoleEnabled {
t.Errorf("Wrong value for TaskIAMRoleEnabled: %v", cfg.TaskIAMRoleEnabled)
}
}
示例7: TestCredentialsAuditLogDisabled
func TestCredentialsAuditLogDisabled(t *testing.T) {
os.Setenv("ECS_AUDIT_LOGFILE_DISABLED", "true")
cfg, err := NewConfig(ec2.NewBlackholeEC2MetadataClient())
if err != nil {
t.Fatal(err)
}
if !cfg.CredentialsAuditLogDisabled {
t.Errorf("Wrong value for CredentialsAuditLogDisabled: %v", cfg.CredentialsAuditLogDisabled)
}
}
示例8: TestImageCleanupMinimumInterval
func TestImageCleanupMinimumInterval(t *testing.T) {
os.Setenv("ECS_IMAGE_CLEANUP_INTERVAL", "1m")
cfg, err := NewConfig(ec2.NewBlackholeEC2MetadataClient())
if err != nil {
t.Fatal(err)
}
if cfg.ImageCleanupInterval != DefaultImageCleanupTimeInterval {
t.Errorf("Wrong value for ImageCleanupInterval: %v", cfg.ImageCleanupInterval)
}
}
示例9: TestImageCleanupMinimumNumImagesToDeletePerCycle
func TestImageCleanupMinimumNumImagesToDeletePerCycle(t *testing.T) {
os.Setenv("ECS_NUM_IMAGES_DELETE_PER_CYCLE", "-1")
cfg, err := NewConfig(ec2.NewBlackholeEC2MetadataClient())
if err != nil {
t.Fatal(err)
}
if cfg.NumImagesToDeletePerCycle != DefaultNumImagesToDeletePerCycle {
t.Errorf("Wrong value for NumImagesToDeletePerCycle: %v", cfg.NumImagesToDeletePerCycle)
}
}
示例10: TestTaskIAMRoleForHostNetworkEnabled
func TestTaskIAMRoleForHostNetworkEnabled(t *testing.T) {
os.Setenv("ECS_ENABLE_TASK_IAM_ROLE_NETWORK_HOST", "true")
cfg, err := NewConfig(ec2.NewBlackholeEC2MetadataClient())
if err != nil {
t.Fatal(err)
}
if !cfg.TaskIAMRoleEnabledForNetworkHost {
t.Errorf("Wrong value for TaskIAMRoleEnabledForNetworkHost: %v", cfg.TaskIAMRoleEnabledForNetworkHost)
}
}
示例11: TestCredentialsAuditLogFile
func TestCredentialsAuditLogFile(t *testing.T) {
dummyLocation := "/foo/bar.log"
os.Setenv("ECS_AUDIT_LOGFILE", dummyLocation)
cfg, err := NewConfig(ec2.NewBlackholeEC2MetadataClient())
if err != nil {
t.Fatal(err)
}
if cfg.CredentialsAuditLogFile != dummyLocation {
t.Errorf("Wrong value for CredentialsAuditLogFile: %v", cfg.CredentialsAuditLogFile)
}
}
示例12: TestReservedMemory
func TestReservedMemory(t *testing.T) {
os.Setenv("ECS_RESERVED_MEMORY", "1")
cfg, err := NewConfig(ec2.NewBlackholeEC2MetadataClient())
if err != nil {
t.Fatal(err)
}
// If an invalid value is set, the config should pick up the default value for
// reserved memory, which is 0.
if cfg.ReservedMemory != 1 {
t.Errorf("Wrong value for ReservedMemory. Expected %d, got %d", 1, cfg.ReservedMemory)
}
}
示例13: TestTaskCleanupTimeout
func TestTaskCleanupTimeout(t *testing.T) {
os.Setenv("ECS_ENGINE_TASK_CLEANUP_WAIT_DURATION", "10m")
cfg, err := NewConfig(ec2.NewBlackholeEC2MetadataClient())
if err != nil {
t.Fatal(err)
}
// If an invalid value is set, the config should pick up the default value for
// cleaning up the task.
if cfg.TaskCleanupWaitDuration != 10*time.Minute {
t.Errorf("Task cleanup wait duration set incorrectly. Expected %v, got %v", 10*time.Minute, cfg.TaskCleanupWaitDuration)
}
}
示例14: TestInvalidTaskCleanupTimeout
func TestInvalidTaskCleanupTimeout(t *testing.T) {
os.Setenv("ECS_ENGINE_TASK_CLEANUP_WAIT_DURATION", "1s")
cfg, err := NewConfig(ec2.NewBlackholeEC2MetadataClient())
if err != nil {
t.Fatal(err)
}
// If an invalid value is set, the config should pick up the default value for
// cleaning up the task.
if cfg.TaskCleanupWaitDuration != 3*time.Hour {
t.Error("Defualt task cleanup wait duration set incorrectly")
}
}
示例15: TestSubmitContainerStateChange
func TestSubmitContainerStateChange(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
client, _, mockSubmitStateClient := NewMockClient(mockCtrl, ec2.NewBlackholeEC2MetadataClient())
mockSubmitStateClient.EXPECT().SubmitContainerStateChange(&containerSubmitInputMatcher{
ecs.SubmitContainerStateChangeInput{
Cluster: strptr(configuredCluster),
Task: strptr("arn"),
ContainerName: strptr("cont"),
Status: strptr("RUNNING"),
NetworkBindings: []*ecs.NetworkBinding{
&ecs.NetworkBinding{
BindIP: strptr("1.2.3.4"),
ContainerPort: int64ptr(intptr(1)),
HostPort: int64ptr(intptr(2)),
Protocol: strptr("tcp"),
},
&ecs.NetworkBinding{
BindIP: strptr("2.2.3.4"),
ContainerPort: int64ptr(intptr(3)),
HostPort: int64ptr(intptr(4)),
Protocol: strptr("udp"),
},
},
},
})
err := client.SubmitContainerStateChange(api.ContainerStateChange{
TaskArn: "arn",
ContainerName: "cont",
Status: api.ContainerRunning,
PortBindings: []api.PortBinding{
api.PortBinding{
BindIp: "1.2.3.4",
ContainerPort: 1,
HostPort: 2,
},
api.PortBinding{
BindIp: "2.2.3.4",
ContainerPort: 3,
HostPort: 4,
Protocol: api.TransportProtocolUDP,
},
},
})
if err != nil {
t.Errorf("Unable to submit container state change: %v", err)
}
}