Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
| ... | ... |
@@ -111,3 +111,70 @@ func TestGetVersion(t *testing.T) {
|
| 111 | 111 |
t.Errorf("Expected Content-Type %s, %s found", expected, result)
|
| 112 | 112 |
} |
| 113 | 113 |
} |
| 114 |
+ |
|
| 115 |
+func TestGetInfo(t *testing.T) {
|
|
| 116 |
+ tmp, err := utils.TestDirectory("")
|
|
| 117 |
+ if err != nil {
|
|
| 118 |
+ t.Fatal(err) |
|
| 119 |
+ } |
|
| 120 |
+ defer os.RemoveAll(tmp) |
|
| 121 |
+ eng, err := engine.New(tmp) |
|
| 122 |
+ if err != nil {
|
|
| 123 |
+ t.Fatal(err) |
|
| 124 |
+ } |
|
| 125 |
+ |
|
| 126 |
+ var called bool |
|
| 127 |
+ eng.Register("info", func(job *engine.Job) engine.Status {
|
|
| 128 |
+ called = true |
|
| 129 |
+ v := &engine.Env{}
|
|
| 130 |
+ v.SetInt("Containers", 1)
|
|
| 131 |
+ v.SetInt("Images", 42000)
|
|
| 132 |
+ if _, err := v.WriteTo(job.Stdout); err != nil {
|
|
| 133 |
+ return job.Error(err) |
|
| 134 |
+ } |
|
| 135 |
+ return engine.StatusOK |
|
| 136 |
+ }) |
|
| 137 |
+ |
|
| 138 |
+ r := httptest.NewRecorder() |
|
| 139 |
+ req, err := http.NewRequest("GET", "/info", nil)
|
|
| 140 |
+ if err != nil {
|
|
| 141 |
+ t.Fatal(err) |
|
| 142 |
+ } |
|
| 143 |
+ // FIXME getting the version should require an actual running Server |
|
| 144 |
+ if err := ServeRequest(eng, api.APIVERSION, r, req); err != nil {
|
|
| 145 |
+ t.Fatal(err) |
|
| 146 |
+ } |
|
| 147 |
+ if !called {
|
|
| 148 |
+ t.Fatalf("handler was not called")
|
|
| 149 |
+ } |
|
| 150 |
+ |
|
| 151 |
+ out := engine.NewOutput() |
|
| 152 |
+ i, err := out.AddEnv() |
|
| 153 |
+ if err != nil {
|
|
| 154 |
+ t.Fatal(err) |
|
| 155 |
+ } |
|
| 156 |
+ if _, err := io.Copy(out, r.Body); err != nil {
|
|
| 157 |
+ t.Fatal(err) |
|
| 158 |
+ } |
|
| 159 |
+ out.Close() |
|
| 160 |
+ {
|
|
| 161 |
+ expected := 42000 |
|
| 162 |
+ result := i.GetInt("Images")
|
|
| 163 |
+ if expected != result {
|
|
| 164 |
+ t.Fatalf("%#v\n", result)
|
|
| 165 |
+ } |
|
| 166 |
+ } |
|
| 167 |
+ {
|
|
| 168 |
+ expected := 1 |
|
| 169 |
+ result := i.GetInt("Containers")
|
|
| 170 |
+ if expected != result {
|
|
| 171 |
+ t.Fatalf("%#v\n", result)
|
|
| 172 |
+ } |
|
| 173 |
+ } |
|
| 174 |
+ {
|
|
| 175 |
+ expected := "application/json" |
|
| 176 |
+ if result := r.HeaderMap.Get("Content-Type"); result != expected {
|
|
| 177 |
+ t.Fatalf("%#v\n", result)
|
|
| 178 |
+ } |
|
| 179 |
+ } |
|
| 180 |
+} |
| ... | ... |
@@ -24,47 +24,6 @@ import ( |
| 24 | 24 |
"github.com/dotcloud/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar" |
| 25 | 25 |
) |
| 26 | 26 |
|
| 27 |
-func TestGetInfo(t *testing.T) {
|
|
| 28 |
- eng := NewTestEngine(t) |
|
| 29 |
- defer mkRuntimeFromEngine(eng, t).Nuke() |
|
| 30 |
- |
|
| 31 |
- job := eng.Job("images")
|
|
| 32 |
- initialImages, err := job.Stdout.AddListTable() |
|
| 33 |
- if err != nil {
|
|
| 34 |
- t.Fatal(err) |
|
| 35 |
- } |
|
| 36 |
- if err := job.Run(); err != nil {
|
|
| 37 |
- t.Fatal(err) |
|
| 38 |
- } |
|
| 39 |
- req, err := http.NewRequest("GET", "/info", nil)
|
|
| 40 |
- if err != nil {
|
|
| 41 |
- t.Fatal(err) |
|
| 42 |
- } |
|
| 43 |
- r := httptest.NewRecorder() |
|
| 44 |
- |
|
| 45 |
- if err := server.ServeRequest(eng, api.APIVERSION, r, req); err != nil {
|
|
| 46 |
- t.Fatal(err) |
|
| 47 |
- } |
|
| 48 |
- assertHttpNotError(r, t) |
|
| 49 |
- |
|
| 50 |
- out := engine.NewOutput() |
|
| 51 |
- i, err := out.AddEnv() |
|
| 52 |
- if err != nil {
|
|
| 53 |
- t.Fatal(err) |
|
| 54 |
- } |
|
| 55 |
- if _, err := io.Copy(out, r.Body); err != nil {
|
|
| 56 |
- t.Fatal(err) |
|
| 57 |
- } |
|
| 58 |
- out.Close() |
|
| 59 |
- if images := i.GetInt("Images"); images != initialImages.Len() {
|
|
| 60 |
- t.Errorf("Expected images: %d, %d found", initialImages.Len(), images)
|
|
| 61 |
- } |
|
| 62 |
- expected := "application/json" |
|
| 63 |
- if result := r.HeaderMap.Get("Content-Type"); result != expected {
|
|
| 64 |
- t.Errorf("Expected Content-Type %s, %s found", expected, result)
|
|
| 65 |
- } |
|
| 66 |
-} |
|
| 67 |
- |
|
| 68 | 27 |
func TestGetEvents(t *testing.T) {
|
| 69 | 28 |
eng := NewTestEngine(t) |
| 70 | 29 |
srv := mkServerFromEngine(eng, t) |