Skip to content

Commit

Permalink
[DDO-3900] Fix clearing banner bucket (#714)
Browse files Browse the repository at this point in the history
  • Loading branch information
em-may authored Nov 21, 2024
1 parent ae3dff6 commit b728e86
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
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)
}
}

0 comments on commit b728e86

Please sign in to comment.