Skip to content

Commit

Permalink
Merge pull request #624 from meroxa/app-with-fn-env
Browse files Browse the repository at this point in the history
Early failure for deploying an application with a function to an env
  • Loading branch information
dianadoherty authored Feb 6, 2023
2 parents eae9dc2 + 60d04b5 commit 3d187d8
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/meroxa/root/apps/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,12 @@ func (d *Deploy) getAppImage(ctx context.Context) (string, error) {
return "", nil
}

// Prevent creation of function in an Env
if d.flags.Environment != "" {
d.logger.StopSpinnerWithStatus("\t", log.Failed)
return "", errors.New("cannot deploy an application with a functions to an environment")
}

d.logger.StopSpinnerWithStatus("Application processes found. Creating application image...", log.Successful)

d.localDeploy.Lang = d.lang
Expand Down
62 changes: 62 additions & 0 deletions cmd/meroxa/root/apps/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,68 @@ func TestGetPlatformImage(t *testing.T) {
}
}

func TestGetAppImage(t *testing.T) {
ctx := context.Background()
ctrl := gomock.NewController(t)
logger := log.NewTestLogger()
appName := "my-app"

tests := []struct {
name string
meroxaClient func() meroxa.Client
mockTurbineCLI func() turbine.CLI
err error
}{
{
name: "Don't build app image when for app with no function",
meroxaClient: func() meroxa.Client {
return mock.NewMockClient(ctrl)
},
mockTurbineCLI: func() turbine.CLI {
mockTurbineCLI := turbine_mock.NewMockCLI(ctrl)
mockTurbineCLI.EXPECT().
NeedsToBuild(ctx, appName).
Return(false, nil)
return mockTurbineCLI
},
},
{
name: "Fail to build app image when deploying to an environment",
meroxaClient: func() meroxa.Client {
return mock.NewMockClient(ctrl)
},
mockTurbineCLI: func() turbine.CLI {
mockTurbineCLI := turbine_mock.NewMockCLI(ctrl)
mockTurbineCLI.EXPECT().
NeedsToBuild(ctx, appName).
Return(true, nil)
return mockTurbineCLI
},
err: errors.New("cannot deploy an application with a functions to an environment"),
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
d := &Deploy{
client: tc.meroxaClient(),
turbineCLI: tc.mockTurbineCLI(),
logger: logger,
appName: appName,
}
d.flags.Environment = "my-env"

_, err := d.getAppImage(ctx)
if err != nil {
require.NotNil(t, tc.err)
require.Equal(t, tc.err, err)
} else {
require.Empty(t, tc.err)
}
})
}
}

func TestPrepareAppName(t *testing.T) {
ctx := context.Background()
appName := "my-app"
Expand Down

0 comments on commit 3d187d8

Please sign in to comment.