From a11a8ad606e134e94bfd92165e7f6113f6162776 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sat, 6 Jul 2024 01:17:57 +0200 Subject: [PATCH 1/3] Add File() similar to EnvVar() --- value_source.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/value_source.go b/value_source.go index 266f5e54bf..7d3f7ee45c 100644 --- a/value_source.go +++ b/value_source.go @@ -128,6 +128,10 @@ func (f *fileValueSource) GoString() string { return fmt.Sprintf("&fileValueSource{Path:%[1]q}", f.Path) } +func File(path string) ValueSource { + return &fileValueSource{Path: path} +} + // Files is a helper function to encapsulate a number of // fileValueSource together as a ValueSourceChain func Files(paths ...string) ValueSourceChain { From c9bc880441a66a061ecf535fde466ed6e66fd43d Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sat, 6 Jul 2024 02:16:41 +0200 Subject: [PATCH 2/3] generate godoc --- godoc-current.txt | 2 ++ testdata/godoc-v3.x.txt | 2 ++ 2 files changed, 4 insertions(+) diff --git a/godoc-current.txt b/godoc-current.txt index 07bd07eca4..80d41e856d 100644 --- a/godoc-current.txt +++ b/godoc-current.txt @@ -979,6 +979,8 @@ type ValueSource interface { func EnvVar(key string) ValueSource +func File(path string) ValueSource + type ValueSourceChain struct { Chain []ValueSource } diff --git a/testdata/godoc-v3.x.txt b/testdata/godoc-v3.x.txt index 07bd07eca4..80d41e856d 100644 --- a/testdata/godoc-v3.x.txt +++ b/testdata/godoc-v3.x.txt @@ -979,6 +979,8 @@ type ValueSource interface { func EnvVar(key string) ValueSource +func File(path string) ValueSource + type ValueSourceChain struct { Chain []ValueSource } From bb1b3a9eb3c268d217b1c3821d052daf289ee51a Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sat, 6 Jul 2024 03:23:45 +0200 Subject: [PATCH 3/3] use File() in tests --- value_source_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/value_source_test.go b/value_source_test.go index 57b9cfdcb4..7f1c36ece9 100644 --- a/value_source_test.go +++ b/value_source_test.go @@ -71,7 +71,7 @@ func TestFileValueSource(t *testing.T) { r.Implements((*ValueSource)(nil), &fileValueSource{}) t.Run("not found", func(t *testing.T) { - src := &fileValueSource{Path: fmt.Sprintf("junk_file_name-%[1]v", rand.Int())} + src := File(fmt.Sprintf("junk_file_name-%[1]v", rand.Int())) _, ok := src.Lookup() r.False(ok) }) @@ -82,7 +82,7 @@ func TestFileValueSource(t *testing.T) { r.Nil(os.WriteFile(fileName, []byte("pita"), 0o644)) t.Run("found", func(t *testing.T) { - src := &fileValueSource{Path: fileName} + src := File(fileName) str, ok := src.Lookup() r.True(ok) r.Equal("pita", str) @@ -90,7 +90,7 @@ func TestFileValueSource(t *testing.T) { }) t.Run("implements fmt.Stringer", func(t *testing.T) { - src := &fileValueSource{Path: "/dev/null"} + src := File("/dev/null") r := require.New(t) r.Implements((*ValueSource)(nil), src) @@ -98,7 +98,7 @@ func TestFileValueSource(t *testing.T) { }) t.Run("implements fmt.GoStringer", func(t *testing.T) { - src := &fileValueSource{Path: "/dev/null"} + src := File("/dev/null") r := require.New(t) r.Implements((*ValueSource)(nil), src)