當前位置: 首頁>>代碼示例>>Golang>>正文


Golang models.App類代碼示例

本文整理匯總了Golang中github.com/convox/rack/api/models.App的典型用法代碼示例。如果您正苦於以下問題:Golang App類的具體用法?Golang App怎麽用?Golang App使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了App類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: assertFixture

func assertFixture(t *testing.T, name string) {
	orig := manifest.ManifestRandomPorts
	manifest.ManifestRandomPorts = false
	defer func() { manifest.ManifestRandomPorts = orig }()

	app := models.App{
		Name: "httpd",
		Tags: map[string]string{
			"Name":   "httpd",
			"Type":   "app",
			"System": "convox",
			"Rack":   "convox-test",
		},
	}

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

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

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

	pretty, err := models.PrettyJSON(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(pretty), "\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"))
	}
}
開發者ID:gmelika,項目名稱:rack,代碼行數:60,代碼來源:fixtures_test.go

示例2: TestRackStackName

func TestRackStackName(t *testing.T) {
	r := models.App{
		Name: "convox-test",
	}

	assert.Equal(t, "convox-test", r.StackName())
}
開發者ID:convox,項目名稱:rack,代碼行數:7,代碼來源:app_test.go

示例3: TestAppStackName

func TestAppStackName(t *testing.T) {
	// unbound app (no rack prefix)
	a := models.App{
		Name: "httpd",
		Tags: map[string]string{
			"Type":   "app",
			"System": "convox",
			"Rack":   "convox-test",
		},
	}

	assert.Equal(t, "httpd", a.StackName())

	// bound app (rack prefix, and Name tag)
	a = models.App{
		Name: "httpd",
		Tags: map[string]string{
			"Name":   "httpd",
			"Type":   "app",
			"System": "convox",
			"Rack":   "convox-test",
		},
	}

	assert.Equal(t, "convox-test-httpd", a.StackName())
}
開發者ID:convox,項目名稱:rack,代碼行數:26,代碼來源:app_test.go

示例4: TestAppCronJobs

func TestAppCronJobs(t *testing.T) {

	m := manifest.Manifest{
		Version: "1",
		Services: map[string]manifest.Service{
			"one": {
				Name: "one",
				Labels: manifest.Labels{
					"convox.cron.task1": "00 19 * * ? ls -la",
				},
			},
			"two": {
				Name: "two",
				Labels: manifest.Labels{
					"convox.cron.task2": "00 20 * * ? ls -la",
					"convox.cron.task3": "00 21 * * ? ls -la",
				},
			},
		},
	}

	a := models.App{
		Name: "httpd",
		Tags: map[string]string{
			"Name":   "httpd",
			"Type":   "app",
			"System": "convox",
			"Rack":   "convox-test",
		},
	}

	cj := a.CronJobs(m)
	sort.Sort(models.CronJobs(cj))

	assert.Equal(t, len(cj), 3)
	assert.Equal(t, cj[0].Name, "task1")
	assert.Equal(t, cj[0].Service.Name, "one")
	assert.Equal(t, cj[1].Service.Name, "two")
	assert.Equal(t, cj[1].Name, "task2")
	assert.Equal(t, cj[2].Service.Name, "two")
	assert.Equal(t, cj[2].Name, "task3")
}
開發者ID:convox,項目名稱:rack,代碼行數:42,代碼來源:app_test.go

示例5: main

func main() {
	if len(os.Args) < 2 {
		die(fmt.Errorf("usage: fixture <docker-compose.yml>"))
	}

	os.Setenv("REGION", "test")

	data, err := ioutil.ReadFile(os.Args[1])
	if err != nil {
		die(err)
	}

	app := models.App{
		Name: "httpd",
		Tags: map[string]string{
			"Name":   "httpd",
			"Type":   "app",
			"System": "convox",
			"Rack":   "convox-test",
		},
	}

	m, err := manifest.Load(data)
	if err != nil {
		die(err)
	}

	f, err := app.Formation(*m)
	if err != nil {
		die(err)
	}

	pretty, err := models.PrettyJSON(f)
	if err != nil {
		die(err)
	}

	fmt.Println(pretty)
}
開發者ID:gmelika,項目名稱:rack,代碼行數:39,代碼來源:fixture.go


注:本文中的github.com/convox/rack/api/models.App類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。