Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
RSDK-2961 Default use_live_data to true (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
EshaMaharishi authored May 16, 2023
1 parent 17a343e commit 44f0c42
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
11 changes: 6 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ func DetermineDeleteProcessedData(logger golog.Logger, deleteData *bool, useLive
// DetermineUseLiveData will determine the value of the useLiveData attribute
// based on the liveData input parameter and sensor list.
func DetermineUseLiveData(logger golog.Logger, liveData *bool, sensors []string) (bool, error) {
// If liveData is not set, default it to true and require a sensor to have been provided.
if liveData == nil {
return false, newError("use_live_data is a required input parameter")
if len(sensors) == 0 {
return false, newError("sensors field cannot be empty")
}
return true, nil
}

useLiveData := *liveData
if useLiveData && len(sensors) == 0 {
return false, newError("sensors field cannot be empty when use_live_data is set to true")
Expand Down Expand Up @@ -64,10 +69,6 @@ func (config *Config) Validate(path string) ([]string, error) {
return nil, utils.NewConfigValidationFieldRequiredError(path, "data_dir")
}

if config.UseLiveData == nil {
return nil, utils.NewConfigValidationFieldRequiredError(path, "use_live_data")
}

if config.DataRateMsec < 0 {
return nil, errors.New("cannot specify data_rate_msec less than zero")
}
Expand Down
8 changes: 4 additions & 4 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestValidate(t *testing.T) {

t.Run("Config without required fields", func(t *testing.T) {
// Test for missing main attribute fields
requiredFields := []string{"data_dir", "use_live_data"}
requiredFields := []string{"data_dir"}
for _, requiredField := range requiredFields {
logger.Debugf("Testing SLAM config without %s\n", requiredField)
cfgService := makeCfgService()
Expand Down Expand Up @@ -131,12 +131,12 @@ func TestDetermineUseLiveData(t *testing.T) {
logger := golog.NewTestLogger(t)
t.Run("No use_live_data specified", func(t *testing.T) {
useLiveData, err := DetermineUseLiveData(logger, nil, []string{})
test.That(t, err, test.ShouldBeError, newError("use_live_data is a required input parameter"))
test.That(t, err, test.ShouldBeError, newError("sensors field cannot be empty"))
test.That(t, useLiveData, test.ShouldBeFalse)

useLiveData, err = DetermineUseLiveData(logger, nil, []string{"camera"})
test.That(t, err, test.ShouldBeError, newError("use_live_data is a required input parameter"))
test.That(t, useLiveData, test.ShouldBeFalse)
test.That(t, err, test.ShouldBeNil)
test.That(t, useLiveData, test.ShouldBeTrue)
})
t.Run("False use_live_data", func(t *testing.T) {
useLiveData, err := DetermineUseLiveData(logger, &_false, []string{})
Expand Down

0 comments on commit 44f0c42

Please sign in to comment.