Merge branch '13647-load-old-config'
authorTom Clegg <tclegg@veritasgenetics.com>
Fri, 12 Jul 2019 19:05:06 +0000 (15:05 -0400)
committerTom Clegg <tclegg@veritasgenetics.com>
Fri, 12 Jul 2019 19:05:06 +0000 (15:05 -0400)
refs #13647

Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg@veritasgenetics.com>

1  2 
build/run-tests.sh
lib/config/cmd_test.go
lib/config/load.go
lib/config/load_test.go
sdk/go/arvados/config.go

Simple merge
Simple merge
index ee9cdd60f43e71cc70ec6b766ea2bb0a4c78b1dc,347875e8e99240c46a5ac27421178c02e4903d62..168c1aa22a8554ef649cc65463b10b8437970494
@@@ -156,15 -252,11 +252,15 @@@ func (ldr *Loader) logExtraKeys(expecte
                allowed[strings.ToLower(k)] = v
        }
        for k, vsupp := range supplied {
 +              if k == "SAMPLE" {
 +                      // entry will be dropped in removeSampleKeys anyway
 +                      continue
 +              }
                vexp, ok := allowed[strings.ToLower(k)]
 -              if !ok && expected["SAMPLE"] != nil {
 +              if expected["SAMPLE"] != nil {
                        vexp = expected["SAMPLE"]
                } else if !ok {
-                       log.Warnf("deprecated or unknown config entry: %s%s", prefix, k)
+                       ldr.Logger.Warnf("deprecated or unknown config entry: %s%s", prefix, k)
                        continue
                }
                if vsupp, ok := vsupp.(map[string]interface{}); !ok {
index 6e8b6208d5661e67911eb2c8190e608455471871,2d60f9e5b4cf340a64ee5be3b712f2d38a81f2f7..eea3efbd98f61c680ea6a21727aac74c4a3c8e83
@@@ -6,10 -6,11 +6,12 @@@ package confi
  
  import (
        "bytes"
+       "fmt"
        "io"
+       "io/ioutil"
        "os"
        "os/exec"
 +      "reflect"
        "strings"
        "testing"
  
@@@ -98,49 -199,13 +200,49 @@@ Clusters
        c.Check(logs, check.HasLen, 2)
  }
  
 +func (s *LoadSuite) checkSAMPLEKeys(c *check.C, path string, x interface{}) {
 +      v := reflect.Indirect(reflect.ValueOf(x))
 +      switch v.Kind() {
 +      case reflect.Map:
 +              var stringKeys, sampleKey bool
 +              iter := v.MapRange()
 +              for iter.Next() {
 +                      k := iter.Key()
 +                      if k.Kind() == reflect.String {
 +                              stringKeys = true
 +                              if k.String() == "SAMPLE" || k.String() == "xxxxx" {
 +                                      sampleKey = true
 +                                      s.checkSAMPLEKeys(c, path+"."+k.String(), iter.Value().Interface())
 +                              }
 +                      }
 +              }
 +              if stringKeys && !sampleKey {
 +                      c.Errorf("%s is a map with string keys (type %T) but config.default.yml has no SAMPLE key", path, x)
 +              }
 +              return
 +      case reflect.Struct:
 +              for i := 0; i < v.NumField(); i++ {
 +                      val := v.Field(i)
 +                      if val.CanInterface() {
 +                              s.checkSAMPLEKeys(c, path+"."+v.Type().Field(i).Name, val.Interface())
 +                      }
 +              }
 +      }
 +}
 +
 +func (s *LoadSuite) TestDefaultConfigHasAllSAMPLEKeys(c *check.C) {
 +      cfg, err := Load(bytes.NewBuffer(DefaultYAML), ctxlog.TestLogger(c))
 +      c.Assert(err, check.IsNil)
 +      s.checkSAMPLEKeys(c, "", cfg)
 +}
 +
  func (s *LoadSuite) TestNoUnrecognizedKeysInDefaultConfig(c *check.C) {
        var logbuf bytes.Buffer
-       logger := logrus.New()
-       logger.Out = &logbuf
        var supplied map[string]interface{}
        yaml.Unmarshal(DefaultYAML, &supplied)
-       cfg, err := Load(bytes.NewBuffer(DefaultYAML), logger)
+       loader := testLoader(c, string(DefaultYAML), &logbuf)
+       cfg, err := loader.Load()
        c.Assert(err, check.IsNil)
        var loaded map[string]interface{}
        buf, err := yaml.Marshal(cfg)
Simple merge