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

[DDO-3900] Fix clearing banner bucket #714

Merged
merged 2 commits into from
Nov 21, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions sherlock/internal/api/sherlock/environments_v3_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,14 @@ func environmentsV3Edit(ctx *gin.Context) {
}
}

// Allow clearing serviceBannerBucket by setting an empty string.
if body.ServiceBannerBucket != nil && *body.ServiceBannerBucket == "" {
toEdit.ServiceBannerBucket = nil
if err = db.Model(&toEdit).Omit(clause.Associations).Update("service_banner_bucket", nil).Error; err != nil {
errors.AbortRequest(ctx, err)
return
}
}

ctx.JSON(http.StatusOK, environmentFromModel(toEdit))
}
27 changes: 27 additions & 0 deletions sherlock/internal/api/sherlock/environments_v3_edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,30 @@ func (s *handlerSuite) TestEnvironmentsV3Edit_deleteAfter_failToParse() {
s.Equal(errors.BadRequest, got.Type)
s.Contains(got.Message, "foobar")
}

func (s *handlerSuite) TestEnvironmentsV3Edit_clearExistingBannerBucket() {
edit := s.TestData.Environment_Swatomation_TestBee()
var got EnvironmentV3
code := s.HandleRequest(
s.NewRequest("PATCH", fmt.Sprintf("/api/environments/v3/%d", edit.ID), EnvironmentV3Edit{
ServiceBannerBucket: utils.PointerTo(""),
}),
&got)
s.Equal(http.StatusOK, code)
println(got.ServiceBannerBucket)
s.Nil(got.ServiceBannerBucket)
}

func (s *handlerSuite) TestEnvironmentsV3Edit_setMissingBannerBucket() {
edit := s.TestData.Environment_DdpAzureDev()
var got EnvironmentV3
code := s.HandleRequest(
s.NewRequest("PATCH", fmt.Sprintf("/api/environments/v3/%d", edit.ID), EnvironmentV3Edit{
ServiceBannerBucket: utils.PointerTo("firecloud-alerts-ddp-azure-dev"),
}),
&got)
s.Equal(http.StatusOK, code)
if s.NotNil(got.ServiceBannerBucket) {
s.Equal("firecloud-alerts-ddp-azure-dev", *got.ServiceBannerBucket)
}
}
Loading