18346: Do not forward locally-issued token to own login cluster.
[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         "encoding/json"
9
10         "github.com/ghodss/yaml"
11         check "gopkg.in/check.v1"
12 )
13
14 var _ = check.Suite(&ConfigSuite{})
15
16 type ConfigSuite struct{}
17
18 func (s *ConfigSuite) TestInstanceTypesAsArray(c *check.C) {
19         var cluster Cluster
20         yaml.Unmarshal([]byte(`
21 API:
22   DisabledAPIs: [jobs.list]`), &cluster)
23         c.Check(len(cluster.API.DisabledAPIs), check.Equals, 1)
24         _, ok := cluster.API.DisabledAPIs["jobs.list"]
25         c.Check(ok, check.Equals, true)
26 }
27
28 func (s *ConfigSuite) TestStringSetAsArray(c *check.C) {
29         var cluster Cluster
30         yaml.Unmarshal([]byte("InstanceTypes:\n- Name: foo\n"), &cluster)
31         c.Check(len(cluster.InstanceTypes), check.Equals, 1)
32         c.Check(cluster.InstanceTypes["foo"].Name, check.Equals, "foo")
33 }
34
35 func (s *ConfigSuite) TestInstanceTypesAsHash(c *check.C) {
36         var cluster Cluster
37         yaml.Unmarshal([]byte("InstanceTypes:\n  foo:\n    ProviderType: bar\n"), &cluster)
38         c.Check(len(cluster.InstanceTypes), check.Equals, 1)
39         c.Check(cluster.InstanceTypes["foo"].Name, check.Equals, "foo")
40         c.Check(cluster.InstanceTypes["foo"].ProviderType, check.Equals, "bar")
41 }
42
43 func (s *ConfigSuite) TestInstanceTypeSize(c *check.C) {
44         var it InstanceType
45         err := yaml.Unmarshal([]byte("Name: foo\nScratch: 4GB\nRAM: 4GiB\n"), &it)
46         c.Check(err, check.IsNil)
47         c.Check(int64(it.Scratch), check.Equals, int64(4000000000))
48         c.Check(int64(it.RAM), check.Equals, int64(4294967296))
49 }
50
51 func (s *ConfigSuite) TestInstanceTypeFixup(c *check.C) {
52         for _, confdata := range []string{
53                 // Current format: map of entries
54                 `{foo4: {IncludedScratch: 4GB}, foo8: {ProviderType: foo_8, Scratch: 8GB}}`,
55                 // Legacy format: array of entries with key in "Name" field
56                 `[{Name: foo4, IncludedScratch: 4GB}, {Name: foo8, ProviderType: foo_8, Scratch: 8GB}]`,
57         } {
58                 c.Log(confdata)
59                 var itm InstanceTypeMap
60                 err := yaml.Unmarshal([]byte(confdata), &itm)
61                 c.Check(err, check.IsNil)
62
63                 c.Check(itm["foo4"].Name, check.Equals, "foo4")
64                 c.Check(itm["foo4"].ProviderType, check.Equals, "foo4")
65                 c.Check(itm["foo4"].Scratch, check.Equals, ByteSize(4000000000))
66                 c.Check(itm["foo4"].AddedScratch, check.Equals, ByteSize(0))
67                 c.Check(itm["foo4"].IncludedScratch, check.Equals, ByteSize(4000000000))
68
69                 c.Check(itm["foo8"].Name, check.Equals, "foo8")
70                 c.Check(itm["foo8"].ProviderType, check.Equals, "foo_8")
71                 c.Check(itm["foo8"].Scratch, check.Equals, ByteSize(8000000000))
72                 c.Check(itm["foo8"].AddedScratch, check.Equals, ByteSize(8000000000))
73                 c.Check(itm["foo8"].IncludedScratch, check.Equals, ByteSize(0))
74         }
75 }
76
77 func (s *ConfigSuite) TestURLTrailingSlash(c *check.C) {
78         var a, b map[URL]bool
79         json.Unmarshal([]byte(`{"https://foo.example": true}`), &a)
80         json.Unmarshal([]byte(`{"https://foo.example/": true}`), &b)
81         c.Check(a, check.DeepEquals, b)
82 }