diff options
| author | Dave Henderson <dhenderson@gmail.com> | 2024-01-25 20:11:31 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-25 20:11:31 -0500 |
| commit | ebb97fb7367fb983cffc1935a8fb57e4b80f5249 (patch) | |
| tree | 43ef6cd01f629f60f59efe1e5b003f7c8e3a1257 /internal/funcs/aws_test.go | |
| parent | f1d9158ea99abbe556251c1ff2fe970f3b460ee9 (diff) | |
Move funcs package to internal (#1977)
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'internal/funcs/aws_test.go')
| -rw-r--r-- | internal/funcs/aws_test.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/internal/funcs/aws_test.go b/internal/funcs/aws_test.go new file mode 100644 index 00000000..2a1efc5d --- /dev/null +++ b/internal/funcs/aws_test.go @@ -0,0 +1,46 @@ +package funcs + +import ( + "context" + "strconv" + "testing" + + "github.com/hairyhenderson/gomplate/v4/aws" + "github.com/stretchr/testify/assert" +) + +func TestCreateAWSFuncs(t *testing.T) { + t.Parallel() + + for i := 0; i < 10; i++ { + // Run this a bunch to catch race conditions + t.Run(strconv.Itoa(i), func(t *testing.T) { + t.Parallel() + + ctx := context.Background() + fmap := CreateAWSFuncs(ctx) + actual := fmap["aws"].(func() interface{}) + + assert.Equal(t, ctx, actual().(*Funcs).ctx) + }) + } +} + +func TestAWSFuncs(t *testing.T) { + t.Parallel() + + m := aws.NewDummyEc2Meta() + i := aws.NewDummyEc2Info(m) + af := &Funcs{meta: m, info: i} + assert.Equal(t, "unknown", must(af.EC2Region())) + assert.Equal(t, "", must(af.EC2Meta("foo"))) + assert.Equal(t, "", must(af.EC2Tag("foo"))) + assert.Equal(t, "unknown", must(af.EC2Region())) +} + +func must(r interface{}, err error) interface{} { + if err != nil { + panic(err) + } + return r +} |
