1- package altsrc
1+ package altsrc_test
22
33import (
44 "errors"
55 "fmt"
66 "io/ioutil"
77 "log"
88 "os"
9- "reflect"
109 "testing"
1110 "time"
1211
1312 "github.com/urfave/cli/v2"
14- // "github.com/urfave/cli/v2/altsrc"
13+ "github.com/urfave/cli/v2/altsrc"
1514)
1615
1716func ExampleApp_Run_yamlFileLoaderDuration () {
@@ -36,11 +35,11 @@ func ExampleApp_Run_yamlFileLoaderDuration() {
3635 } else if ! context .IsSet (configFlag ) && ! fileExists (configFile ) {
3736 return nil
3837 }
39- inputSource , err := NewYamlSourceFromFile (configFile )
38+ inputSource , err := altsrc . NewYamlSourceFromFile (configFile )
4039 if err != nil {
4140 return err
4241 }
43- return ApplyInputSourceValues (context , inputSource , flags )
42+ return altsrc . ApplyInputSourceValues (context , inputSource , flags )
4443 }
4544 }
4645
@@ -53,7 +52,7 @@ func ExampleApp_Run_yamlFileLoaderDuration() {
5352 DefaultText : "../testdata/empty.yml" ,
5453 Usage : "config file" ,
5554 },
56- NewDurationFlag (
55+ altsrc . NewDurationFlag (
5756 & cli.DurationFlag {
5857 Name : "keepalive-interval" ,
5958 Aliases : []string {"k" },
@@ -96,11 +95,11 @@ func TestYamlFileInt64Slice(t *testing.T) {
9695 defer os .Remove ("current.yaml" )
9796
9897 testFlag := []cli.Flag {
99- & StringFlag {StringFlag : & cli.StringFlag {Name : "conf" }},
100- & Int64SliceFlag {Int64SliceFlag : & cli.Int64SliceFlag {Name : "top.test" }},
98+ & altsrc. StringFlag {StringFlag : & cli.StringFlag {Name : "conf" }},
99+ & altsrc. Int64SliceFlag {Int64SliceFlag : & cli.Int64SliceFlag {Name : "top.test" }},
101100 }
102101 app := & cli.App {}
103- app .Before = InitInputSourceWithContext (testFlag , NewYamlSourceFromFlagFunc ("conf" ))
102+ app .Before = altsrc . InitInputSourceWithContext (testFlag , altsrc . NewYamlSourceFromFlagFunc ("conf" ))
104103 app .Action = func (c * cli.Context ) error { return nil }
105104 app .Flags = append (app .Flags , testFlag ... )
106105
@@ -116,11 +115,11 @@ func TestYamlFileStringSlice(t *testing.T) {
116115 defer os .Remove ("current.yaml" )
117116
118117 testFlag := []cli.Flag {
119- & StringFlag {StringFlag : & cli.StringFlag {Name : "conf" }},
120- & StringSliceFlag {StringSliceFlag : & cli.StringSliceFlag {Name : "top.test" , EnvVars : []string {"THE_TEST" }}},
118+ & altsrc. StringFlag {StringFlag : & cli.StringFlag {Name : "conf" }},
119+ & altsrc. StringSliceFlag {StringSliceFlag : & cli.StringSliceFlag {Name : "top.test" , EnvVars : []string {"THE_TEST" }}},
121120 }
122121 app := & cli.App {}
123- app .Before = InitInputSourceWithContext (testFlag , NewYamlSourceFromFlagFunc ("conf" ))
122+ app .Before = altsrc . InitInputSourceWithContext (testFlag , altsrc . NewYamlSourceFromFlagFunc ("conf" ))
124123 app .Action = func (c * cli.Context ) error {
125124 if c .IsSet ("top.test" ) {
126125 return nil
@@ -185,12 +184,12 @@ func TestYamlFileUint64(t *testing.T) {
185184 defer os .Remove ("current.yaml" )
186185
187186 testFlag := []cli.Flag {
188- & StringFlag {StringFlag : & cli.StringFlag {Name : "conf" }},
189- & Uint64Flag {Uint64Flag : & cli.Uint64Flag {Name : test .name }},
187+ & altsrc. StringFlag {StringFlag : & cli.StringFlag {Name : "conf" }},
188+ & altsrc. Uint64Flag {Uint64Flag : & cli.Uint64Flag {Name : test .name }},
190189 }
191190 app := & cli.App {}
192191 app .Flags = append (app .Flags , testFlag ... )
193- app .Before = InitInputSourceWithContext (testFlag , NewYamlSourceFromFlagFunc ("conf" ))
192+ app .Before = altsrc . InitInputSourceWithContext (testFlag , altsrc . NewYamlSourceFromFlagFunc ("conf" ))
194193
195194 appCmd := []string {"testApp" , "--conf" , "current.yaml" }
196195 err := app .Run (appCmd )
@@ -249,12 +248,12 @@ func TestYamlFileUint(t *testing.T) {
249248 defer os .Remove ("current.yaml" )
250249
251250 testFlag := []cli.Flag {
252- & StringFlag {StringFlag : & cli.StringFlag {Name : "conf" }},
253- & UintFlag {UintFlag : & cli.UintFlag {Name : test .name }},
251+ & altsrc. StringFlag {StringFlag : & cli.StringFlag {Name : "conf" }},
252+ & altsrc. UintFlag {UintFlag : & cli.UintFlag {Name : test .name }},
254253 }
255254 app := & cli.App {}
256255 app .Flags = append (app .Flags , testFlag ... )
257- app .Before = InitInputSourceWithContext (testFlag , NewYamlSourceFromFlagFunc ("conf" ))
256+ app .Before = altsrc . InitInputSourceWithContext (testFlag , altsrc . NewYamlSourceFromFlagFunc ("conf" ))
258257
259258 appCmd := []string {"testApp" , "--conf" , "current.yaml" }
260259 err := app .Run (appCmd )
@@ -313,12 +312,12 @@ func TestYamlFileInt64(t *testing.T) {
313312 defer os .Remove ("current.yaml" )
314313
315314 testFlag := []cli.Flag {
316- & StringFlag {StringFlag : & cli.StringFlag {Name : "conf" }},
317- & Int64Flag {Int64Flag : & cli.Int64Flag {Name : test .name }},
315+ & altsrc. StringFlag {StringFlag : & cli.StringFlag {Name : "conf" }},
316+ & altsrc. Int64Flag {Int64Flag : & cli.Int64Flag {Name : test .name }},
318317 }
319318 app := & cli.App {}
320319 app .Flags = append (app .Flags , testFlag ... )
321- app .Before = InitInputSourceWithContext (testFlag , NewYamlSourceFromFlagFunc ("conf" ))
320+ app .Before = altsrc . InitInputSourceWithContext (testFlag , altsrc . NewYamlSourceFromFlagFunc ("conf" ))
322321
323322 appCmd := []string {"testApp" , "--conf" , "current.yaml" }
324323 err := app .Run (appCmd )
@@ -327,36 +326,3 @@ func TestYamlFileInt64(t *testing.T) {
327326 }
328327 }
329328}
330-
331- func TestCastToUint64 (t * testing.T ) {
332- tests := []struct {
333- value interface {}
334- expect bool
335- }{
336- {int64 (100 ), true },
337- {uint (100 ), true },
338- }
339-
340- for _ , test := range tests {
341- v , isType := castToUint64 (test .value )
342- if isType != test .expect && reflect .TypeOf (v ).Kind () != reflect .Uint64 {
343- t .Fatalf ("expect %v, but %v" , test .expect , isType )
344- }
345- }
346- }
347-
348- func TestCastToUint (t * testing.T ) {
349- tests := []struct {
350- value interface {}
351- expect bool
352- }{
353- {int64 (100 ), true },
354- }
355-
356- for _ , test := range tests {
357- v , isType := castToUint (test .value )
358- if isType != test .expect && reflect .TypeOf (v ).Kind () != reflect .Uint64 {
359- t .Fatalf ("expect %v, but %v" , test .expect , isType )
360- }
361- }
362- }
0 commit comments