diff --git a/test/deployer/deployer_test.go b/test/deployer/deployer_test.go index cf65f8a8a3..d328f0ff69 100644 --- a/test/deployer/deployer_test.go +++ b/test/deployer/deployer_test.go @@ -9,6 +9,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/superfly/fly-go" "github.com/superfly/flyctl/test/testlib" ) @@ -198,6 +199,39 @@ func TestLaunchGoFromRepo(t *testing.T) { require.Contains(t, string(body), "I'm running in the yyz region") } +func TestLaunchPreCustomized(t *testing.T) { + customize := fly.CLISession{ + ID: "", + URL: "", + AccessToken: "", + Metadata: map[string]interface{}{ + "vm_memory": 2048, + }, + } + + deploy := testDeployer(t, + createRandomApp, + testlib.WithRegion("yyz"), + testlib.WithPreCustomize(&customize), + testlib.WithouExtensions, + testlib.DeployNow, + testlib.WithGitRepo("https://github.com/fly-apps/go-example"), + ) + + appName := deploy.Extra["appName"].(string) + + manifest, err := deploy.Output().ArtifactManifest() + require.NoError(t, err) + require.NotNil(t, manifest) + + require.Equal(t, manifest.Plan.Guest().MemoryMB, 2048) + + body, err := testlib.RunHealthCheck(fmt.Sprintf("https://%s.fly.dev", appName)) + require.NoError(t, err) + + require.Contains(t, string(body), "I'm running in the yyz region") +} + func TestLaunchRails70(t *testing.T) { deploy := testDeployer(t, withFixtureApp("deploy-rails-7.0"), diff --git a/test/testlib/deployer.go b/test/testlib/deployer.go index 22559361db..d13328d60f 100644 --- a/test/testlib/deployer.go +++ b/test/testlib/deployer.go @@ -11,6 +11,7 @@ import ( "fmt" "io" "os" + "path/filepath" "strings" "testing" @@ -21,6 +22,7 @@ import ( v1 "github.com/opencontainers/image-spec/specs-go/v1" "github.com/stretchr/testify/require" + "github.com/superfly/fly-go" "github.com/superfly/flyctl/internal/command/launch" ) @@ -94,6 +96,7 @@ type DeployTestRun struct { skipExtensions bool copyConfig bool optOutGha bool + customizePath string deployOnly bool deployNow bool @@ -127,6 +130,22 @@ func WithApp(app string) func(*DeployTestRun) { } } +func WithPreCustomize(customize *fly.CLISession) func(*DeployTestRun) { + b, err := json.Marshal(customize) + if err != nil { + panic(err) + } + return func(d *DeployTestRun) { + p := filepath.Join(d.WorkDir(), "customize.json") + if err := os.WriteFile(p, b, 0666); err != nil { + panic(err) + } + dst := "/opt/customize.json" + d.containerBinds = append(d.containerBinds, fmt.Sprintf("%s:%s", p, dst)) + d.customizePath = dst + } +} + func WithGitRepo(repo string) func(*DeployTestRun) { return func(d *DeployTestRun) { d.gitRepo = repo @@ -237,6 +256,10 @@ func (d *DeployTestRun) Start(ctx context.Context) error { env = append(env, "DEPLOYER_CLEANUP_BEFORE_EXIT=1") } + if d.customizePath != "" { + env = append(env, fmt.Sprintf("DEPLOY_CUSTOMIZE_PATH=%s", d.customizePath)) + } + fmt.Printf("creating container... image=%s\n", d.deployerImage) cont, err := d.dockerClient.ContainerCreate(ctx, &container.Config{ Image: d.deployerImage,