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

Unified Diff: worker/apiuniter/tools_test.go

Issue 13512049: worker/apiuniter: Clone uniter, fix imports (Closed)
Patch Set: Created 11 years, 7 months ago
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « worker/apiuniter/tools.go ('k') | worker/apiuniter/uniter.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: worker/apiuniter/tools_test.go
=== added file 'worker/apiuniter/tools_test.go'
--- worker/apiuniter/tools_test.go 1970-01-01 00:00:00 +0000
+++ worker/apiuniter/tools_test.go 2013-09-10 12:21:02 +0000
@@ -0,0 +1,69 @@
+// Copyright 2012, 2013 Canonical Ltd.
+// Licensed under the AGPLv3, see LICENCE file for details.
+
+package apiuniter_test
+
+import (
+ "io/ioutil"
+ "os"
+ "path/filepath"
+ "time"
+
+ gc "launchpad.net/gocheck"
+
+ "launchpad.net/juju-core/agent/tools"
+ "launchpad.net/juju-core/version"
+ "launchpad.net/juju-core/worker/apiuniter"
+ "launchpad.net/juju-core/worker/apiuniter/jujuc"
+)
+
+type ToolsSuite struct {
+ dataDir, toolsDir string
+}
+
+var _ = gc.Suite(&ToolsSuite{})
+
+func (s *ToolsSuite) SetUpTest(c *gc.C) {
+ s.dataDir = c.MkDir()
+ s.toolsDir = tools.SharedToolsDir(s.dataDir, version.Current)
+ err := os.MkdirAll(s.toolsDir, 0755)
+ c.Assert(err, gc.IsNil)
+ err = os.Symlink(s.toolsDir, tools.ToolsDir(s.dataDir, "unit-u-123"))
+ c.Assert(err, gc.IsNil)
+}
+
+func (s *ToolsSuite) TestEnsureJujucSymlinks(c *gc.C) {
+ jujudPath := filepath.Join(s.toolsDir, "jujud")
+ err := ioutil.WriteFile(jujudPath, []byte("assume sane"), 0755)
+ c.Assert(err, gc.IsNil)
+
+ assertLink := func(path string) time.Time {
+ target, err := os.Readlink(path)
+ c.Assert(err, gc.IsNil)
+ c.Assert(target, gc.Equals, "./jujud")
+ fi, err := os.Lstat(path)
+ c.Assert(err, gc.IsNil)
+ return fi.ModTime()
+ }
+
+ // Check that EnsureJujucSymlinks writes appropriate symlinks.
+ err = apiuniter.EnsureJujucSymlinks(s.toolsDir)
+ c.Assert(err, gc.IsNil)
+ mtimes := map[string]time.Time{}
+ for _, name := range jujuc.CommandNames() {
+ tool := filepath.Join(s.toolsDir, name)
+ mtimes[tool] = assertLink(tool)
+ }
+
+ // Check that EnsureJujucSymlinks doesn't overwrite things that don't need to be.
+ err = apiuniter.EnsureJujucSymlinks(s.toolsDir)
+ c.Assert(err, gc.IsNil)
+ for tool, mtime := range mtimes {
+ c.Assert(assertLink(tool), gc.Equals, mtime)
+ }
+}
+
+func (s *ToolsSuite) TestEnsureJujucSymlinksBadDir(c *gc.C) {
+ err := apiuniter.EnsureJujucSymlinks(filepath.Join(c.MkDir(), "noexist"))
+ c.Assert(err, gc.ErrorMatches, "cannot initialize hook commands in .*: no such file or directory")
+}
« 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