Fix repositories.get_all_permissions, add tests. closes #3546
[arvados.git] / sdk / go / src / arvados.org / sdk / sdk_test.go
1 package sdk
2
3 import (
4         "fmt"
5         . "gopkg.in/check.v1"
6         "net/http"
7         "os"
8         "os/exec"
9         "strings"
10         "testing"
11 )
12
13 // Gocheck boilerplate
14 func Test(t *testing.T) {
15         TestingT(t)
16 }
17
18 var _ = Suite(&ServerRequiredSuite{})
19
20 // Tests that require the Keep server running
21 type ServerRequiredSuite struct{}
22
23 func pythonDir() string {
24         gopath := os.Getenv("GOPATH")
25         return fmt.Sprintf("%s/../python/tests", strings.Split(gopath, ":")[0])
26 }
27
28 func (s *ServerRequiredSuite) SetUpSuite(c *C) {
29         os.Chdir(pythonDir())
30         if err := exec.Command("python", "run_test_server.py", "start").Run(); err != nil {
31                 panic("'python run_test_server.py start' returned error")
32         }
33         if err := exec.Command("python", "run_test_server.py", "start_keep").Run(); err != nil {
34                 panic("'python run_test_server.py start_keep' returned error")
35         }
36 }
37
38 func (s *ServerRequiredSuite) TestMakeArvadosClient(c *C) {
39         os.Setenv("ARVADOS_API_HOST", "localhost:3001")
40         os.Setenv("ARVADOS_API_TOKEN", "4axaw8zxe0qm22wa6urpp5nskcne8z88cvbupv653y1njyi05h")
41         os.Setenv("ARVADOS_API_HOST_INSECURE", "")
42
43         kc, err := MakeArvadosClient()
44         c.Check(kc.ApiServer, Equals, "localhost:3001")
45         c.Check(kc.ApiToken, Equals, "4axaw8zxe0qm22wa6urpp5nskcne8z88cvbupv653y1njyi05h")
46         c.Check(kc.ApiInsecure, Equals, false)
47
48         os.Setenv("ARVADOS_API_HOST_INSECURE", "true")
49
50         kc, err = MakeArvadosClient()
51         c.Check(kc.ApiServer, Equals, "localhost:3001")
52         c.Check(kc.ApiToken, Equals, "4axaw8zxe0qm22wa6urpp5nskcne8z88cvbupv653y1njyi05h")
53         c.Check(kc.ApiInsecure, Equals, true)
54         c.Check(kc.Client.Transport.(*http.Transport).TLSClientConfig.InsecureSkipVerify, Equals, true)
55
56         c.Assert(err, Equals, nil)
57 }
58
59 func (s *ServerRequiredSuite) TestCreatePipelineTemplate(c *C) {
60         os.Setenv("ARVADOS_API_HOST", "localhost:3001")
61         os.Setenv("ARVADOS_API_TOKEN", "4axaw8zxe0qm22wa6urpp5nskcne8z88cvbupv653y1njyi05h")
62         os.Setenv("ARVADOS_API_HOST_INSECURE", "true")
63
64         arv, err := MakeArvadosClient()
65
66         getback := make(Dict)
67         err = arv.Create("pipeline_templates",
68                 Dict{"pipeline_template": Dict{
69                         "name": "tmp",
70                         "components": Dict{
71                                 "c1": map[string]string{"script": "script1"},
72                                 "c2": map[string]string{"script": "script2"}}}},
73                 &getback)
74         c.Assert(err, Equals, nil)
75         c.Assert(getback["name"], Equals, "tmp")
76         c.Assert(getback["components"].(map[string]interface{})["c2"].(map[string]interface{})["script"], Equals, "script2")
77
78         uuid := getback["uuid"].(string)
79         getback = make(Dict)
80         err = arv.Update("pipeline_templates", uuid,
81                 Dict{
82                         "pipeline_template": Dict{"name": "tmp2"}},
83                 &getback)
84         c.Assert(err, Equals, nil)
85         c.Assert(getback["name"], Equals, "tmp2")
86
87         c.Assert(getback["uuid"].(string), Equals, uuid)
88         getback = make(Dict)
89         err = arv.Delete("pipeline_templates", uuid, nil, &getback)
90         c.Assert(err, Equals, nil)
91         c.Assert(getback["name"], Equals, "tmp2")
92 }