14716: Moves keep-web legacy config loading test to lib/config.
[arvados.git] / lib / config / deprecated_test.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package config
6
7 import (
8         "flag"
9         "io/ioutil"
10         "os"
11         "time"
12
13         "git.curoverse.com/arvados.git/sdk/go/arvados"
14         check "gopkg.in/check.v1"
15 )
16
17 func (s *LoadSuite) TestDeprecatedNodeProfilesToServices(c *check.C) {
18         hostname, err := os.Hostname()
19         c.Assert(err, check.IsNil)
20         s.checkEquivalent(c, `
21 Clusters:
22  z1111:
23   NodeProfiles:
24    "*":
25     arvados-controller:
26      listen: ":9004"
27    `+hostname+`:
28     arvados-api-server:
29      listen: ":8000"
30    dispatch-host:
31     arvados-dispatch-cloud:
32      listen: ":9006"
33 `, `
34 Clusters:
35  z1111:
36   Services:
37    RailsAPI:
38     InternalURLs:
39      "http://localhost:8000": {}
40    Controller:
41     InternalURLs:
42      "http://localhost:9004": {}
43    DispatchCloud:
44     InternalURLs:
45      "http://dispatch-host:9006": {}
46   NodeProfiles:
47    "*":
48     arvados-controller:
49      listen: ":9004"
50    `+hostname+`:
51     arvados-api-server:
52      listen: ":8000"
53    dispatch-host:
54     arvados-dispatch-cloud:
55      listen: ":9006"
56 `)
57 }
58
59 func (s *LoadSuite) TestLegacyKeepWebConfig(c *check.C) {
60         content := []byte(`
61 {
62         "Client": {
63                 "Scheme": "",
64                 "APIHost": "example.com",
65                 "AuthToken": "abcdefg",
66         },
67         "Listen": ":80",
68         "AnonymousTokens": [
69                 "anonusertoken"
70         ],
71         "AttachmentOnlyHost": "download.example.com",
72         "TrustAllContent": true,
73         "Cache": {
74                 "TTL": "1m",
75                 "UUIDTTL": "1s",
76                 "MaxCollectionEntries": 42,
77                 "MaxCollectionBytes": 1234567890,
78                 "MaxPermissionEntries": 100,
79                 "MaxUUIDEntries": 100
80         },
81         "ManagementToken": "xyzzy"
82 }
83 `)
84         tmpfile, err := ioutil.TempFile("", "example")
85         if err != nil {
86                 c.Error(err)
87         }
88         defer os.Remove(tmpfile.Name())
89
90         if _, err := tmpfile.Write(content); err != nil {
91                 c.Error(err)
92         }
93         if err := tmpfile.Close(); err != nil {
94                 c.Error(err)
95         }
96         flags := flag.NewFlagSet("keep-web", flag.ExitOnError)
97         ldr := testLoader(c, "Clusters: {zzzzz: {}}", nil)
98         ldr.SetupFlags(flags)
99         args := ldr.MungeLegacyConfigArgs(ldr.Logger, []string{"-config", tmpfile.Name()}, "-legacy-keepweb-config")
100         flags.Parse(args)
101         cfg, err := ldr.Load()
102         if err != nil {
103                 c.Error(err)
104         }
105         c.Check(cfg, check.NotNil)
106         cluster, err := cfg.GetCluster("")
107         if err != nil {
108                 c.Error(err)
109         }
110         c.Check(cluster, check.NotNil)
111
112         c.Check(cluster.Services.Controller.ExternalURL, check.Equals, arvados.URL{Scheme: "https", Host: "example.com"})
113         c.Check(cluster.SystemRootToken, check.Equals, "abcdefg")
114
115         c.Check(cluster.Collections.WebDAVCache.TTL, check.Equals, arvados.Duration(60*time.Second))
116         c.Check(cluster.Collections.WebDAVCache.UUIDTTL, check.Equals, arvados.Duration(time.Second))
117         c.Check(cluster.Collections.WebDAVCache.MaxCollectionEntries, check.Equals, 42)
118         c.Check(cluster.Collections.WebDAVCache.MaxCollectionBytes, check.Equals, int64(1234567890))
119         c.Check(cluster.Collections.WebDAVCache.MaxPermissionEntries, check.Equals, 100)
120         c.Check(cluster.Collections.WebDAVCache.MaxUUIDEntries, check.Equals, 100)
121
122         c.Check(cluster.Services.WebDAVDownload.ExternalURL, check.Equals, arvados.URL{Host: "download.example.com"})
123         c.Check(cluster.Services.WebDAVDownload.InternalURLs[arvados.URL{Host: ":80"}], check.NotNil)
124         c.Check(cluster.Services.WebDAV.InternalURLs[arvados.URL{Host: ":80"}], check.NotNil)
125
126         c.Check(cluster.Collections.TrustAllContent, check.Equals, true)
127         c.Check(cluster.Users.AnonymousUserToken, check.Equals, "anonusertoken")
128         c.Check(cluster.ManagementToken, check.Equals, "xyzzy")
129 }