Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue with running VS Code Tasks that rely on environment configuration path #2858

Merged
merged 3 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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