Skip to content

Commit

Permalink
Make TryReadConfig call GenerateDefaults
Browse files Browse the repository at this point in the history
Also change GenerateDefaults test to fit with this
  • Loading branch information
einarmo committed Jun 10, 2020
1 parent 544443f commit 7edc0c5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions Cognite.Config/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ public static int GetVersionFromString(string yaml)

/// <summary>
/// Try to read a configuration object of type <typeparamref name="T"/> from the provided <paramref name="yaml"/>
/// string. Matching the configuration object version with the versions provided in <paramref name="acceptedConfigVersions"/>
/// string. Matching the configuration object version with the versions provided in <paramref name="acceptedConfigVersions"/>.
/// Also calls GenerateDefaults() on the retrieved configuration object after reading.
/// </summary>
/// <param name="yaml">String containing a yaml configuration</param>
/// <param name="acceptedConfigVersions">Accepted versions</param>
Expand All @@ -108,13 +109,17 @@ public static T TryReadConfigFromString<T>(string yaml, params int[] acceptedCon
{
int configVersion = ConfigurationUtils.GetVersionFromString(yaml);
CheckVersion(configVersion, acceptedConfigVersions);
return ConfigurationUtils.ReadString<T>(yaml);

var config = ConfigurationUtils.ReadString<T>(yaml);
config.GenerateDefaults();
return config;
}

/// <summary>
/// Try to read a configuration object of type <typeparamref name="T"/> from the yaml file located in
/// the provided <paramref name="path"/>. Matching the configuration object version with the versions
/// provided in <paramref name="acceptedConfigVersions"/>
/// provided in <paramref name="acceptedConfigVersions"/>.
/// Also calls GenerateDefaults() on the retrieved configuration object after reading.
/// </summary>
/// <param name="path">Path to the yml file</param>
/// <param name="acceptedConfigVersions">Accepted versions</param>
Expand All @@ -127,7 +132,9 @@ public static T TryReadConfigFromFile<T>(string path, params int[] acceptedConfi
int configVersion = ConfigurationUtils.GetVersionFromFile(path);
CheckVersion(configVersion, acceptedConfigVersions);

return ConfigurationUtils.Read<T>(path);
var config = ConfigurationUtils.Read<T>(path);
config.GenerateDefaults();
return config;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion ExtractorUtils.Test/ConfigurationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public static void TestEmptyVersion()
public static void TestGenerateDefaults()
{
var yaml = "version: 0";
var conf = ConfigurationUtils.TryReadConfigFromString<TestBaseConfig>(yaml);
var conf = ConfigurationUtils.ReadString<TestBaseConfig>(yaml);
Assert.Null(conf.Cognite);
Assert.Null(conf.Logger);
Assert.Null(conf.Metrics);
Expand Down

0 comments on commit 7edc0c5

Please sign in to comment.