Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
longquanzheng committed Aug 26, 2021
1 parent c0ef2c6 commit e6613aa
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
8 changes: 8 additions & 0 deletions common/config/archival.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,20 @@ func (a *Archival) Validate(domainDefaults *ArchivalDomainDefaults) error {
if domainDefaults.History.URI == "" || a.History.Provider == nil {
return errors.New("invalid history archival config, must provide domainDefaults.History.URI and Provider")
}
} else {
if a.History.EnableRead {
return errors.New("invalid history archival config, cannot EnableRead when archival is disabled")
}
}

if a.Visibility.Status == common.ArchivalEnabled {
if domainDefaults.Visibility.URI == "" || a.Visibility.Provider == nil {
return errors.New("invalid visibility archival config, must provide domainDefaults.Visibility.URI and Provider")
}
} else {
if a.Visibility.EnableRead {
return errors.New("invalid visibility archival config, cannot EnableRead when archival is disabled")
}
}

return nil
Expand Down
44 changes: 41 additions & 3 deletions common/config/archival_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
// Copyright (c) 2021 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package config

import (
Expand Down Expand Up @@ -53,12 +73,21 @@ func TestValidDisabledHistoryArchivalConfig(t *testing.T) {
require.NoError(t, err)
}

func TestValidEmptyHistoryArchivalConfig(t *testing.T) {
func TestInvalidDisabledHistoryArchivalConfig(t *testing.T) {
archival := Archival{
History: HistoryArchival{
EnableRead: true,
},
}
err := archival.Validate(&ArchivalDomainDefaults{})
require.Error(t, err)
}

func TestValidEmptyHistoryArchivalConfig(t *testing.T) {
archival := Archival{
History: HistoryArchival{},
}
err := archival.Validate(&ArchivalDomainDefaults{})
require.NoError(t, err)
}

Expand Down Expand Up @@ -107,11 +136,20 @@ func TestValidDisabledVisibilityArchivalConfig(t *testing.T) {
require.NoError(t, err)
}

func TestValidEmptyVisibilityArchivalConfig(t *testing.T) {
func TestInvalidDisabledVisibilityArchivalConfig(t *testing.T) {
archival := Archival{
Visibility: VisibilityArchival{
EnableRead: true,
},
}
err := archival.Validate(&ArchivalDomainDefaults{})
require.Error(t, err)
}

func TestValidEmptyVisibilityArchivalConfig(t *testing.T) {
archival := Archival{
Visibility: VisibilityArchival{},
}
err := archival.Validate(&ArchivalDomainDefaults{})
require.NoError(t, err)
}
}

0 comments on commit e6613aa

Please sign in to comment.