15003: Ensure all map[string]* have sample keys.
authorTom Clegg <tclegg@veritasgenetics.com>
Thu, 11 Jul 2019 19:51:09 +0000 (15:51 -0400)
committerTom Clegg <tclegg@veritasgenetics.com>
Thu, 11 Jul 2019 19:51:09 +0000 (15:51 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg@veritasgenetics.com>

lib/config/load_test.go
sdk/go/arvados/config.go

index 6b014476b6d9f31d6cf23197bcde6fac2fda0bc3..6e8b6208d5661e67911eb2c8190e608455471871 100644 (file)
@@ -9,6 +9,7 @@ import (
        "io"
        "os"
        "os/exec"
+       "reflect"
        "strings"
        "testing"
 
@@ -97,6 +98,42 @@ 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()
index 9c667610bcaaafc97ba276c4c25e632e6eb1c881..07be5d51b61856ef97739a47d47360e61f98ecee 100644 (file)
@@ -76,13 +76,17 @@ type Cluster struct {
                UnloggedAttributes []string
        }
        Collections struct {
-               BlobSigning           bool
-               BlobSigningKey        string
-               BlobSigningTTL        Duration
-               CollectionVersioning  bool
-               DefaultTrashLifetime  Duration
-               DefaultReplication    int
-               ManagedProperties     map[string]interface{}
+               BlobSigning          bool
+               BlobSigningKey       string
+               BlobSigningTTL       Duration
+               CollectionVersioning bool
+               DefaultTrashLifetime Duration
+               DefaultReplication   int
+               ManagedProperties    map[string]struct {
+                       Value     interface{}
+                       Function  string
+                       Protected bool
+               }
                PreserveVersionIfIdle Duration
                TrashSweepInterval    Duration
                TrustAllContent       bool