Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
saragluna committed Nov 25, 2024
1 parent 7d5bdd6 commit 8c72593
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 11 deletions.
18 changes: 13 additions & 5 deletions cli/azd/internal/repository/app_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ func TestInitializer_prjConfigFromDetect(t *testing.T) {
"my$special$db",
"n",
"postgres", // fill in db name
"Username and password",
},
want: project.ProjectConfig{
Services: map[string]*project.ServiceConfig{
Expand All @@ -237,18 +238,25 @@ func TestInitializer_prjConfigFromDetect(t *testing.T) {
Type: project.ResourceTypeDbRedis,
Name: "redis",
},
"mongodb": {
"mongo": {
Type: project.ResourceTypeDbMongo,
Name: "mongodb",
Name: "mongo",
Props: project.MongoDBProps{
DatabaseName: "mongodb",
},
},
"postgres": {
"postgresql": {
Type: project.ResourceTypeDbPostgres,
Name: "postgres",
Name: "postgresql",
Props: project.PostgresProps{
AuthType: internal.AuthTypePassword,
DatabaseName: "postgres",
},
},
"py": {
Type: project.ResourceTypeHostContainerApp,
Name: "py",
Uses: []string{"postgres", "mongodb", "redis"},
Uses: []string{"postgresql", "mongo", "redis"},
Props: project.ContainerAppProps{
Port: 80,
},
Expand Down
6 changes: 6 additions & 0 deletions cli/azd/pkg/project/importer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,9 @@ func Test_ImportManager_ProjectInfrastructure_FromResources(t *testing.T) {

prjConfig := &ProjectConfig{}
err := yaml.Unmarshal([]byte(prjWithResources), prjConfig)
for key, res := range prjConfig.Resources {
res.Name = key
}
require.NoError(t, err)

infra, err := im.ProjectInfrastructure(context.Background(), prjConfig)
Expand Down Expand Up @@ -443,6 +446,9 @@ func TestImportManager_SynthAllInfrastructure_FromResources(t *testing.T) {
prjConfig := &ProjectConfig{}
err := yaml.Unmarshal([]byte(prjWithResources), prjConfig)
require.NoError(t, err)
for key, res := range prjConfig.Resources {
res.Name = key
}

projectFs, err := im.SynthAllInfrastructure(context.Background(), prjConfig)
require.NoError(t, err)
Expand Down
45 changes: 40 additions & 5 deletions cli/azd/pkg/project/scaffold_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,11 @@ func printHintsAboutUses(infraSpec *scaffold.InfraSpec, projectConfig *ProjectCo
return fmt.Errorf("in azure.yaml, (%s) uses (%s), but (%s) doesn't",
userResourceName, usedResourceName, usedResourceName)
}
(*console).Message(*context, fmt.Sprintf("CAUTION: In azure.yaml, '%s' uses '%s'. "+
"After deployed, the 'uses' is achieved by providing these environment variables: ",
userResourceName, usedResourceName))
if *console != nil {
(*console).Message(*context, fmt.Sprintf("CAUTION: In azure.yaml, '%s' uses '%s'. "+
"After deployed, the 'uses' is achieved by providing these environment variables: ",
userResourceName, usedResourceName))
}
switch usedResource.Type {
case ResourceTypeDbPostgres:
err := printHintsAboutUsePostgres(userSpec.DbPostgres.AuthType, console, context)
Expand Down Expand Up @@ -356,7 +358,10 @@ func printHintsAboutUses(infraSpec *scaffold.InfraSpec, projectConfig *ProjectCo
"which is doen't add necessary environment variable",
userResource.Name, usedResource.Name, usedResource.Name, usedResource.Type)
}
(*console).Message(*context, "Please make sure your application used the right environment variable name.\n")
if *console != nil {
(*console).Message(*context, "Please make sure your application used the right environment variable name.\n")
}

}
}
return nil
Expand Down Expand Up @@ -485,7 +490,7 @@ func fulfillFrontendBackend(

usedSpec := getServiceSpecByName(infraSpec, usedResource.Name)
if usedSpec == nil {
return fmt.Errorf("'%s' uses '%s', but %s doesn't", userSpec.Name, usedResource.Name, usedResource.Name)
return fmt.Errorf("'%s' uses '%s', but %s doesn't exist", userSpec.Name, usedResource.Name, usedResource.Name)
}
if usedSpec.Backend == nil {
usedSpec.Backend = &scaffold.Backend{}
Expand All @@ -506,6 +511,9 @@ func getServiceSpecByName(infraSpec *scaffold.InfraSpec, name string) *scaffold.

func printHintsAboutUsePostgres(authType internal.AuthType,
console *input.Console, context *context.Context) error {
if *console == nil {
return nil
}
(*console).Message(*context, "POSTGRES_HOST=xxx")
(*console).Message(*context, "POSTGRES_DATABASE=xxx")
(*console).Message(*context, "POSTGRES_PORT=xxx")
Expand Down Expand Up @@ -534,6 +542,9 @@ func printHintsAboutUsePostgres(authType internal.AuthType,

func printHintsAboutUseMySql(authType internal.AuthType,
console *input.Console, context *context.Context) error {
if *console == nil {
return nil
}
(*console).Message(*context, "MYSQL_HOST=xxx")
(*console).Message(*context, "MYSQL_DATABASE=xxx")
(*console).Message(*context, "MYSQL_PORT=xxx")
Expand All @@ -560,6 +571,9 @@ func printHintsAboutUseMySql(authType internal.AuthType,
}

func printHintsAboutUseRedis(console *input.Console, context *context.Context) {
if *console == nil {
return
}
(*console).Message(*context, "REDIS_HOST=xxx")
(*console).Message(*context, "REDIS_PORT=xxx")
(*console).Message(*context, "REDIS_URL=xxx")
Expand All @@ -569,18 +583,27 @@ func printHintsAboutUseRedis(console *input.Console, context *context.Context) {
}

func printHintsAboutUseMongo(console *input.Console, context *context.Context) {
if *console == nil {
return
}
(*console).Message(*context, "MONGODB_URL=xxx")
(*console).Message(*context, "spring.data.mongodb.uri=xxx")
(*console).Message(*context, "spring.data.mongodb.database=xxx")
}

func printHintsAboutUseCosmos(console *input.Console, context *context.Context) {
if *console == nil {
return
}
(*console).Message(*context, "spring.cloud.azure.cosmos.endpoint=xxx")
(*console).Message(*context, "spring.cloud.azure.cosmos.database=xxx")
}

func printHintsAboutUseServiceBus(isJms bool, authType internal.AuthType,
console *input.Console, context *context.Context) error {
if *console == nil {
return nil
}
if !isJms {
(*console).Message(*context, "spring.cloud.azure.servicebus.namespace=xxx")
}
Expand All @@ -602,6 +625,9 @@ func printHintsAboutUseServiceBus(isJms bool, authType internal.AuthType,

func printHintsAboutUseEventHubs(UseKafka bool, authType internal.AuthType, springBootVersion string,
console *input.Console, context *context.Context) error {
if *console == nil {
return nil
}
if !UseKafka {
(*console).Message(*context, "spring.cloud.azure.eventhubs.namespace=xxx")
} else {
Expand Down Expand Up @@ -630,6 +656,9 @@ func printHintsAboutUseEventHubs(UseKafka bool, authType internal.AuthType, spri

func printHintsAboutUseStorageAccount(authType internal.AuthType,
console *input.Console, context *context.Context) error {
if *console == nil {
return nil
}
(*console).Message(*context, "spring.cloud.azure.eventhubs.processor.checkpoint-store.account-name=xxx")
if authType == internal.AuthTypeUserAssignedManagedIdentity {
(*console).Message(*context, "spring.cloud.azure.eventhubs.processor.checkpoint-store.connection-string=''")
Expand All @@ -649,12 +678,18 @@ func printHintsAboutUseStorageAccount(authType internal.AuthType,

func printHintsAboutUseHostContainerApp(userResourceName string, usedResourceName string,
console *input.Console, context *context.Context) {
if *console == nil {
return
}
(*console).Message(*context, fmt.Sprintf("Environemnt variables in %s:", userResourceName))
(*console).Message(*context, fmt.Sprintf("%s_BASE_URL=xxx", strings.ToUpper(usedResourceName)))
(*console).Message(*context, fmt.Sprintf("Environemnt variables in %s:", usedResourceName))
(*console).Message(*context, fmt.Sprintf("%s_BASE_URL=xxx", strings.ToUpper(userResourceName)))
}

func printHintsAboutUseOpenAiModel(console *input.Console, context *context.Context) {
if *console == nil {
return
}
(*console).Message(*context, "AZURE_OPENAI_ENDPOINT")
}
2 changes: 1 addition & 1 deletion cli/azd/test/functional/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func Test_CLI_Init_From_App_With_Infra(t *testing.T) {
"Use code in the current directory\n"+
"Confirm and continue initializing my app\n"+
"appdb\n"+
"Use user assigned managed identity\n"+
"User assigned managed identity\n"+
"TESTENV\n",
"init",
)
Expand Down

0 comments on commit 8c72593

Please sign in to comment.