15881: Move Google, SSO, and PAM configs into their own sections.
[arvados.git] / sdk / go / arvados / config_test.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: Apache-2.0
4
5 package arvados
6
7 import (
8         "github.com/ghodss/yaml"
9         check "gopkg.in/check.v1"
10 )
11
12 var _ = check.Suite(&ConfigSuite{})
13
14 type ConfigSuite struct{}
15
16 func (s *ConfigSuite) TestInstanceTypesAsArray(c *check.C) {
17         var cluster Cluster
18         yaml.Unmarshal([]byte(`
19 API:
20   DisabledAPIs: [jobs.list]`), &cluster)
21         c.Check(len(cluster.API.DisabledAPIs), check.Equals, 1)
22         _, ok := cluster.API.DisabledAPIs["jobs.list"]
23         c.Check(ok, check.Equals, true)
24 }
25
26 func (s *ConfigSuite) TestStringSetAsArray(c *check.C) {
27         var cluster Cluster
28         yaml.Unmarshal([]byte("InstanceTypes:\n- Name: foo\n"), &cluster)
29         c.Check(len(cluster.InstanceTypes), check.Equals, 1)
30         c.Check(cluster.InstanceTypes["foo"].Name, check.Equals, "foo")
31 }
32
33 func (s *ConfigSuite) TestInstanceTypesAsHash(c *check.C) {
34         var cluster Cluster
35         yaml.Unmarshal([]byte("InstanceTypes:\n  foo:\n    ProviderType: bar\n"), &cluster)
36         c.Check(len(cluster.InstanceTypes), check.Equals, 1)
37         c.Check(cluster.InstanceTypes["foo"].Name, check.Equals, "foo")
38         c.Check(cluster.InstanceTypes["foo"].ProviderType, check.Equals, "bar")
39 }
40
41 func (s *ConfigSuite) TestInstanceTypeSize(c *check.C) {
42         var it InstanceType
43         err := yaml.Unmarshal([]byte("Name: foo\nScratch: 4GB\nRAM: 4GiB\n"), &it)
44         c.Check(err, check.IsNil)
45         c.Check(int64(it.Scratch), check.Equals, int64(4000000000))
46         c.Check(int64(it.RAM), check.Equals, int64(4294967296))
47 }
48
49 func (s *ConfigSuite) TestInstanceTypeFixup(c *check.C) {
50         for _, confdata := range []string{
51                 // Current format: map of entries
52                 `{foo4: {IncludedScratch: 4GB}, foo8: {ProviderType: foo_8, Scratch: 8GB}}`,
53                 // Legacy format: array of entries with key in "Name" field
54                 `[{Name: foo4, IncludedScratch: 4GB}, {Name: foo8, ProviderType: foo_8, Scratch: 8GB}]`,
55         } {
56                 c.Log(confdata)
57                 var itm InstanceTypeMap
58                 err := yaml.Unmarshal([]byte(confdata), &itm)
59                 c.Check(err, check.IsNil)
60
61                 c.Check(itm["foo4"].Name, check.Equals, "foo4")
62                 c.Check(itm["foo4"].ProviderType, check.Equals, "foo4")
63                 c.Check(itm["foo4"].Scratch, check.Equals, ByteSize(4000000000))
64                 c.Check(itm["foo4"].AddedScratch, check.Equals, ByteSize(0))
65                 c.Check(itm["foo4"].IncludedScratch, check.Equals, ByteSize(4000000000))
66
67                 c.Check(itm["foo8"].Name, check.Equals, "foo8")
68                 c.Check(itm["foo8"].ProviderType, check.Equals, "foo_8")
69                 c.Check(itm["foo8"].Scratch, check.Equals, ByteSize(8000000000))
70                 c.Check(itm["foo8"].AddedScratch, check.Equals, ByteSize(8000000000))
71                 c.Check(itm["foo8"].IncludedScratch, check.Equals, ByteSize(0))
72         }
73 }