forked from tsuru/tsuru
/
suite_test.go
50 lines (42 loc) · 1.09 KB
/
suite_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2014 tsuru authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package cmd
import (
"bytes"
"launchpad.net/gocheck"
"os"
"os/exec"
"testing"
)
func Test(t *testing.T) { gocheck.TestingT(t) }
type S struct {
stdin *os.File
recover []string
}
var _ = gocheck.Suite(&S{})
var manager *Manager
func (s *S) SetUpSuite(c *gocheck.C) {
targetFile := os.Getenv("HOME") + "/.tsuru_target"
_, err := os.Stat(targetFile)
if err == nil {
old := targetFile + ".old"
s.recover = []string{"mv", old, targetFile}
exec.Command("mv", targetFile, old).Run()
} else {
s.recover = []string{"rm", targetFile}
}
f, err := os.Create(targetFile)
c.Assert(err, gocheck.IsNil)
f.Write([]byte("http://localhost"))
f.Close()
}
func (s *S) TearDownSuite(c *gocheck.C) {
exec.Command(s.recover[0], s.recover[1:]...).Run()
}
func (s *S) SetUpTest(c *gocheck.C) {
var stdout, stderr bytes.Buffer
manager = NewManager("glb", "1.0", "", &stdout, &stderr, os.Stdin, nil)
var exiter recordingExiter
manager.e = &exiter
}