Skip to content

Commit

Permalink
Fixes issue with running Tasks that relay on environment configuratio…
Browse files Browse the repository at this point in the history
…n path (#2858)

Fixes the issue where DotEnvPath was unintentionally removed from the azd env list --output json
  • Loading branch information
wbreza committed Oct 12, 2023
1 parent 4641c9d commit 36b06ce
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
16 changes: 12 additions & 4 deletions cli/azd/pkg/environment/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@ import (

// Description is a metadata description of an environment returned for the `azd env list` command
type Description struct {
Name string
HasLocal bool
// The name of the environment
Name string
// The path to the local .env file for the environment
// This path is used by the VS Code extension to load the current environment variables when using VS code tasks
DotEnvPath string
// Specifies when the environment exists locally
HasLocal bool
// Specifies when the environment exists remotely
HasRemote bool
// Specifies when the environment is the default environment
IsDefault bool
}

Expand Down Expand Up @@ -243,8 +250,9 @@ func (m *manager) List(ctx context.Context) ([]*Description, error) {

for _, env := range localEnvs {
envMap[env.Name] = &Description{
Name: env.Name,
HasLocal: true,
Name: env.Name,
HasLocal: true,
DotEnvPath: env.DotEnvPath,
}
}

Expand Down
25 changes: 15 additions & 10 deletions cli/azd/pkg/environment/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ var (
emptyEnvList []*contracts.EnvListEnvironment = []*contracts.EnvListEnvironment{}
localEnvList []*contracts.EnvListEnvironment = []*contracts.EnvListEnvironment{
{
Name: "env1",
IsDefault: true,
Name: "env1",
IsDefault: true,
DotEnvPath: ".azure/env1/.env",
},
{
Name: "env2",
IsDefault: false,
Name: "env2",
IsDefault: false,
DotEnvPath: ".azure/env1/.env",
},
}
remoteEnvList []*contracts.EnvListEnvironment = []*contracts.EnvListEnvironment{
Expand Down Expand Up @@ -149,8 +151,9 @@ func Test_EnvManager_List(t *testing.T) {

require.Equal(t, 2, len(envList))
require.Equal(t, "env1", envList[0].Name)
require.Equal(t, true, envList[1].HasLocal)
require.Equal(t, false, envList[1].HasRemote)
require.Equal(t, true, envList[0].HasLocal)
require.Equal(t, false, envList[0].HasRemote)
require.Equal(t, ".azure/env1/.env", envList[0].DotEnvPath)
})

t.Run("RemoteOnly", func(t *testing.T) {
Expand All @@ -167,8 +170,9 @@ func Test_EnvManager_List(t *testing.T) {

require.Equal(t, 3, len(envList))
require.Equal(t, "env1", envList[0].Name)
require.Equal(t, false, envList[1].HasLocal)
require.Equal(t, true, envList[1].HasRemote)
require.Equal(t, false, envList[0].HasLocal)
require.Equal(t, true, envList[0].HasRemote)
require.Equal(t, "", envList[0].DotEnvPath)
})

t.Run("LocalAndRemote", func(t *testing.T) {
Expand All @@ -185,8 +189,9 @@ func Test_EnvManager_List(t *testing.T) {

require.Equal(t, 3, len(envList))
require.Equal(t, "env1", envList[0].Name)
require.Equal(t, true, envList[1].HasLocal)
require.Equal(t, true, envList[1].HasRemote)
require.Equal(t, true, envList[0].HasLocal)
require.Equal(t, true, envList[0].HasRemote)
require.Equal(t, ".azure/env1/.env", envList[0].DotEnvPath)
})
}

Expand Down

0 comments on commit 36b06ce

Please sign in to comment.