Commit graph

160 commits

Author SHA1 Message Date
sandeep
2e9148610a
fix #1700: update tests to use local viper instance (#1791)
* fix:test to use local viper instance

* fix linting

* fix typo

* remove unsed function
2024-04-07 13:09:02 +02:00
Mark Sagi-Kazar
030b77a720 fix: lint violations
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
2024-02-15 14:19:50 +01:00
Mark Sagi-Kazar
473a3dfc7f fix!: hide struct binding behind a feature flag
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
2023-12-18 19:36:22 +01:00
Filip Krakowski
fb6eb1e8e9 fix: merge missing struct keys inside UnmarshalExact 2023-12-08 14:44:05 +01:00
linuxsong
f7363633d1
fix isPathShadowedInFlatMap type cast bug (#1585)
* fix isPathShadowedInFlatMap type cast bug

* Add "IsPathShadowedInFlatMap" method unit test

* fix: typo

* add an unit test for flag shadow

---------

Co-authored-by: Márk Sági-Kazár <sagikazarmark@users.noreply.github.com>
2023-12-06 14:41:36 +01:00
Oleksandr Redko
36a38682ba Review changes 2023-12-06 19:07:50 +07:00
Oleksandr Redko
f0c4ccd6cd fix: gocritic lint issues 2023-12-06 19:07:50 +07:00
Oleksandr Redko
3a23b80b11 ci: enable test shuffle; fix tests 2023-12-06 19:03:14 +07:00
Mark Sagi-Kazar
73dfb94c57 feat: make Unmarshal work with AutomaticEnv
Co-authored-by: Filip Krakowski <krakowski@hhu.de>
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
2023-12-06 18:44:04 +07:00
Oleksandr Redko
c4dcd31f68 fix: godot lint issues 2023-11-30 21:20:53 +07:00
Oleksandr Redko
b5daec6e7b test: Replace ifs with asserts to simplify tests 2023-10-14 02:12:35 +02:00
Oleksandr Redko
c292b55050 test: refactor asserts 2023-10-05 00:58:18 +02:00
Oleksandr Redko
3d006fe361 refactor: replace interface{} with any 2023-10-01 17:04:26 +02:00
Oleksandr Redko
6fdfebc843 Fix tests on Windows 2023-09-16 13:48:38 +02:00
Oleksandr Redko
4aeec5882c Remove usages of deprecated io/ioutil; simplify tests 2023-09-16 13:48:38 +02:00
Oleksandr Redko
13dbfcafff test: remove testutil.Setenv as not needed from Go 1.17 2023-09-07 13:33:21 +02:00
Oleksandr Redko
a0696bbc97 docs: fix typos in comments 2023-09-07 13:32:51 +02:00
andig
21a7fd828e
Allow ConfigParseError to unwrap (#1433)
* Allow ConfigParseError to unwrap

* wip

* Avoid pointer type
2023-05-30 12:07:27 +02:00
VOrishirne
2ee16310d0 extend viper's pflag binding to stringToInt pflag 2023-05-29 15:34:52 +02:00
Mark Sagi-Kazar
995db99714 test: fix test to actually assert something
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
2023-04-06 11:12:29 +02:00
TaylorOno
3970ad177e Preserve envPrefix in Sub 2023-02-25 22:17:36 +01:00
TaylorOno
3f4449054d Sub inerits from automaticEnvApplied and envKeyReplacer
parents are tracked so sub(x).sub(y).GetString(z) looks up x.y.z
2023-02-25 22:17:36 +01:00
Dawid Urbański
c898f59d33
fix: time.Duration slice type conversion (#1498)
* fix DurationSlice

* Fix typo

---------

Co-authored-by: Márk Sági-Kazár <sagikazarmark@users.noreply.github.com>
2023-02-05 18:30:05 +01:00
Christian Banse
202060b3a2 Adds support for uint16 with GetUint16
We have encountered numerous places where it is convenient to have viper return a `uint16` value, especially in combination with the new `netip` package  that represents a port correctly as `uint16` rather than just an `int`. cobra already supports this, but we need a conversion from the existing `GetUint` method in viper.
2022-09-04 03:07:23 +02:00
Mark Sagi-Kazar
97591f0083 build: fix lint violations
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
2022-09-03 19:07:15 +02:00
Andrew Richardson
5247643f02 Recurse into arrays when converting keys to lowercase
Fixes #1386

Signed-off-by: Andrew Richardson <andrew.richardson@kaleido.io>
2022-07-12 18:10:05 +02:00
Illarion Kovalchuk
97664ba020 Added test case for merging configs, where target is null, and source is not null 2022-01-11 22:36:46 +01:00
illarion Kovalchuk
0353c6ea50 Allow merging configs with different types of leaf values 2022-01-11 22:36:46 +01:00
Mark Sagi-Kazar
98c10c3c31 test(encoding): fix failing tests due to the yaml library update
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
2022-01-01 18:16:38 +01:00
Mark Sagi-Kazar
35877c8f77 chore: fix lint
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
2021-11-21 15:05:44 +01:00
Mark Sagi-Kazar
41ec2aaf27 chore: run lint fixer
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
2021-11-21 14:51:34 +01:00
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