Add vendor folder to git

This commit is contained in:
Lucas Käldström 2017-06-26 19:23:05 +03:00
parent 66cf5eaafb
commit 183585f56f
No known key found for this signature in database
GPG key ID: 600FEFBBD0D40D21
6916 changed files with 2629581 additions and 1 deletions

55
vendor/github.com/coreos/pkg/yamlutil/yaml.go generated vendored Normal file
View file

@ -0,0 +1,55 @@
package yamlutil
import (
"flag"
"fmt"
"strings"
"gopkg.in/yaml.v1"
)
// SetFlagsFromYaml goes through all registered flags in the given flagset,
// and if they are not already set it attempts to set their values from
// the YAML config. It will use the key REPLACE(UPPERCASE(flagname), '-', '_')
func SetFlagsFromYaml(fs *flag.FlagSet, rawYaml []byte) (err error) {
conf := make(map[string]string)
if err = yaml.Unmarshal(rawYaml, conf); err != nil {
return
}
alreadySet := map[string]struct{}{}
fs.Visit(func(f *flag.Flag) {
alreadySet[f.Name] = struct{}{}
})
errs := make([]error, 0)
fs.VisitAll(func(f *flag.Flag) {
if f.Name == "" {
return
}
if _, ok := alreadySet[f.Name]; ok {
return
}
tag := strings.Replace(strings.ToUpper(f.Name), "-", "_", -1)
val, ok := conf[tag]
if !ok {
return
}
if serr := fs.Set(f.Name, val); serr != nil {
errs = append(errs, fmt.Errorf("invalid value %q for %s: %v", val, tag, serr))
}
})
if len(errs) != 0 {
err = ErrorSlice(errs)
}
return
}
type ErrorSlice []error
func (e ErrorSlice) Error() string {
s := ""
for _, err := range e {
s += ", " + err.Error()
}
return "Errors: " + s
}

80
vendor/github.com/coreos/pkg/yamlutil/yaml_test.go generated vendored Normal file
View file

@ -0,0 +1,80 @@
package yamlutil
import (
"flag"
"testing"
)
func TestSetFlagsFromYaml(t *testing.T) {
config := "A: foo\nC: woof"
fs := flag.NewFlagSet("testing", flag.ExitOnError)
fs.String("a", "", "")
fs.String("b", "", "")
fs.String("c", "", "")
fs.Parse([]string{})
// flags should be settable using yaml vars
// and command-line flags
if err := fs.Set("b", "bar"); err != nil {
t.Fatal(err)
}
// command-line flags take precedence over the file
if err := fs.Set("c", "quack"); err != nil {
t.Fatal(err)
}
// first verify that flags are as expected before reading the file
for f, want := range map[string]string{
"a": "",
"b": "bar",
"c": "quack",
} {
if got := fs.Lookup(f).Value.String(); got != want {
t.Fatalf("flag %q=%q, want %q", f, got, want)
}
}
// now read the yaml and verify flags were updated as expected
err := SetFlagsFromYaml(fs, []byte(config))
if err != nil {
t.Errorf("err=%v, want nil", err)
}
for f, want := range map[string]string{
"a": "foo",
"b": "bar",
"c": "quack",
} {
if got := fs.Lookup(f).Value.String(); got != want {
t.Errorf("flag %q=%q, want %q", f, got, want)
}
}
}
func TestSetFlagsFromYamlBad(t *testing.T) {
// now verify that an error is propagated
fs := flag.NewFlagSet("testing", flag.ExitOnError)
fs.Int("x", 0, "")
badConf := "X: not_a_number"
if err := SetFlagsFromYaml(fs, []byte(badConf)); err == nil {
t.Errorf("got err=nil, flag x=%q, want err != nil", fs.Lookup("x").Value.String())
}
}
func TestSetFlagsFromYamlMultiError(t *testing.T) {
fs := flag.NewFlagSet("testing", flag.ExitOnError)
fs.Int("x", 0, "")
fs.Int("y", 0, "")
fs.Int("z", 0, "")
conf := "X: foo\nY: bar\nZ: 3"
err := SetFlagsFromYaml(fs, []byte(conf))
if err == nil {
t.Errorf("got err= nil, want err != nil")
}
es, ok := err.(ErrorSlice)
if !ok {
t.Errorf("Got ok=false want ok=true")
}
if len(es) != 2 {
t.Errorf("2 errors should be contained in the error, got %d errors", len(es))
}
}