forked from tsuru/tsuru
/
suite_test.go
55 lines (45 loc) · 1.17 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
51
52
53
54
55
// Copyright 2012 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 tsuru
import (
"bytes"
"errors"
"github.com/globocom/tsuru/cmd"
"io/ioutil"
. "launchpad.net/gocheck"
"net/http"
"os"
"testing"
)
type S struct{}
type transport struct {
msg string
status int
}
type conditionalTransport struct {
transport
condFunc func(*http.Request) bool
}
var _ = Suite(&S{})
var manager *cmd.Manager
func Test(t *testing.T) { TestingT(t) }
func (t *transport) RoundTrip(req *http.Request) (resp *http.Response, err error) {
resp = &http.Response{
Body: ioutil.NopCloser(bytes.NewBufferString(t.msg)),
StatusCode: t.status,
}
return resp, nil
}
func (t *conditionalTransport) RoundTrip(req *http.Request) (*http.Response, error) {
if !t.condFunc(req) {
return &http.Response{Body: nil, StatusCode: 500}, errors.New("condition failed")
}
return t.transport.RoundTrip(req)
}
func (s *S) SetUpTest(c *C) {
var stdout, stderr bytes.Buffer
manager = cmd.NewManager("glb", "0.x", "Foo-Tsuru", &stdout, &stderr, os.Stdin)
AppName = new(string)
AssumeYes = new(bool)
}