Exemplo n.º 1
0
func TestEc2MetaTemplates_ValidKey(t *testing.T) {
	server, ec2meta := aws.MockServer(200, "i-1234")
	defer server.Close()
	g := &Gomplate{
		funcMap: template.FuncMap{
			"ec2meta": ec2meta.Meta,
		},
	}

	assert.Equal(t, "i-1234", testTemplate(g, `{{ec2meta "instance-id"}}`))
	assert.Equal(t, "i-1234", testTemplate(g, `{{ec2meta "instance-id" "default"}}`))
}
Exemplo n.º 2
0
func TestEc2MetaTemplates_MissingKey(t *testing.T) {
	server, ec2meta := aws.MockServer(404, "")
	defer server.Close()
	g := &Gomplate{
		funcMap: template.FuncMap{
			"ec2meta": ec2meta.Meta,
		},
	}

	assert.Equal(t, "", testTemplate(g, `{{ec2meta "foo"}}`))
	assert.Equal(t, "default", testTemplate(g, `{{ec2meta "foo" "default"}}`))
}
Exemplo n.º 3
0
func TestEc2MetaTemplates_WithJSON(t *testing.T) {
	server, ec2meta := aws.MockServer(200, `{"foo":"bar"}`)
	defer server.Close()
	ty := new(TypeConv)
	g := &Gomplate{
		funcMap: template.FuncMap{
			"ec2meta":    ec2meta.Meta,
			"ec2dynamic": ec2meta.Dynamic,
			"json":       ty.JSON,
		},
	}

	assert.Equal(t, "bar", testTemplate(g, `{{ (ec2meta "obj" | json).foo }}`))
	assert.Equal(t, "bar", testTemplate(g, `{{ (ec2dynamic "obj" | json).foo }}`))
}