summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/magiconair/properties/integrate_test.go
diff options
context:
space:
mode:
authorCorey Hulen <corey@hulen.com>2017-03-24 23:31:34 -0700
committerenahum <nahumhbl@gmail.com>2017-03-25 03:31:34 -0300
commit54d3d47daf9190275bbdaf8703b84969a4593451 (patch)
tree05899b296d0186c1a0da8a540bc486e34ad8eec9 /vendor/github.com/magiconair/properties/integrate_test.go
parent7460302dec7796e01c98264e84bece8169cb6ed9 (diff)
downloadchat-54d3d47daf9190275bbdaf8703b84969a4593451.tar.gz
chat-54d3d47daf9190275bbdaf8703b84969a4593451.tar.bz2
chat-54d3d47daf9190275bbdaf8703b84969a4593451.zip
PLT-6076 Adding viper libs for config file changes (#5871)
* Adding viper libs for config file changes * Removing the old fsnotify lib * updating some missing libs
Diffstat (limited to 'vendor/github.com/magiconair/properties/integrate_test.go')
-rw-r--r--vendor/github.com/magiconair/properties/integrate_test.go76
1 files changed, 76 insertions, 0 deletions
diff --git a/vendor/github.com/magiconair/properties/integrate_test.go b/vendor/github.com/magiconair/properties/integrate_test.go
new file mode 100644
index 000000000..cbee181f6
--- /dev/null
+++ b/vendor/github.com/magiconair/properties/integrate_test.go
@@ -0,0 +1,76 @@
+// Copyright 2017 Frank Schroeder. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package properties
+
+import (
+ "flag"
+ "fmt"
+ "testing"
+)
+
+// TestFlag verifies Properties.MustFlag without flag.FlagSet.Parse
+func TestFlag(t *testing.T) {
+ f := flag.NewFlagSet("src", flag.PanicOnError)
+ gotS := f.String("s", "?", "string flag")
+ gotI := f.Int("i", -1, "int flag")
+
+ p := NewProperties()
+ p.MustSet("s", "t")
+ p.MustSet("i", "9")
+ p.MustFlag(f)
+
+ if want := "t"; *gotS != want {
+ t.Errorf("Got string s=%q, want %q", *gotS, want)
+ }
+ if want := 9; *gotI != want {
+ t.Errorf("Got int i=%d, want %d", *gotI, want)
+ }
+}
+
+// TestFlagOverride verifies Properties.MustFlag with flag.FlagSet.Parse.
+func TestFlagOverride(t *testing.T) {
+ f := flag.NewFlagSet("src", flag.PanicOnError)
+ gotA := f.Int("a", 1, "remain default")
+ gotB := f.Int("b", 2, "customized")
+ gotC := f.Int("c", 3, "overridden")
+
+ if err := f.Parse([]string{"-c", "4"}); err != nil {
+ t.Fatal(err)
+ }
+
+ p := NewProperties()
+ p.MustSet("b", "5")
+ p.MustSet("c", "6")
+ p.MustFlag(f)
+
+ if want := 1; *gotA != want {
+ t.Errorf("Got remain default a=%d, want %d", *gotA, want)
+ }
+ if want := 5; *gotB != want {
+ t.Errorf("Got customized b=%d, want %d", *gotB, want)
+ }
+ if want := 4; *gotC != want {
+ t.Errorf("Got overriden c=%d, want %d", *gotC, want)
+ }
+}
+
+func ExampleProperties_MustFlag() {
+ x := flag.Int("x", 0, "demo customize")
+ y := flag.Int("y", 0, "demo override")
+
+ // Demo alternative for flag.Parse():
+ flag.CommandLine.Parse([]string{"-y", "10"})
+ fmt.Printf("flagged as x=%d, y=%d\n", *x, *y)
+
+ p := NewProperties()
+ p.MustSet("x", "7")
+ p.MustSet("y", "42") // note discard
+ p.MustFlag(flag.CommandLine)
+ fmt.Printf("configured to x=%d, y=%d\n", *x, *y)
+
+ // Output:
+ // flagged as x=0, y=10
+ // configured to x=7, y=10
+}