Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2)

Side by Side Diff: worker/apiuniter/tools_test.go

Issue 13512049: worker/apiuniter: Clone uniter, fix imports (Closed)
Patch Set: Created 11 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « worker/apiuniter/tools.go ('k') | worker/apiuniter/uniter.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2012, 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details.
3
4 package apiuniter_test
5
6 import (
7 "io/ioutil"
8 "os"
9 "path/filepath"
10 "time"
11
12 gc "launchpad.net/gocheck"
13
14 "launchpad.net/juju-core/agent/tools"
15 "launchpad.net/juju-core/version"
16 "launchpad.net/juju-core/worker/apiuniter"
17 "launchpad.net/juju-core/worker/apiuniter/jujuc"
18 )
19
20 type ToolsSuite struct {
21 dataDir, toolsDir string
22 }
23
24 var _ = gc.Suite(&ToolsSuite{})
25
26 func (s *ToolsSuite) SetUpTest(c *gc.C) {
27 s.dataDir = c.MkDir()
28 s.toolsDir = tools.SharedToolsDir(s.dataDir, version.Current)
29 err := os.MkdirAll(s.toolsDir, 0755)
30 c.Assert(err, gc.IsNil)
31 err = os.Symlink(s.toolsDir, tools.ToolsDir(s.dataDir, "unit-u-123"))
32 c.Assert(err, gc.IsNil)
33 }
34
35 func (s *ToolsSuite) TestEnsureJujucSymlinks(c *gc.C) {
36 jujudPath := filepath.Join(s.toolsDir, "jujud")
37 err := ioutil.WriteFile(jujudPath, []byte("assume sane"), 0755)
38 c.Assert(err, gc.IsNil)
39
40 assertLink := func(path string) time.Time {
41 target, err := os.Readlink(path)
42 c.Assert(err, gc.IsNil)
43 c.Assert(target, gc.Equals, "./jujud")
44 fi, err := os.Lstat(path)
45 c.Assert(err, gc.IsNil)
46 return fi.ModTime()
47 }
48
49 // Check that EnsureJujucSymlinks writes appropriate symlinks.
50 err = apiuniter.EnsureJujucSymlinks(s.toolsDir)
51 c.Assert(err, gc.IsNil)
52 mtimes := map[string]time.Time{}
53 for _, name := range jujuc.CommandNames() {
54 tool := filepath.Join(s.toolsDir, name)
55 mtimes[tool] = assertLink(tool)
56 }
57
58 // Check that EnsureJujucSymlinks doesn't overwrite things that don't ne ed to be.
59 err = apiuniter.EnsureJujucSymlinks(s.toolsDir)
60 c.Assert(err, gc.IsNil)
61 for tool, mtime := range mtimes {
62 c.Assert(assertLink(tool), gc.Equals, mtime)
63 }
64 }
65
66 func (s *ToolsSuite) TestEnsureJujucSymlinksBadDir(c *gc.C) {
67 err := apiuniter.EnsureJujucSymlinks(filepath.Join(c.MkDir(), "noexist") )
68 c.Assert(err, gc.ErrorMatches, "cannot initialize hook commands in .*: n o such file or directory")
69 }
OLDNEW
« no previous file with comments | « worker/apiuniter/tools.go ('k') | worker/apiuniter/uniter.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b