Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

explicitly pass config path when reading dnf config #131

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions dnfconfig/defaultconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ func TestDefaultDnfRepoConfig(t *testing.T) {
repoHost := "https://artifactory.infra.corp.arista.io"
viper.Set("DnfRepoHost",
"https://artifactory.infra.corp.arista.io")
viper.Set("DnfConfigFile", "../configfiles/dnfconfig.yaml")
defer viper.Reset()

t.Log("Testing YAML syntax")
dnfConfig, loadErr := LoadDnfConfig()
dnfConfig, loadErr := LoadDnfConfig("../configfiles/dnfconfig.yaml")
require.NoError(t, loadErr)
require.NotNil(t, dnfConfig)
t.Log("YAML syntax ok")
Expand Down
3 changes: 1 addition & 2 deletions dnfconfig/dnfconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ func (b *DnfRepoBundleConfig) GetDnfRepoParams(
// Enabled computes enabled flags for a particular repo
// LoadDnfConfig loads the dnf repo config file, parses it and
// returns the data structure
func LoadDnfConfig() (*DnfConfig, error) {
cfgPath := viper.GetString("DnfConfigFile")
func LoadDnfConfig(cfgPath string) (*DnfConfig, error) {
_, statErr := os.Stat(cfgPath)
if statErr != nil {
if os.IsNotExist(statErr) {
Expand Down
3 changes: 1 addition & 2 deletions dnfconfig/dnfconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ func TestRepoConfig(t *testing.T) {
t.Fatal(err)
}
defer os.RemoveAll(dir)
viper.Set("DnfConfigFile", "testData/sample-dnfconfig.yaml")
viper.Set("DnfRepoHost", "http://foo.org")
defer viper.Reset()

t.Log("Testing Load")
dnfConfig, loadErr := LoadDnfConfig()
dnfConfig, loadErr := LoadDnfConfig("testData/sample-dnfconfig.yaml")
require.NoError(t, loadErr)
require.NotNil(t, dnfConfig)
require.Contains(t, dnfConfig.DnfRepoBundleConfig, "bundle1")
Expand Down
4 changes: 2 additions & 2 deletions impl/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ func Mock(repo string, pkg string, arch string, extraArgs MockExtraCmdlineArgs)
util.ErrPrefix("mockBuilder: ")); err != nil {
return err
}

dnfConfig, dnfConfigErr := dnfconfig.LoadDnfConfig()
cfgPath := viper.GetString("DnfConfigFile")
dnfConfig, dnfConfigErr := dnfconfig.LoadDnfConfig(cfgPath)
if dnfConfigErr != nil {
return dnfConfigErr
}
Expand Down
3 changes: 2 additions & 1 deletion impl/mock_cfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ func testMockConfig(t *testing.T, chained bool) {
require.NotNil(t, manifestObj)

t.Log("Load dnfconfig.yaml")
dnfConfig, loadErr := dnfconfig.LoadDnfConfig()
cfgPath := viper.GetString("DnfConfigFile")
dnfConfig, loadErr := dnfconfig.LoadDnfConfig(cfgPath)
require.NoError(t, loadErr)
require.NotNil(t, dnfConfig)

Expand Down
Loading