Commit graph

129 commits

Author SHA1 Message Date
Mark Sagi-Kazar
0594522560 test: fix failing tests on windows
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
2021-09-22 20:41:33 +02:00
Mark Sagi-Kazar
14c9dc6a57 test: fix file find tests on windows
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
2021-09-22 20:41:33 +02:00
Mark Sagi-Kazar
8b7777d3c6 test(windows): skip failing tests on windows
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
2021-09-22 11:17:33 +02:00
Mark Sagi-Kazar
15c88da25c test(windows): fix watch file test
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
2021-09-22 11:17:33 +02:00
Mark Sagi-Kazar
5a4e555471 test: add tests for reading config files
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
2021-09-21 18:01:05 +02:00
Mark Sagi-Kazar
557c5d64e0 test: improve tests for searching files
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
2021-09-21 18:01:05 +02:00
Séra Zoltán
a1f26b11bd Add test for cannot write hidden file without extension 2021-09-19 09:28:14 +02:00
Vasily Ovchinnikov
e606f7496e fix: made InConfig process paths correctly 2021-09-16 10:32:19 +02:00
Mikhail f. Shiryaev
bd03865899 Add a proper processing for pflag.StringArray 2021-06-25 13:55:36 +02:00
Mark Sagi-Kazar
65ee98690c chore(lint): fix gofumpt
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
2021-06-16 03:06:32 +02:00
Carolyn Van Slyck
cdb5e5976f Fix merging a key into a nil target
When merging a key where the target value is nil, the type of the target
and source do not match. What currently happens is an error is logged
and the key is skipped.

I have changed it so that it does the same thing as when the target key
is missing: copy the source value to the target.

Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com>
2021-05-17 08:55:31 +02:00
dylandreimerink
33bcdc91ea
Added support for accessing slices (#861)
* Added support for accessing slices

* Processed PR feedback
- renamed searchMapWithPathPrefixes to searchIndexableWithPathPrefixes
- moved source type specific search logic to speparate functions
- Inverted if statments to avoid the arrow pattern

* Quickly return from searchSliceWithPathPrefixes and searchMapWithPathPrefixes functions without intermediate variables
2020-10-04 20:07:34 +02:00
Mark Sagi-Kazar
82c2ddf493 Fix tests broken by mapstructure update
Mapstructure so far returned nil for empty string slices.
In a recent version this bug has been fixed:
https://github.com/mitchellh/mapstructure/pull/155

Incidentally, this was a bug in Viper too:

GetStringSlice and Unmarshal returned with different values.

Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
2020-09-30 15:03:37 +02:00
Mark Sagi-Kazar
cfcfed504d refactor: add setenv helper for tests
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
2020-09-30 13:15:51 +02:00
Gabriel Aszalos
b655224c01 Allow BindEnv to register multiple environment variables.
This change modifies BindEnv to permit a list of environment variable
names in order to support multiple env. vars. for the same config key.
When this form is used, env. keys take precedence in the written order.

Closes #971
2020-09-30 12:44:21 +02:00
Dan Rollo
a0285163e1 ensure BindPFlag() detects a nil flag parameter before wrapping in pflagValue. 2020-09-23 19:29:16 +02:00
Mark Sagi-Kazar
a5152092c6 Improve lint rules
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
2020-09-11 17:53:37 +02:00
Trevor Foster
3856c05f99
Fix: Getting the value of a StringToString pflag (#874)
* add parsing for stringToString flags

* add logic to return flags default if not val set, add a test

* extract parsing into single func

* add a few more cases

* return nil if unable to parse instead of panicing

* return map[string]interface in order to work with cast.ToStringMap

* mostly copy pflags implementation of the conversion to a stringtostring
2020-05-09 11:38:39 +02:00
Gustavo Bazan
97ee7adfef
Add support to save file with no extension (#813)
* Add support to save file with no extension

The support introduced for files with no file extension is only partial as trying to save the config file would fail with `<file name> requires valid extension`
This adds support to saving such files
2020-02-20 00:41:04 +01:00
Pedro Silva
9cd571279d Extensionless files only allowed when config type is set (#827)
* Only consider files without extension if the config type is explicitly specified

* Hides unused variable in test

* First check for config type then for file without extension
2020-01-16 19:23:50 +01:00
Mark Sagi-Kazar
eabbc68a3e Fix file path lookup 2019-12-06 17:29:42 +01:00
Mark Sagi-Kazar
4ad4c8df70 Add string replacer interface and env key replacer option 2019-12-06 14:13:46 +01:00
Mark Sagi-Kazar
a842b8f618 Replace SetKeyDelimiter with functional options 2019-12-06 14:01:42 +01:00
Mark Sagi-Kazar
a73303ee89 Add key delimiter setter 2019-12-06 14:01:42 +01:00
Mark Sagi-Kazar
2fd264d3d1 Fix misspell 2019-12-06 13:00:52 +01:00
Mark Sagi-Kazar
8b7fbcaa4b Fix golint 2019-12-06 13:00:52 +01:00
Mark Sagi-Kazar
7b5adba788 Fix whitespace 2019-12-06 13:00:52 +01:00
Mark Sagi-Kazar
e316012b4d Fix gofmt 2019-12-06 13:00:52 +01:00
Matti R
351bfe9719 loop through ini sections
pass tests

write out ini file & tests

go fmt

Update viper_test.go
fix test

gofmt
2019-12-06 09:02:54 +01:00
javaducky
3a19b6e0d9 Review updates to utilize afero for file checks and updated checks on unit tests 2019-12-06 08:36:52 +01:00
javaducky
a708479794 Updating SafeWriteConfig and SafeWriteConfigAs to match documented behavior.
Methods should throw an error if the config file already exists or if no configpath is configured when not explicitly requesting a write path.
2019-12-06 08:36:52 +01:00
Benoit Masson
4e1ebbdaba Added tests to TestIsSet()
Added tests for:
- nested elements
- environment values
- flags (currently fails => IsSet() always returns true,
                            due to the default value of the flag)
2019-11-29 21:16:13 +01:00
Pedro Silva
d1c60d9e69 Support config files with no extensions (#722)
* Support config files with no extensions

* Update README informing config files without extension are supported
2019-11-06 14:54:13 +01:00
Mark Sagi-Kazar
71509d2887 Revert the effective changes of #673 2019-09-28 12:02:57 +02:00
Mark Sagi-Kazar
398adc5a7d Add breaking test that requires reverting #673 2019-09-28 12:02:57 +02:00
inkychris
99520c81d8 Implemented ability to unmarshal keys containing dots to structs.
Changed formatting of test objects for better git diffing and readibility.
Fixed failing tests on Windows.
2019-09-11 16:03:08 +02:00
Christian Muehlhaeuser
33bf76add3 Simplify code
Removed unnecessary conversions.
2019-07-29 18:37:00 +02:00
Christian Muehlhaeuser
1b33e8258e Add error handling
Added error handling around ineffectual err assignments. Please review
thoroughly.
2019-07-28 14:50:13 +02:00
CodeLingo Bot
275a36d0a0 Fix function comments based on best practices from Effective Go
Signed-off-by: CodeLingo Bot <bot@codelingo.io>
2019-07-13 12:11:16 +02:00
AGirard
b8221cf4ee Add GetIntSlice helper method 2019-07-13 12:04:36 +02:00
Márk Sági-Kazár
ad5ed02fa4 Add support for int slice flags (#637)
* Add support for int slice flags

* Add int slice test to unmarshal
2019-06-11 16:51:57 -04:00
mexisme
3620d3d9e1 Support .env format files (#528)
* Support `.env` format files

* Missing "dotenv" from SupportedExtns
2019-06-11 16:47:43 -04:00
Anthony Fok
2bd2732789
Use GetInt64 for largenum in viper_test.go
to prevent overflow error on 32-bit platforms.

Fixes #704
2019-05-24 11:53:49 -06:00
Anthony Fok
93066f92c6
Fix typo in viper_test.go: lagrenum → largenum 2019-05-24 07:40:12 -06:00
Mitch Connors
7a605a50e6 Uint Support (#681)
* add GetUint/GetUint32/GetUint64

* Add Get(string) support for uint.
2019-04-08 10:06:45 -04:00
Bjørn Erik Pedersen
6d33b5a963
Make the map in MergeConfigMap case insensitive 2018-12-07 11:03:36 +01:00
Bjørn Erik Pedersen
41cd1c3aa3 Restrict Travis to >= Go 1.11, use Go Modules, and get the test to pass 2018-12-05 17:13:47 +01:00
Bjørn Erik Pedersen
3535c75fa8 Add MergeConfigMap
Fixes #605
2018-12-05 17:13:47 +01:00
Bjørn Erik Pedersen
06c7c0d9b3
Use assert.EqualValues for slice checking 2018-11-19 10:38:40 +01:00
Benoit Masson
ae103d7e59 Moved shared resources out of the loops in TestBindPFlagsStringSlice()
Common code and resources put out of the loops, to improve
efficiency and readability.
2018-11-07 12:08:59 +01:00