unit tests for load from file
This commit is contained in:
parent
21fcab0dee
commit
c698b821b8
55
flag_test.go
55
flag_test.go
@ -2,6 +2,8 @@ package cli
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
@ -1291,22 +1293,37 @@ func TestParseGenericFromEnvCascade(t *testing.T) {
|
|||||||
a.Run([]string{"run"})
|
a.Run([]string{"run"})
|
||||||
}
|
}
|
||||||
|
|
||||||
// func TestFlagFromFile(t *testing.T) {
|
func TestFlagFromFile(t *testing.T) {
|
||||||
// temp, err := ioutil.TempFile("", "urfave_cli_test")
|
os.Clearenv()
|
||||||
// if err != nil {
|
os.Setenv("APP_FOO", "123")
|
||||||
// t.Error(err)
|
|
||||||
// return
|
temp, err := ioutil.TempFile("", "urfave_cli_test")
|
||||||
// }
|
if err != nil {
|
||||||
// io.WriteString(temp, "abc")
|
t.Error(err)
|
||||||
// temp.Close()
|
return
|
||||||
// defer func() {
|
}
|
||||||
// os.Remove(temp.Name())
|
io.WriteString(temp, "abc")
|
||||||
// }()
|
temp.Close()
|
||||||
//
|
defer func() {
|
||||||
// if want, got := flagFromFileEnv("file-does-not-exist", "123"), "123"; want != got {
|
os.Remove(temp.Name())
|
||||||
// t.Errorf("Did not expect %v - Got %v", want, got)
|
}()
|
||||||
// }
|
|
||||||
// if want, got := flagFromFile(temp.Name(), "123"), "abc"; want != got {
|
var filePathTests = []struct {
|
||||||
// t.Errorf("Did not expect %v - Got %v", want, got)
|
path string
|
||||||
// }
|
name string
|
||||||
// }
|
expected string
|
||||||
|
}{
|
||||||
|
{"file-does-not-exist", "APP_BAR", ""},
|
||||||
|
{"file-does-not-exist", "APP_FOO", "123"},
|
||||||
|
{"file-does-not-exist", "APP_FOO,APP_BAR", "123"},
|
||||||
|
{temp.Name(), "APP_FOO", "123"},
|
||||||
|
{temp.Name(), "APP_BAR", "abc"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, filePathTest := range filePathTests {
|
||||||
|
got, _ := flagFromFileEnv(filePathTest.path, filePathTest.name)
|
||||||
|
if want := filePathTest.expected; got != want {
|
||||||
|
t.Errorf("Did not expect %v - Want %v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user