Skip to content

Commit

Permalink
add a test for pre-customize.json
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromegn committed Nov 4, 2024
1 parent 3f487f2 commit 6d565cf
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/deployer/deployer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"

"github.com/stretchr/testify/require"
"github.com/superfly/fly-go"
"github.com/superfly/flyctl/test/testlib"
)

Expand Down Expand Up @@ -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"),
Expand Down
23 changes: 23 additions & 0 deletions test/testlib/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fmt"
"io"
"os"
"path/filepath"
"strings"
"testing"

Expand All @@ -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"
)

Expand Down Expand Up @@ -94,6 +96,7 @@ type DeployTestRun struct {
skipExtensions bool
copyConfig bool
optOutGha bool
customizePath string

deployOnly bool
deployNow bool
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 6d565cf

Please sign in to comment.