16328: Merge branch 'master' into 16328-keep-proxy-uses-config.yaml-to-find-keepstores
[arvados.git] / sdk / go / arvados / config_test.go
index 59c7432686c8fb3246c2aab007eb1f01b4d7fdd6..e4d26e03fd3f8101ad339f648b1efbaa56208437 100644 (file)
@@ -14,6 +14,16 @@ var _ = check.Suite(&ConfigSuite{})
 type ConfigSuite struct{}
 
 func (s *ConfigSuite) TestInstanceTypesAsArray(c *check.C) {
+       var cluster Cluster
+       yaml.Unmarshal([]byte(`
+API:
+  DisabledAPIs: [jobs.list]`), &cluster)
+       c.Check(len(cluster.API.DisabledAPIs), check.Equals, 1)
+       _, ok := cluster.API.DisabledAPIs["jobs.list"]
+       c.Check(ok, check.Equals, true)
+}
+
+func (s *ConfigSuite) TestStringSetAsArray(c *check.C) {
        var cluster Cluster
        yaml.Unmarshal([]byte("InstanceTypes:\n- Name: foo\n"), &cluster)
        c.Check(len(cluster.InstanceTypes), check.Equals, 1)
@@ -35,3 +45,29 @@ func (s *ConfigSuite) TestInstanceTypeSize(c *check.C) {
        c.Check(int64(it.Scratch), check.Equals, int64(4000000000))
        c.Check(int64(it.RAM), check.Equals, int64(4294967296))
 }
+
+func (s *ConfigSuite) TestInstanceTypeFixup(c *check.C) {
+       for _, confdata := range []string{
+               // Current format: map of entries
+               `{foo4: {IncludedScratch: 4GB}, foo8: {ProviderType: foo_8, Scratch: 8GB}}`,
+               // Legacy format: array of entries with key in "Name" field
+               `[{Name: foo4, IncludedScratch: 4GB}, {Name: foo8, ProviderType: foo_8, Scratch: 8GB}]`,
+       } {
+               c.Log(confdata)
+               var itm InstanceTypeMap
+               err := yaml.Unmarshal([]byte(confdata), &itm)
+               c.Check(err, check.IsNil)
+
+               c.Check(itm["foo4"].Name, check.Equals, "foo4")
+               c.Check(itm["foo4"].ProviderType, check.Equals, "foo4")
+               c.Check(itm["foo4"].Scratch, check.Equals, ByteSize(4000000000))
+               c.Check(itm["foo4"].AddedScratch, check.Equals, ByteSize(0))
+               c.Check(itm["foo4"].IncludedScratch, check.Equals, ByteSize(4000000000))
+
+               c.Check(itm["foo8"].Name, check.Equals, "foo8")
+               c.Check(itm["foo8"].ProviderType, check.Equals, "foo_8")
+               c.Check(itm["foo8"].Scratch, check.Equals, ByteSize(8000000000))
+               c.Check(itm["foo8"].AddedScratch, check.Equals, ByteSize(8000000000))
+               c.Check(itm["foo8"].IncludedScratch, check.Equals, ByteSize(0))
+       }
+}