14388: Merge branch 'master' into 14388-overreplication
[arvados.git] / services / keep-balance / main_test.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package main
6
7 import (
8         "time"
9
10         "github.com/ghodss/yaml"
11         check "gopkg.in/check.v1"
12 )
13
14 var _ = check.Suite(&mainSuite{})
15
16 type mainSuite struct{}
17
18 func (s *mainSuite) TestExampleJSON(c *check.C) {
19         var config Config
20         c.Check(yaml.Unmarshal(exampleConfigFile, &config), check.IsNil)
21         c.Check(config.KeepServiceTypes, check.DeepEquals, []string{"disk"})
22         c.Check(config.Client.AuthToken, check.Equals, "xyzzy")
23         c.Check(time.Duration(config.RunPeriod), check.Equals, 600*time.Second)
24 }
25
26 func (s *mainSuite) TestConfigJSONWithKeepServiceList(c *check.C) {
27         var config Config
28         c.Check(yaml.Unmarshal([]byte(`{
29                     "Client": {
30                         "APIHost": "zzzzz.arvadosapi.com:443",
31                         "AuthToken": "xyzzy",
32                         "Insecure": false
33                     },
34                     "KeepServiceList": {
35                         "items": [
36                             {"uuid":"zzzzz-bi64l-abcdefghijklmno", "service_type":"disk", "service_host":"a.zzzzz.arvadosapi.com", "service_port":12345},
37                             {"uuid":"zzzzz-bi64l-bcdefghijklmnop", "service_type":"blob", "service_host":"b.zzzzz.arvadosapi.com", "service_port":12345}
38                         ]
39                     },
40                     "RunPeriod": "600s"
41                 }`), &config), check.IsNil)
42         c.Assert(len(config.KeepServiceList.Items), check.Equals, 2)
43         c.Check(config.KeepServiceList.Items[0].UUID, check.Equals, "zzzzz-bi64l-abcdefghijklmno")
44         c.Check(config.KeepServiceList.Items[0].ServicePort, check.Equals, 12345)
45         c.Check(config.Client.AuthToken, check.Equals, "xyzzy")
46 }