Testcontainers wrapper for the Instance Metadata Mock (imds-mock) tool. Quickly and easily simulate the Amazon Instance Metadata Service (IMDS) for localised testing.
Import the library into your project:
go get github.com/purpleclay/testcontainers-imds
Then write your first test:
package imds_test
import (
"context"
"testing"
imds "github.com/purpleclay/testcontainers-imds"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestInstanceMetadata(t *testing.T) {
ctx := context.Background()
container, err := imds.Start(ctx)
require.NoError(t, err)
defer container.Terminate(ctx)
ipv4, _, _ := container.Get(imds.PathLocalIPv4)
assert.Equal(t, imds.ValueLocalIPv4, ipv4)
}
If you need more examples, take a look here.