@@ -6,13 +6,15 @@ import (
66 "os"
77 "testing"
88
9+ "github.com/spf13/afero"
910 "github.com/stretchr/testify/assert"
1011
1112 "github.com/netapp/trident/internal/nodeprep/mpathconfig"
1213)
1314
1415func TestNew (t * testing.T ) {
15- config , err := mpathconfig .New ()
16+ fs := afero .NewMemMapFs ()
17+ config , err := mpathconfig .New (afero.Afero {Fs : fs })
1618 assert .Nil (t , err )
1719 assert .NotNil (t , config )
1820 assert .IsType (t , & mpathconfig.Configuration {}, config )
@@ -38,9 +40,11 @@ func TestNewFromFile(t *testing.T) {
3840 },
3941 }
4042
43+ fs := afero .NewMemMapFs ()
44+
4145 for name , params := range tests {
4246 t .Run (name , func (t * testing.T ) {
43- config , err := mpathconfig .NewFromFile (params .fileName )
47+ config , err := mpathconfig .NewFromFile (afero. Afero { Fs : fs }, params .fileName )
4448 if params .assertError != nil {
4549 params .assertError (t , err )
4650 }
@@ -52,7 +56,9 @@ func TestNewFromFile(t *testing.T) {
5256}
5357
5458func TestConfiguration_GetRootSection (t * testing.T ) {
55- config , err := mpathconfig .New ()
59+ fs := afero .NewMemMapFs ()
60+
61+ config , err := mpathconfig .New (afero.Afero {Fs : fs })
5662 assert .Nil (t , err )
5763 assert .NotNil (t , config )
5864
@@ -62,6 +68,9 @@ func TestConfiguration_GetRootSection(t *testing.T) {
6268}
6369
6470func TestConfiguration_GetSection (t * testing.T ) {
71+ fs := afero .NewMemMapFs ()
72+ os := afero.Afero {Fs : fs }
73+
6574 type parameters struct {
6675 getConfig func () mpathconfig.MpathConfiguration
6776 sectionName string
@@ -80,7 +89,7 @@ func TestConfiguration_GetSection(t *testing.T) {
8089 },
8190 "get default section from empty configuration" : {
8291 getConfig : func () mpathconfig.MpathConfiguration {
83- config , err := mpathconfig .New ()
92+ config , err := mpathconfig .New (os )
8493 assert .Nil (t , err )
8594 return config
8695 },
@@ -90,7 +99,7 @@ func TestConfiguration_GetSection(t *testing.T) {
9099 },
91100 "get default section from configuration that has a default section" : {
92101 getConfig : func () mpathconfig.MpathConfiguration {
93- config , err := mpathconfig .New ()
102+ config , err := mpathconfig .New (os )
94103 assert .Nil (t , err )
95104
96105 _ , err = config .GetRootSection ().AddSection (mpathconfig .DefaultsSectionName )
@@ -104,7 +113,7 @@ func TestConfiguration_GetSection(t *testing.T) {
104113 },
105114 "get invalid section from configuration that has a default section" : {
106115 getConfig : func () mpathconfig.MpathConfiguration {
107- config , err := mpathconfig .New ()
116+ config , err := mpathconfig .New (os )
108117 assert .Nil (t , err )
109118
110119 _ , err = config .GetRootSection ().AddSection (mpathconfig .DefaultsSectionName )
@@ -134,6 +143,9 @@ func TestConfiguration_GetSection(t *testing.T) {
134143}
135144
136145func TestConfiguration_PrintConf (t * testing.T ) {
146+ fs := afero .NewMemMapFs ()
147+ os := afero.Afero {Fs : fs }
148+
137149 type parameters struct {
138150 getConfig func () mpathconfig.MpathConfiguration
139151 expectedOutput []string
@@ -148,15 +160,15 @@ func TestConfiguration_PrintConf(t *testing.T) {
148160 },
149161 "print empty configuration" : {
150162 getConfig : func () mpathconfig.MpathConfiguration {
151- config , err := mpathconfig .New ()
163+ config , err := mpathconfig .New (os )
152164 assert .Nil (t , err )
153165 return config
154166 },
155167 expectedOutput : nil ,
156168 },
157169 "print configuration with a default section" : {
158170 getConfig : func () mpathconfig.MpathConfiguration {
159- config , err := mpathconfig .New ()
171+ config , err := mpathconfig .New (os )
160172 assert .Nil (t , err )
161173
162174 _ , err = config .GetRootSection ().AddSection (mpathconfig .DefaultsSectionName )
@@ -178,7 +190,8 @@ func TestConfiguration_PrintConf(t *testing.T) {
178190}
179191
180192func TestConfiguration_SaveConfig (t * testing.T ) {
181- config , err := mpathconfig .New ()
193+ fs := afero .NewMemMapFs ()
194+ config , err := mpathconfig .New (afero.Afero {Fs : fs })
182195 assert .NoError (t , err )
183196 defaultSection , err := config .GetRootSection ().AddSection (mpathconfig .DefaultsSectionName )
184197 assert .NoError (t , err )
0 commit comments