Пример #1
0
func TestCreateExecute(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	th.Mux.HandleFunc("/stacks", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "POST")
		w.Header().Add("Content-Type", "application/json")
		w.WriteHeader(http.StatusAccepted)
		fmt.Fprintf(w, `{"stack": {"id": "3095aefc-09fb-4bc7-b1f0-f21a304e864c"}}`)
	})
	cmd := &commandCreate{
		Ctx: &handler.Context{
			ServiceClient: client.ServiceClient(),
		},
	}
	templateOpts := new(osStacks.Template)
	templateOpts.Bin = []byte(`"heat_template_version": "2014-10-16"`)
	actual := &handler.Resource{
		Params: &paramsCreate{
			opts: &osStacks.CreateOpts{
				Name:         "stack1",
				TemplateOpts: templateOpts,
				Parameters: map[string]string{
					"img":    "foo",
					"flavor": "bar",
				},
			},
		},
	}
	cmd.Execute(actual)
	th.AssertNoErr(t, actual.Err)
}
Пример #2
0
func TestCreateHandleFlags(t *testing.T) {
	app := cli.NewApp()
	flagset := flag.NewFlagSet("flags", 1)
	flagset.String("name", "", "")
	flagset.String("disable-rollback", "", "")
	flagset.String("template-file", "", "")
	flagset.String("environment-file", "", "")
	flagset.String("timeout", "", "")
	flagset.String("parameters", "", "")
	flagset.Set("name", "stack1")
	flagset.Set("disable-rollback", "true")
	flagset.Set("template-file", "mytemplate.yaml")
	flagset.Set("environment-file", "myenvironment.yaml")
	flagset.Set("timeout", "300")
	flagset.Set("parameters", "img=foo,flavor=bar")
	c := cli.NewContext(app, flagset, nil)
	cmd := &commandCreate{
		Ctx: &handler.Context{
			CLIContext: c,
		},
	}
	disableRollback := true
	templateOpts := new(osStacks.Template)
	templateOpts.URL = "mytemplate.yaml"
	environmentOpts := new(osStacks.Environment)
	environmentOpts.URL = "myenvironment.yaml"
	expected := &handler.Resource{
		Params: &paramsCreate{
			opts: &osStacks.CreateOpts{
				Name:            "stack1",
				TemplateOpts:    templateOpts,
				EnvironmentOpts: environmentOpts,
				DisableRollback: &disableRollback,
				Timeout:         300,
				Parameters: map[string]string{
					"img":    "foo",
					"flavor": "bar",
				},
			},
		},
	}
	actual := &handler.Resource{}
	err := cmd.HandleFlags(actual)
	th.AssertNoErr(t, err)
	th.AssertDeepEquals(t, *expected.Params.(*paramsCreate).opts, *actual.Params.(*paramsCreate).opts)
}
Пример #3
0
func TestUpdateExecute(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	th.Mux.HandleFunc("/stacks/stack1/id1", func(w http.ResponseWriter, r *http.Request) {
		if r.Method == "PUT" {
			w.WriteHeader(http.StatusAccepted)
			w.Header().Add("Content-Type", "application/json")
			fmt.Fprintf(w, `{"stack": {}}`)
		} else if r.Method == "GET" {
			w.Header().Add("Content-Type", "application/json")
			w.WriteHeader(http.StatusOK)
			fmt.Fprint(w, `{"stack": {"creation_time": "2014-06-03T20:59:46"}}`)
		}
	})
	cmd := &commandUpdate{
		Ctx: &handler.Context{
			ServiceClient: client.ServiceClient(),
		},
	}
	templateOpts := new(osStacks.Template)
	templateOpts.Bin = []byte(`"heat_template_version": "2014-10-16"`)
	actual := &handler.Resource{
		Params: &paramsUpdate{
			stackName: "stack1",
			stackID:   "id1",
			opts: &osStacks.UpdateOpts{
				TemplateOpts: templateOpts,
				Parameters: map[string]string{
					"img":    "foo",
					"flavor": "bar",
				},
			},
		},
	}
	cmd.Execute(actual)
	th.AssertNoErr(t, actual.Err)
}