Ejemplo n.º 1
0
func TestClient(t *T) {
	Convey("client", t, func() {
		Convey("Create(http)", func() {
			Convey("It should create a new http client", func() {
				s, err := client.Create("http://127.0.0.1:6060", "username", "password")
				So(err, ShouldEqual, nil)
				js, ok := s.(*Client)
				So(ok, ShouldEqual, true)
				So(js.Addr, ShouldEqual, "http://127.0.0.1:6060")
				So(js.Auth, ShouldEqual, "dXNlcm5hbWU6cGFzc3dvcmQ=")
			})
		})
		Convey("Create(https)", func() {
			Convey("It should create a new http client", func() {
				s, err := client.Create("https://127.0.0.1:6060", "username", "password")
				So(err, ShouldEqual, nil)
				js, ok := s.(*Client)
				So(ok, ShouldEqual, true)
				So(js.Addr, ShouldEqual, "https://127.0.0.1:6060")
				So(js.Auth, ShouldEqual, "dXNlcm5hbWU6cGFzc3dvcmQ=")
			})
		})
	})
}
Ejemplo n.º 2
0
func TestClient(t *T) {
	Convey("client", t, func() {
		Convey("Create()", func() {
			Convey("It should create a new json client", func() {
				s, err := client.Create("json://127.0.0.1:6060", "username", "password")
				So(err, ShouldEqual, nil)
				js, ok := s.(*Client)
				So(ok, ShouldEqual, true)
				So(js.Addr, ShouldEqual, "127.0.0.1:6060")
				So(js.Auth[0], ShouldEqual, "username")
				So(js.Auth[1], ShouldEqual, "password")
			})
		})
	})
}
Ejemplo n.º 3
0
func runHandler(c *cli.Context) {
	name := c.Args().First()
	if name == "" {
		log.Fatal("Action name can not be empty.")
	}

	var actionRunner runner.Runner = local.DefaultRunner

	if cloud := c.String("cloud"); cloud != "" {
		var err error
		actionRunner, err = client.Create(cloud)
		if err != nil {
			log.Fatalf("client create error: %v", err)
		}
	}

	ctx := make(action.Map)

	for _, kvs := range c.StringSlice("var") {
		if index := strings.Index(kvs, "="); index <= 0 || index >= len(kvs)+1 {
			log.Fatalf("incorrect -var flag: %q", kvs)
		} else {
			key := kvs[:index-1]
			value := kvs[index+1:]
			ctx[key] = value
		}
	}

	resp, err := actionRunner.Run(&action.Action{Name: name, Ctx: ctx})
	if err != nil {
		log.Fatalf("action error: %v", err)
	}

	body, _ := json.MarshalIndent(resp, "", "  ")
	log.Printf("%s", body)
}