Skip to content

Testcontainers wrapper for the Instance Metadata Mock (imds-mock) tool. Quickly and easily simulate IMDS for localised testing

License

Notifications You must be signed in to change notification settings

purpleclay/testcontainers-imds

Repository files navigation

testcontainers-imds

Build status License MIT Go Report Card Go Version DeepSource

Testcontainers wrapper for the Instance Metadata Mock (imds-mock) tool. Quickly and easily simulate the Amazon Instance Metadata Service (IMDS) for localised testing.

Quick Start

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.