Example #1
0
func TestCMDExtractor(t *testing.T) {
	api := httpmock.NewServeReplay(t).Add(httpmock.PathHandler(t,
		"GET /version",
		200, `{ "ApiVersion": "1.20" }`,
	)).Add(httpmock.PathHandler(t,
		"GET /images/remind101:acme-inc/json",
		200, `{ "Config": { "Cmd": ["/go/bin/app","server"] } }`,
	))

	c, s := newTestDockerClient(t, api)
	defer s.Close()

	e := cmdExtractor{
		client: c,
	}

	got, err := e.Extract(nil, image.Image{
		Tag:        "acme-inc",
		Repository: "remind101",
	}, nil)
	if err != nil {
		t.Fatal(err)
	}

	want := []byte(`web:
  command:
  - /go/bin/app
  - server
`)

	if !reflect.DeepEqual(got, want) {
		t.Errorf("Extract() => %q; want %q", got, want)
	}
}
Example #2
0
func TestCMDExtractor(t *testing.T) {
	api := httpmock.NewServeReplay(t).Add(httpmock.PathHandler(t,
		"GET /images/remind101:acme-inc/json",
		200, `{ "Config": { "Cmd": ["/go/bin/app","server"] } }`,
	))

	c, s := newTestDockerClient(t, api)
	defer s.Close()

	e := CMDExtractor{
		client: c,
	}

	got, err := e.Extract(image.Image{
		Tag:        "acme-inc",
		Repository: "remind101",
	})
	if err != nil {
		t.Fatal(err)
	}

	want := Procfile{
		"web": "/go/bin/app server",
	}

	if !reflect.DeepEqual(got, want) {
		t.Errorf("Extract() => %q; want %q", got, want)
	}
}
Example #3
0
func TestProcfileFallbackExtractor(t *testing.T) {
	api := httpmock.NewServeReplay(t).Add(httpmock.PathHandler(t,
		"GET /version",
		200, `{ "ApiVersion": "1.20" }`,
	)).Add(httpmock.PathHandler(t,
		"POST /containers/create",
		200, `{ "ID": "abc" }`,
	)).Add(httpmock.PathHandler(t,
		"GET /containers/abc/json",
		200, `{}`,
	)).Add(httpmock.PathHandler(t,
		"POST /containers/abc/copy",
		404, ``,
	)).Add(httpmock.PathHandler(t,
		"DELETE /containers/abc",
		200, `{}`,
	)).Add(httpmock.PathHandler(t,
		"GET /images/remind101:acme-inc/json",
		200, `{ "Config": { "Cmd": ["/go/bin/app","server"] } }`,
	))

	c, s := newTestDockerClient(t, api)
	defer s.Close()

	e := multiExtractor(
		newFileExtractor(c),
		newCMDExtractor(c),
	)

	got, err := e.Extract(nil, image.Image{
		Tag:        "acme-inc",
		Repository: "remind101",
	}, nil)
	if err != nil {
		t.Fatal(err)
	}

	want := []byte(`web:
  command:
  - /go/bin/app
  - server
`)

	if !reflect.DeepEqual(got, want) {
		t.Errorf("Extract() => %q; want %q", got, want)
	}

}
Example #4
0
func TestProcfileFallbackExtractor(t *testing.T) {
	api := httpmock.NewServeReplay(t).Add(httpmock.PathHandler(t,
		"POST /containers/create",
		200, `{ "ID": "abc" }`,
	)).Add(httpmock.PathHandler(t,
		"GET /containers/abc/json",
		200, `{}`,
	)).Add(httpmock.PathHandler(t,
		"POST /containers/abc/copy",
		404, ``,
	)).Add(httpmock.PathHandler(t,
		"DELETE /containers/abc",
		200, `{}`,
	)).Add(httpmock.PathHandler(t,
		"GET /images/remind101:acme-inc/json",
		200, `{ "Config": { "Cmd": ["/go/bin/app","server"] } }`,
	))

	c, s := newTestDockerClient(t, api)
	defer s.Close()

	e := newProcfileFallbackExtractor(c)

	got, err := e.Extract(image.Image{
		Tag:        "acme-inc",
		Repository: "remind101",
	})
	if err != nil {
		t.Fatal(err)
	}

	want := CommandMap{
		ProcessType("web"): Command("/go/bin/app server"),
	}

	if !reflect.DeepEqual(got, want) {
		t.Errorf("Extract() => %q; want %q", got, want)
	}

}
Example #5
0
func TestProcfileExtractor_Docker12(t *testing.T) {
	api := httpmock.NewServeReplay(t).Add(httpmock.PathHandler(t,
		"GET /version",
		200, `{ "ApiVersion": "1.24" }`,
	)).Add(httpmock.PathHandler(t,
		"POST /containers/create",
		200, `{ "ID": "abc" }`,
	)).Add(httpmock.PathHandler(t,
		"GET /containers/abc/json",
		200, `{}`,
	)).Add(httpmock.PathHandler(t,
		"GET /containers/abc/archive",
		200, tarProcfile(t),
	)).Add(httpmock.PathHandler(t,
		"DELETE /containers/abc",
		200, `{}`,
	))

	c, s := newTestDockerClient(t, api)
	defer s.Close()

	e := fileExtractor{
		client: c,
	}

	got, err := e.Extract(nil, image.Image{
		Tag:        "acme-inc",
		Repository: "remind101",
	}, nil)
	if err != nil {
		t.Fatal(err)
	}

	want := []byte(`web: rails server`)

	if !reflect.DeepEqual(got, want) {
		t.Errorf("Extract() => %q; want %q", got, want)
	}
}
Example #6
0
func TestProcfileExtractor(t *testing.T) {
	api := httpmock.NewServeReplay(t).Add(httpmock.PathHandler(t,
		"POST /containers/create",
		200, `{ "ID": "abc" }`,
	)).Add(httpmock.PathHandler(t,
		"GET /containers/abc/json",
		200, `{}`,
	)).Add(httpmock.PathHandler(t,
		"POST /containers/abc/copy",
		200, tarProcfile(t),
	)).Add(httpmock.PathHandler(t,
		"DELETE /containers/abc",
		200, `{}`,
	))

	c, s := newTestDockerClient(t, api)
	defer s.Close()

	e := procfileExtractor{
		client: c,
	}

	got, err := e.Extract(image.Image{
		Tag:        "acme-inc",
		Repository: "remind101",
	})
	if err != nil {
		t.Fatal(err)
	}

	want := CommandMap{
		ProcessType("web"): Command("rails server"),
	}

	if !reflect.DeepEqual(got, want) {
		t.Errorf("Extract() => %q; want %q", got, want)
	}

}