Ejemplo n.º 1
0
func TestProjectType(t *testing.T) {
	t.Parallel()
	h := parsecli.NewHarness(t)
	defer h.Stop()

	h.MakeEmptyRoot()
	ensure.Nil(t, parsecli.CloneSampleCloudCode(h.Env, false))

	c := &configureCmd{}
	err := c.projectType(h.Env, []string{"1", "2"})
	ensure.Err(t, err, regexp.MustCompile("only an optional project type argument is expected"))

	h.Env.In = ioutil.NopCloser(strings.NewReader("invalid\n"))
	err = c.projectType(h.Env, nil)
	ensure.StringContains(t, h.Err.String(), "Invalid selection. Please enter a number")
	ensure.Err(t, err, regexp.MustCompile("Could not make a selection. Please try again."))
	h.Err.Reset()
	h.Out.Reset()

	h.Env.In = ioutil.NopCloser(strings.NewReader("0\n"))
	err = c.projectType(h.Env, nil)
	ensure.StringContains(t, h.Err.String(), "Please enter a number between 1 and")
	ensure.Err(t, err, regexp.MustCompile("Could not make a selection. Please try again."))
	h.Err.Reset()
	h.Out.Reset()

	h.Env.In = ioutil.NopCloser(strings.NewReader("1\n"))
	err = c.projectType(h.Env, nil)
	ensure.StringContains(t, h.Out.String(), "Successfully set project type to: parse")
	ensure.Nil(t, err)
}
Ejemplo n.º 2
0
func TestNewCmdContent(t *testing.T) {
	t.Parallel()

	h, _ := newNewCmdHarness(t)
	defer h.Stop()

	ensure.Nil(t, parsecli.CloneSampleCloudCode(h.Env, true))

	for _, newProjectFile := range parsecli.NewProjectFiles {
		content, err := ioutil.ReadFile(
			filepath.Join(h.Env.Root, newProjectFile.Dirname, newProjectFile.Filename),
		)
		ensure.Nil(t, err)
		ensure.DeepEqual(t, string(content), newProjectFile.Content)
	}

	content, err := ioutil.ReadFile(filepath.Join(h.Env.Root, parsecli.ParseProject))
	ensure.Nil(t, err)
	ensure.DeepEqual(t,
		string(content),
		fmt.Sprintf(
			`{
  "project_type" : %d,
  "parse": {"jssdk":""}
}`,
			parsecli.ParseFormat,
		),
	)

	content, err = ioutil.ReadFile(filepath.Join(h.Env.Root, parsecli.ParseLocal))
	ensure.Nil(t, err)
	ensure.DeepEqual(t, string(content), "{}")

}
Ejemplo n.º 3
0
func TestPrintListNoApps(t *testing.T) {
	t.Parallel()
	h, l := newListCmdHarness(t)
	h.MakeEmptyRoot()
	defer h.Stop()
	parsecli.CloneSampleCloudCode(h.Env, true)
	ensure.Nil(t, l.printListOfApps(h.Env))
}
Ejemplo n.º 4
0
func newAddCmdHarnessWithConfig(t testing.TB) (*parsecli.Harness, *addCmd, error) {
	a := addCmd{apps: &defaultApps}

	h, _ := newAddCmdHarness(t)
	h.MakeEmptyRoot()

	ensure.Nil(t, parsecli.CloneSampleCloudCode(h.Env, true))

	return h, &a, nil
}
Ejemplo n.º 5
0
func newDefaultCmdHarness(t testing.TB) (*parsecli.Harness, *defaultCmd, *parsecli.ParseConfig) {
	h := parsecli.NewHarness(t)
	h.MakeEmptyRoot()

	ensure.Nil(t, parsecli.CloneSampleCloudCode(h.Env, true))

	config := newDefaultParseConfig(t, h)
	h.Out.Reset()

	d := &defaultCmd{}
	return h, d, config
}
Ejemplo n.º 6
0
func TestNewCmdDirs(t *testing.T) {
	t.Parallel()

	h, _ := newNewCmdHarness(t)
	defer h.Stop()

	ensure.Nil(t, parsecli.CloneSampleCloudCode(h.Env, true))

	var err error

	for _, newProjectFile := range parsecli.NewProjectFiles {
		_, err = os.Stat(filepath.Join(h.Env.Root, newProjectFile.Dirname))
		ensure.Nil(t, err)
	}
}
Ejemplo n.º 7
0
func newJsSdkHarnessWithConfig(t testing.TB) (*parsecli.Harness, *parsecli.Context) {
	h := newJsSdkHarness(t)
	h.MakeEmptyRoot()

	ensure.Nil(t, parsecli.CloneSampleCloudCode(h.Env, true))
	h.Out.Reset()

	c, err := parsecli.ConfigFromDir(h.Env.Root)
	ensure.Nil(t, err)

	config, ok := (c).(*parsecli.ParseConfig)
	ensure.True(t, ok)

	return h, &parsecli.Context{Config: config}
}
Ejemplo n.º 8
0
func newLegacyAddCmdHarnessWithConfig(t testing.TB) (*parsecli.Harness, *addCmd, error) {
	a := addCmd{apps: &defaultApps}

	h, _ := newAddCmdHarness(t)
	h.MakeEmptyRoot()

	ensure.Nil(t, parsecli.CloneSampleCloudCode(h.Env, true))
	ensure.Nil(t, os.MkdirAll(filepath.Join(h.Env.Root, parsecli.ConfigDir), 0755))
	ensure.Nil(t,
		ioutil.WriteFile(
			filepath.Join(h.Env.Root, parsecli.LegacyConfigFile),
			[]byte("{}"),
			0600,
		),
	)
	return h, &a, nil
}
Ejemplo n.º 9
0
// NOTE: testing for legacy format
func newLegacyDefaultCmdHarness(t testing.TB) (*parsecli.Harness, *defaultCmd, *parsecli.ParseConfig) {
	h := parsecli.NewHarness(t)
	h.MakeEmptyRoot()

	ensure.Nil(t, parsecli.CloneSampleCloudCode(h.Env, true))
	ensure.Nil(t, os.MkdirAll(filepath.Join(h.Env.Root, parsecli.ConfigDir), 0755))
	ensure.Nil(t, ioutil.WriteFile(filepath.Join(h.Env.Root, parsecli.LegacyConfigFile),
		[]byte("{}"),
		0600),
	)

	config := newDefaultParseConfig(t, h)
	h.Out.Reset()

	d := &defaultCmd{}
	return h, d, config
}
Ejemplo n.º 10
0
func CloneSampleCloudCode(
	e *parsecli.Env,
	isNew, configOnly bool,
	appConfig parsecli.AppConfig) (bool, error) {
	dumpTemplate := false
	if !isNew && !configOnly {
		// if parse app was already created try to fetch Cloud Code and populate dir
		masterKey, err := appConfig.GetMasterKey(e)
		if err != nil {
			return false, err
		}
		e.ParseAPIClient = e.ParseAPIClient.WithCredentials(
			parse.MasterKey{
				ApplicationID: appConfig.GetApplicationID(),
				MasterKey:     masterKey,
			},
		)

		d := &downloadCmd{destination: e.Root}
		err = d.run(e, nil)
		if err != nil {
			if err == errNoFiles {
				dumpTemplate = true
			} else {
				fmt.Fprintln(
					e.Out,
					`
NOTE: If you like to fetch the latest deployed Cloud Code from Parse, 
you can use the "parse download" command after finishing the set up.
This will download Cloud Code to a temporary location.
`,
				)
			}
		}
	}
	dumpTemplate = (isNew || dumpTemplate) && !configOnly
	return dumpTemplate, parsecli.CloneSampleCloudCode(e, dumpTemplate)
}