当前位置: 首页>>代码示例>>Golang>>正文


Golang cookoo.Cookoo函数代码示例

本文整理汇总了Golang中github.com/Masterminds/cookoo.Cookoo函数的典型用法代码示例。如果您正苦于以下问题:Golang Cookoo函数的具体用法?Golang Cookoo怎么用?Golang Cookoo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Cookoo函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: main

func main() {
	reg, router, cxt := cookoo.Cookoo()
	cxt.Put("VendorDir", VendorDir)

	routes(reg, cxt)

	app := cli.NewApp()
	app.Name = "glide"
	app.Usage = usage
	app.Version = version
	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:  "yaml, y",
			Value: "glide.yaml",
			Usage: "Set a YAML configuration file.",
		},
		cli.BoolFlag{
			Name:  "quiet, q",
			Usage: "Quiet (no info or debug messages)",
		},
	}
	app.CommandNotFound = func(c *cli.Context, command string) {
		cxt.Put("os.Args", os.Args)
		cxt.Put("command", command)
		setupHandler(c, "@plugin", cxt, router)
	}

	app.Commands = commands(cxt, router)

	app.Run(os.Args)
}
开发者ID:frozzare,项目名称:glide,代码行数:31,代码来源:glide.go

示例2: TestCommandsNonEmpty

func TestCommandsNonEmpty(t *testing.T) {
	_, router, ctx := cookoo.Cookoo()
	commands := commands(ctx, router)
	if len(commands) == 0 {
		t.Fail()
	}
}
开发者ID:rudle,项目名称:glide,代码行数:7,代码来源:glide_test.go

示例3: TestReplayHistory

func TestReplayHistory(t *testing.T) {
	reg, router, cxt := cookoo.Cookoo()
	cxt.AddLogger("out", os.Stdout)

	medium := NewMedium()
	cxt.AddDatasource(MediumDS, medium)

	topic := NewHistoriedTopic("test", 5)
	medium.Add(topic)

	topic.Publish([]byte("first"))
	topic.Publish([]byte("second"))

	req, _ := http.NewRequest("GET", "https://localhost/v1/t/test", nil)
	req.Header.Add(XHistoryLength, "4")
	res := &mockResponseWriter{}

	cxt.Put("http.Request", req)
	cxt.Put("http.ResponseWriter", res)

	reg.Route("test", "Test route").
		Does(ReplayHistory, "res").Using("topic").WithDefault("test")

	err := router.HandleRequest("test", cxt, true)
	if err != nil {
		t.Error(err)
	}

	last := res.String()
	if last != "firstsecond" {
		t.Errorf("Expected 'firstsecond', got '%s'", last)
	}

}
开发者ID:technosophos,项目名称:drift,代码行数:34,代码来源:cmds_test.go

示例4: Example

func Example() {
	_, _, c := cookoo.Cookoo()

	// Set logging to go to Stdout.
	c.AddLogger("stdout", os.Stdout)

	// Set the log level to any of the Log* constants.
	Level = LogInfo

	// Functions are named as they are in log/syslog.
	Err(c, "Failed to do something.")

	// There are also formatting versions of every log function.
	Infof(c, "Informational message with %s.", "formatting")

	// Shorthand for if Level >= LogDebug
	if Debugging() {
		Debug(c, "This is a debug message.")
	}

	// You can test for any level.
	if Level >= LogWarning {
		Warn(c, "And this is a warning.")
	}

	Stack(c, "Stack trace from here.")
}
开发者ID:ngpestelos,项目名称:deis,代码行数:27,代码来源:log_test.go

示例5: TestShowHelp

func TestShowHelp(t *testing.T) {
	registry, router, context := cookoo.Cookoo()

	var out bytes.Buffer

	registry.Route("test", "Testing help.").Does(ShowHelp, "didShowHelp").
		Using("show").WithDefault(true).
		Using("writer").WithDefault(&out).
		Using("summary").WithDefault("This is a summary.").
		Does(Barf, "Fail if help doesn't stop.")

	e := router.HandleRequest("test", context, false)

	if e != nil {
		t.Error("! Unexpected error.")
	}

	res := context.Get("didShowHelp", false).(bool)

	if !res {
		t.Error("! Expected help to be shown.")
	}

	msg := out.String()
	if !strings.Contains(msg, "SUMMARY\n") {
		t.Error("! Expected 'summary' as a header.")
	}
	if !strings.Contains(msg, "This is a summary.") {
		t.Error("! Expected 'This is a summary' to be in the output. Got ", msg)
	}
}
开发者ID:Crispy1975,项目名称:deis,代码行数:31,代码来源:commands_test.go

示例6: runServer

func runServer(config *ssh.ServerConfig, c *Circuit, t *testing.T) cookoo.Context {
	reg, router, cxt := cookoo.Cookoo()
	cxt.Put(ServerConfig, config)
	cxt.Put(Address, testingServerAddr)
	cxt.Put("cookoo.Router", router)

	reg.AddRoute(cookoo.Route{
		Name: "sshPing",
		Help: "Handles an ssh exec ping.",
		Does: cookoo.Tasks{
			cookoo.Cmd{
				Name: "ping",
				Fn:   Ping,
				Using: []cookoo.Param{
					{Name: "request", From: "cxt:request"},
					{Name: "channel", From: "cxt:channel"},
				},
			},
		},
	})

	go func() {
		if err := Serve(reg, router, c, cxt); err != nil {
			t.Fatalf("Failed serving with %s", err)
		}
	}()

	return cxt

}
开发者ID:vdice,项目名称:builder,代码行数:30,代码来源:server_test.go

示例7: main

// main is an example of a simple Web server written in Cookoo.
func main() {
	// First, we create a new Cookoo app.
	reg, router, cxt := cookoo.Cookoo()

	// We declare a route that answers GET requests for the path /
	//
	// By default, this will be running on http://localhost:8080/
	reg.Route("GET /", "Simple test route.").
		Does(web.Flush, "out").
		Using("content").WithDefault("OH HAI!")

	// We declare a route that answers GET requests for the path /test
	// This one uses a basic template.
	//
	// By default, this will be running on http://localhost:8080/
	//
	// Because we use `query:you`, try hitting the app on this URL:
	// http://localhost:8080/test?you=Matt
	reg.Route("GET /test", "Simple test route.").
		Does(fmt.Template, "content").
		Using("template").WithDefault("Hello {{.you}}").
		Using("you").WithDefault("test").From("query:you").
		Does(web.Flush, "out").
		Using("content").From("cxt:content")

	// Start the server.
	web.Serve(reg, router, cxt)
}
开发者ID:ngpestelos,项目名称:deis,代码行数:29,代码来源:webserver.go

示例8: TestTimestamp

func TestTimestamp(t *testing.T) {
	reg, router, cxt := cookoo.Cookoo()

	reg.Route("test", "Test route").
		Does(Timestamp, "res")

	err := router.HandleRequest("test", cxt, true)
	if err != nil {
		t.Error(err)
	}

	ts := cxt.Get("res", "").(string)

	if len(ts) == 0 {
		t.Errorf("Expected timestamp, not empty string.")
	}

	tsInt, err := strconv.Atoi(ts)
	if err != nil {
		t.Error(err)
	}

	if tsInt <= 5 {
		t.Error("Dude, you're stuck in the '70s.")
	}
}
开发者ID:technosophos,项目名称:drift,代码行数:26,代码来源:httputil_test.go

示例9: TestRunOnce

func TestRunOnce(t *testing.T) {
	reg, _, _ := cookoo.Cookoo()

	reg.Route("test", "Test route").
		Does(RunOnce, "res").
		Using("node").WithDefault("localhost:4001")
}
开发者ID:CodeJuan,项目名称:deis,代码行数:7,代码来源:confd_test.go

示例10: TestSet

func TestSet(t *testing.T) {
	reg, router, cxt := cookoo.Cookoo()

	os.Setenv("SLURM", "COFFEE")

	reg.Route("test", "Test route").
		Does(Set, "res").
		Using("HELLO").WithDefault("hello").
		Using("EMPTY").WithDefault(nil).
		Using("FAVORITE_DRINK").WithDefault("$SLURM")

	if err := router.HandleRequest("test", cxt, true); err != nil {
		t.Error(err)
	}

	expect := map[string]string{
		"HELLO":          "hello",
		"EMPTY":          "",
		"FAVORITE_DRINK": "COFFEE",
	}

	for k, v := range expect {
		if v != os.Getenv(k) {
			t.Errorf("Expected env var %s to be '%s', got '%s'", k, v, os.Getenv(k))
		}
		if cv := cxt.Get(k, "___").(string); cv != v {
			t.Errorf("Expected context var %s to be '%s', got '%s'", k, v, cv)
		}
	}

}
开发者ID:helgi,项目名称:pkg,代码行数:31,代码来源:envvar_test.go

示例11: TestTemplate

func TestTemplate(t *testing.T) {
	reg, router, cxt := cookoo.Cookoo()

	reg.Route("test", "Test").
		Does(Template, "out").
		Using("template").WithDefault("{{.Hello}} {{.one}}").
		Using("Hello").WithDefault("Hello").
		Using("one").WithDefault(1)

	if err := router.HandleRequest("test", cxt, false); err != nil {
		t.Errorf("Failed route: %s", err)
	}

	if res := cxt.Get("out", "nada"); res != "Hello 1" {
		t.Errorf("Expected 'Hello 1', got %s", res)
	}

	reg.Route("test2", "Test 2").
		Does(cookoo.AddToContext, "_").Using("Foo").WithDefault("lambkin").
		Does(Template, "out2").
		Using("template.Context").WithDefault(true).
		Using("template").WithDefault("Hello {{.Cxt.Foo}}")

	if err := router.HandleRequest("test2", cxt, false); err != nil {
		t.Errorf("Failed route: %s", err)
	}

	if res := cxt.Get("out2", "nada"); res != "Hello lambkin" {
		t.Errorf("Expected 'Hello lambkin', got %s", res)
	}
}
开发者ID:ngpestelos,项目名称:deis,代码行数:31,代码来源:fmt_test.go

示例12: TestFromYaml

func TestFromYaml(t *testing.T) {
	reg, router, cxt := cookoo.Cookoo()

	reg.Route("t", "Testing").
		Does(ParseYamlString, "cfg").Using("yaml").WithDefault(yamlFile)

	if err := router.HandleRequest("t", cxt, false); err != nil {
		t.Errorf("Failed to parse YAML: %s", err)
	}

	cfg := cxt.Get("cfg", nil).(*Config)
	if cfg.Name != "fake/testing" {
		t.Errorf("Expected name to be 'fake/teting', not '%s'", cfg.Name)
	}

	if len(cfg.Imports) != 3 {
		t.Errorf("Expected 3 imports, got %d", len(cfg.Imports))
	}

	imp := cfg.Imports[2]
	if imp.Name != "github.com/Masterminds/convert" {
		t.Errorf("Expected the convert package, got %s", imp.Name)
	}

	if len(imp.Subpackages) != 3 {
		t.Errorf("Expected 3 subpackages. got %d", len(imp.Subpackages))
	}

	if imp.Subpackages[0] != "color" {
		t.Errorf("Expected first subpackage to be 'color', got '%s'", imp.Subpackages[0])
	}

	if len(imp.Os) != 1 {
		t.Errorf("Expected Os: SOMETHING")
	} else if imp.Os[0] != "linux" {
		t.Errorf("Expected Os: linux")
	}

	if len(imp.Arch) != 2 {
		t.Error("Expected two Archs.")
	} else if imp.Arch[0] != "i386" {
		t.Errorf("Expected arch 1 to be i386, got %s.", imp.Arch[0])
	} else if imp.Arch[1] != "arm" {
		t.Error("Expected arch 2 to be arm.")
	}

	if imp.Repository != "[email protected]:Masterminds/convert.git" {
		t.Errorf("Got wrong repo")
	}
	if imp.Reference != "a9949121a2e2192ca92fa6dddfeaaa4a4412d955" {
		t.Errorf("Got wrong reference.")
	}

	if len(cfg.DevImports) != 1 {
		t.Errorf("Expected one dev import.")
	}

}
开发者ID:jackspirou,项目名称:glide,代码行数:58,代码来源:yaml_test.go

示例13: TestCreateClient

func TestCreateClient(t *testing.T) {
	reg, router, cxt := cookoo.Cookoo()

	reg.Route("test", "Test route").
		Does(CreateClient, "res").Using("url").WithDefault("localhost:4100")

	if err := router.HandleRequest("test", cxt, true); err != nil {
		t.Error(err)
	}

	// All we really want to know is whether we got a valid client back.
	_ = cxt.Get("res", nil).(*etcd.Client)
}
开发者ID:CodeJuan,项目名称:deis,代码行数:13,代码来源:etcd_test.go

示例14: TestGet

func TestGet(t *testing.T) {
	reg, router, cxt := cookoo.Cookoo()

	drink := "DEIS_DRINK_OF_CHOICE"
	cookies := "DEIS_FAVORITE_COOKIES"
	snack := "DEIS_SNACK_TIME"
	snackVal := fmt.Sprintf("$%s and $%s cookies", drink, cookies)

	// Set drink, but not cookies.
	os.Setenv(drink, "coffee")

	reg.Route("test", "Test route").
		Does(Get, "res").
		Using(drink).WithDefault("tea").
		Using(cookies).WithDefault("chocolate chip").
		Does(Get, "res2").
		Using(snack).WithDefault(snackVal)

	err := router.HandleRequest("test", cxt, true)
	if err != nil {
		t.Error(err)
	}

	// Drink should still be coffee.
	if coffee := cxt.Get(drink, "").(string); coffee != "coffee" {
		t.Errorf("A great sin has been committed. Expected coffee, but got '%s'", coffee)
	}
	// Env var should be untouched
	if coffee := os.Getenv(drink); coffee != "coffee" {
		t.Errorf("Environment was changed from 'coffee' to '%s'", coffee)
	}

	// Cookies should have been set to the default
	if cookies := cxt.Get(cookies, "").(string); cookies != "chocolate chip" {
		t.Errorf("Expected chocolate chip cookies, but instead, got '%s' :-(", cookies)
	}

	// In the environment, cookies should have been set.
	if cookies := os.Getenv(cookies); cookies != "chocolate chip" {
		t.Errorf("Expected environment to have chocolate chip cookies, but instead, got '%s'", cookies)
	}

	if both := cxt.Get(snack, "").(string); both != "coffee and chocolate chip cookies" {
		t.Errorf("Expected 'coffee and chocolate chip cookies'. Got '%s'", both)
	}

	if both := os.Getenv(snack); both != snackVal {
		t.Errorf("Expected %s to not be expanded. Got '%s'", snack, both)
	}
}
开发者ID:rsackler,项目名称:deis,代码行数:50,代码来源:envvar_test.go

示例15: TestGetImportsEmptyConfig

func TestGetImportsEmptyConfig(t *testing.T) {
	_, _, c := cookoo.Cookoo()
	SilenceLogs(c)
	cfg := new(Config)
	p := cookoo.NewParamsWithValues(map[string]interface{}{"conf": cfg})
	res, it := GetImports(c, p)
	if it != nil {
		t.Errorf("Interrupt value non-nil")
	}
	bres, ok := res.(bool)
	if !ok || bres {
		t.Errorf("Result was non-bool or true: ok=%t bres=%t", ok, bres)
	}
}
开发者ID:jonboulle,项目名称:glide,代码行数:14,代码来源:get_imports_test.go


注:本文中的github.com/Masterminds/cookoo.Cookoo函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。