-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix #249 * The bug was the function UseRAGEnabled was using a hard coded value for the default rather than the constant. As a result, when we recently changed the default to be true it wasn't actually enabled by default. * Refactor viper processing so its easy to test configuration in a unittest * We want to be able to create instances of viper using viper.New in the unittest so that we don't have to only use the global viper instance. * To support that we refactor InitViper into a separate function which takes as an argument *viper.Viper
- Loading branch information
Showing
2 changed files
with
99 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package config | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/spf13/viper" | ||
) | ||
|
||
func Test_ConfigDefaultConfig(t *testing.T) { | ||
// Create an empty configuration file and run various assertions on it | ||
v := viper.New() | ||
v.SetConfigFile("/tmp/doesnnotexist.yaml") | ||
|
||
if err := InitViperInstance(v, nil); err != nil { | ||
t.Fatalf("Failed to initialize the configuration.") | ||
} | ||
|
||
cfg, err := getConfigFromViper(v) | ||
|
||
if err != nil { | ||
t.Fatalf("Failed to get config; %+v", err) | ||
} | ||
|
||
if cfg.UseRAG() != defaultRagEnabled { | ||
t.Errorf("UseRAG want %v; got %v", defaultRagEnabled, cfg.UseRAG()) | ||
} | ||
|
||
if len(cfg.GetTrainingDirs()) == 0 { | ||
t.Errorf("GetTrainingDirs shouldn't return an empty list") | ||
} | ||
} |