Files
spinifex/tests/integration/launchtemplate_daemon_lite.go
T
joshsiv-mulga aafd36de62 test(integration): migrate launch-template RunInstances expansion off live guests
RunInstances --launch-template resolves ImageId/InstanceType from the
stored template entirely gateway-side (expandLaunchTemplate, before
validation/placement/the daemon-facing NATS hop), so proving it forwards
the resolved fields never needed a real guest boot. Ports the assertion
to tests/integration via a new opt-in StartLaunchTemplateDaemonLite (real
LaunchTemplateServiceImpl over embedded JetStream) plus a direct
subscription on the per-node launch subject to capture what the gateway
actually dispatched, rather than only the client-visible response.

The live test keeps its CRUD/versioning lifecycle (create/modify/delete
version, tag-filtered describe) — none of it touches a guest — and drops
only the RunInstances-from-template + wait-for-running + terminate tail,
whose only job was waiting out a real boot to read back fields already
proven resolved.
2026-07-20 21:16:53 +10:00

45 lines
2.2 KiB
Go

//go:build integration
package integration
import (
"testing"
"github.com/mulgadc/spinifex/spinifex/config"
handlers_ec2_launchtemplate "github.com/mulgadc/spinifex/spinifex/handlers/ec2/launchtemplate"
"github.com/nats-io/nats.go"
"github.com/stretchr/testify/require"
)
// StartLaunchTemplateDaemonLite subscribes a real
// handlers_ec2_launchtemplate.LaunchTemplateServiceImpl — the same production
// code a live daemon runs (daemon/daemon_handlers_launchtemplate.go) — to
// every ec2.*LaunchTemplate* subject the gateway's NATSLaunchTemplateService
// client calls (gateway/ec2/launchtemplate/*.go, RunInstances.go's
// expandLaunchTemplate). Unlike StubSubject's static canned JSON, this
// exercises the real KV-backed CRUD and version-resolution logic, matching
// how RunInstances resolves a referenced template into effective ImageId/
// InstanceType before the per-node launch dispatch.
//
// Kept separate from StartDaemonLite (rather than folded into it) following
// StartVolumeDaemonLite's precedent: only a test that actually exercises
// launch templates should pay for wiring this service.
func StartLaunchTemplateDaemonLite(t *testing.T, gw *Gateway) *handlers_ec2_launchtemplate.LaunchTemplateServiceImpl {
t.Helper()
cfg := &config.Config{AZ: testAZ}
svc, err := handlers_ec2_launchtemplate.NewLaunchTemplateServiceImplWithNATS(cfg, gw.NATSConn)
require.NoError(t, err, "construct launch template service")
nc := gw.NATSConn
sub(t, nc, "ec2.CreateLaunchTemplate", func(m *nats.Msg) { dispatch(m, svc.CreateLaunchTemplate) })
sub(t, nc, "ec2.CreateLaunchTemplateVersion", func(m *nats.Msg) { dispatch(m, svc.CreateLaunchTemplateVersion) })
sub(t, nc, "ec2.DeleteLaunchTemplate", func(m *nats.Msg) { dispatch(m, svc.DeleteLaunchTemplate) })
sub(t, nc, "ec2.DeleteLaunchTemplateVersions", func(m *nats.Msg) { dispatch(m, svc.DeleteLaunchTemplateVersions) })
sub(t, nc, "ec2.ModifyLaunchTemplate", func(m *nats.Msg) { dispatch(m, svc.ModifyLaunchTemplate) })
sub(t, nc, "ec2.DescribeLaunchTemplates", func(m *nats.Msg) { dispatch(m, svc.DescribeLaunchTemplates) })
sub(t, nc, "ec2.DescribeLaunchTemplateVersions", func(m *nats.Msg) { dispatch(m, svc.DescribeLaunchTemplateVersions) })
return svc
}