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

Unified Diff: environs/tools/storage_test.go

Issue 13725043: Upload tools uses simplestreams (Closed)
Patch Set: Upload tools uses simplestreams Created 11 years, 6 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
Index: environs/tools/storage_test.go
=== modified file 'environs/tools/storage_test.go'
--- environs/tools/storage_test.go 2013-09-12 14:16:48 +0000
+++ environs/tools/storage_test.go 2013-09-16 04:44:39 +0000
@@ -4,16 +4,6 @@
package tools_test
import (
- "bytes"
- "io"
- "io/ioutil"
- "net/http"
- "os"
- "os/exec"
- "path/filepath"
- "sort"
- "strings"
-
gc "launchpad.net/gocheck"
"launchpad.net/juju-core/environs"
@@ -122,96 +112,6 @@
s.assertReadList(c)
}
-func (s *StorageSuite) TestUpload(c *gc.C) {
- t, err := envtools.Upload(s.env.Storage(), nil)
- c.Assert(err, gc.IsNil)
- c.Assert(t.Version, gc.Equals, version.Current)
- c.Assert(t.URL, gc.Not(gc.Equals), "")
- dir := downloadTools(c, t)
- out, err := exec.Command(filepath.Join(dir, "jujud"), "version").CombinedOutput()
- c.Assert(err, gc.IsNil)
- c.Assert(string(out), gc.Equals, version.Current.String()+"\n")
-}
-
-func (s *StorageSuite) TestUploadFakeSeries(c *gc.C) {
- t, err := envtools.Upload(s.env.Storage(), nil, "sham", "fake")
- c.Assert(err, gc.IsNil)
- c.Assert(t.Version, gc.Equals, version.Current)
- expectRaw := downloadToolsRaw(c, t)
-
- list, err := envtools.ReadList(s.env.Storage(), version.Current.Major, version.Current.Minor)
- c.Assert(err, gc.IsNil)
- c.Assert(list, gc.HasLen, 3)
- expectSeries := []string{"fake", "sham", version.CurrentSeries()}
- sort.Strings(expectSeries)
- c.Assert(list.AllSeries(), gc.DeepEquals, expectSeries)
- for _, t := range list {
- c.Logf("checking %s", t.URL)
- c.Assert(t.Version.Number, gc.Equals, version.CurrentNumber())
- actualRaw := downloadToolsRaw(c, t)
- c.Assert(string(actualRaw), gc.Equals, string(expectRaw))
- }
-}
-
-func (s *StorageSuite) TestUploadAndForceVersion(c *gc.C) {
- // This test actually tests three things:
- // the writing of the FORCE-VERSION file;
- // the reading of the FORCE-VERSION file by the version package;
- // and the reading of the version from jujud.
- vers := version.Current
- vers.Patch++
- t, err := envtools.Upload(s.env.Storage(), &vers.Number)
- c.Assert(err, gc.IsNil)
- c.Assert(t.Version, gc.Equals, vers)
-}
-
-// Test that the upload procedure fails correctly
-// when the build process fails (because of a bad Go source
-// file in this case).
-func (s *StorageSuite) TestUploadBadBuild(c *gc.C) {
- gopath := c.MkDir()
- join := append([]string{gopath, "src"}, strings.Split("launchpad.net/juju-core/cmd/broken", "/")...)
- pkgdir := filepath.Join(join...)
- err := os.MkdirAll(pkgdir, 0777)
- c.Assert(err, gc.IsNil)
-
- err = ioutil.WriteFile(filepath.Join(pkgdir, "broken.go"), []byte("nope"), 0666)
- c.Assert(err, gc.IsNil)
-
- defer os.Setenv("GOPATH", os.Getenv("GOPATH"))
- os.Setenv("GOPATH", gopath)
-
- t, err := envtools.Upload(s.env.Storage(), nil)
- c.Assert(t, gc.IsNil)
- c.Assert(err, gc.ErrorMatches, `build command "go" failed: exit status 1; can't load package:(.|\n)*`)
-}
-
-// downloadTools downloads the supplied tools and extracts them into a
-// new directory.
-func downloadTools(c *gc.C, t *coretools.Tools) string {
- resp, err := http.Get(t.URL)
- c.Assert(err, gc.IsNil)
- defer resp.Body.Close()
- cmd := exec.Command("tar", "xz")
- cmd.Dir = c.MkDir()
- cmd.Stdin = resp.Body
- out, err := cmd.CombinedOutput()
- c.Assert(err, gc.IsNil, gc.Commentf(string(out)))
- return cmd.Dir
-}
-
-// downloadToolsRaw downloads the supplied tools and returns the raw bytes.
-func downloadToolsRaw(c *gc.C, t *coretools.Tools) []byte {
- resp, err := http.Get(t.URL)
- c.Assert(err, gc.IsNil)
- defer resp.Body.Close()
- c.Assert(resp.StatusCode, gc.Equals, http.StatusOK)
- var buf bytes.Buffer
- _, err = io.Copy(&buf, resp.Body)
- c.Assert(err, gc.IsNil)
- return buf.Bytes()
-}
-
var setenvTests = []struct {
set string
expect []string

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