Ejemplo n.º 1
0
func TestRackUpdateStable(t *testing.T) {
	versions, err := version.All()
	require.Nil(t, err)

	stable, err := versions.Resolve("stable")
	require.Nil(t, err)

	ts := testServer(t,
		test.Http{Method: "PUT", Body: fmt.Sprintf("version=%s", stable.Version), Path: "/system", Code: 200, Response: client.System{
			Name:    "mysystem",
			Version: "ver",
			Count:   1,
			Type:    "type",
		}},
	)

	defer ts.Close()

	test.Runs(t,
		test.ExecRun{
			Command: "convox rack update",
			Exit:    0,
			Stdout:  "Name     mysystem\nStatus   \nVersion  ver\nCount    1\nType     type\n",
		},
	)
}
Ejemplo n.º 2
0
func assertFixture(t *testing.T, name string, primary string) {
	data, err := ioutil.ReadFile(fmt.Sprintf("fixtures/%s.yml", name))
	require.Nil(t, err)

	app := &App{
		Name: "httpd",
		Tags: map[string]string{
			"Name":   "httpd",
			"Type":   "app",
			"System": "convox",
			"Rack":   "convox-test",
		},
	}
	manifest, err := LoadManifest(string(data), app)

	if err != nil {
		fmt.Printf("ERROR: %+v\n", err)
	}

	require.Nil(t, err)

	formation, err := manifest.Formation()

	if err != nil {
		fmt.Printf("ERROR: %+v\n", err)
	}

	require.Nil(t, err)

	data, err = ioutil.ReadFile(fmt.Sprintf("fixtures/%s.json", name))
	require.Nil(t, err)

	Diff(t, name, string(data), formation)
}
Ejemplo n.º 3
0
func assertFixture(t *testing.T, name string, primary string) {
	data, err := ioutil.ReadFile(fmt.Sprintf("fixtures/%s.yml", name))
	require.Nil(t, err)

	manifest, err := LoadManifest(string(data))
	require.Nil(t, err)

	for i, _ := range manifest {
		if manifest[i].Name == primary {
			manifest[i].primary = true
		}
	}

	formation, err := manifest.Formation()
	require.Nil(t, err)

	data, err = ioutil.ReadFile(fmt.Sprintf("fixtures/%s.json", name))
	require.Nil(t, err)

	diff1 := strings.Split(strings.TrimSpace(string(data)), "\n")
	diff2 := strings.Split(strings.TrimSpace(formation), "\n")

	diff := difflib.Diff(diff1, diff2)
	diffs := []string{}

	// bigger than max
	prev := 1000000

	for l, d := range diff {
		switch d.Delta {
		case difflib.LeftOnly:
			if (l - prev) > 1 {
				diffs = append(diffs, "")
			}
			diffs = append(diffs, fmt.Sprintf("%04d - %s", l, d.Payload))
			prev = l
		case difflib.RightOnly:
			if (l - prev) > 1 {
				diffs = append(diffs, "")
			}
			diffs = append(diffs, fmt.Sprintf("%04d + %s", l, d.Payload))
			prev = l
		}
	}

	if len(diffs) > 0 {
		t.Errorf("Unexpected results for %s:\n%s", name, strings.Join(diffs, "\n"))
	}
}
Ejemplo n.º 4
0
func TestManifestRandomPorts(t *testing.T) {
	manifest, err := LoadManifest("web:\n  ports:\n  - 80:3000\n  - 3001")

	require.Nil(t, err)

	// kinda hacky but just making sure we're not in sequence here
	assert.NotEqual(t, 1, (manifest[0].randoms["3001"] - manifest[0].randoms["80:3000"]))
}
Ejemplo n.º 5
0
func assertFixture(t *testing.T, name string, primary string) {
	data, err := ioutil.ReadFile(fmt.Sprintf("fixtures/%s.yml", name))
	require.Nil(t, err)

	manifest, err := LoadManifest(string(data))
	require.Nil(t, err)

	for i, _ := range manifest {
		if manifest[i].Name == primary {
			manifest[i].primary = true
		}
	}

	formation, err := manifest.Formation()
	require.Nil(t, err)

	data, err = ioutil.ReadFile(fmt.Sprintf("fixtures/%s.json", name))
	require.Nil(t, err)

	Diff(t, name, string(data), formation)
}
Ejemplo n.º 6
0
func TestLinks(t *testing.T) {
	t.Skip("skipping until we have a strategy for stubbing out the registry dependency")

	os.Setenv("RACK", "convox-test")
	os.Setenv("CLUSTER", "convox-test")

	resp, err := ioutil.ReadFile("fixtures/get-app-template-response.xml")
	require.Nil(t, err)

	fixData, err := ioutil.ReadFile("fixtures/web_redis.json")
	require.Nil(t, err)

	yamlData, err := ioutil.ReadFile("fixtures/web_redis.yml")
	require.Nil(t, err)

	getAppTemplateCycle := test.GetAppTemplateCycle("web")
	getAppTemplateCycle.Response.Body = string(resp)
	stubAws := test.StubAws(
		getAppTemplateCycle,
		test.DescribeAppStackCycle("web"),
	)
	defer stubAws.Close()

	release := &Release{
		Id:       "DEADBEEF",
		App:      "web",
		Build:    "DEADBEEF",
		Env:      "",
		Manifest: string(yamlData),
	}

	ManifestRandomPorts = false
	formation, err := release.Formation()
	require.Nil(t, err)
	ManifestRandomPorts = true

	Diff(t, "web_redis", string(fixData), formation)
}