예제 #1
0
func TestLegacyIn(t *testing.T) {

	var cat = "cat"
	if isWindows {
		cat = "cmd /c type"
	}
	//// Run

	// in V2 BashOutput accepts an options map

	out, err := RunOutput(cat+" foo.txt", M{"$in": "test"})
	assert.NoError(t, err)
	assert.Equal(t, "foo", str.Clean(out))

	if isWindows {
		return
	}

	//// Bash

	// in V2 BashOutput accepts an options map
	out, err = BashOutput("cat foo.txt", M{"$in": "test"})
	assert.NoError(t, err)
	assert.Equal(t, "foo", str.Clean(out))
}
예제 #2
0
파일: main.go 프로젝트: THEY/godo
func main() {
	// legacy version used tasks/
	godoFiles := []string{"Gododir/Godofile.go", "tasks/Godofile.go"}
	src := ""
	rel := ""
	for _, filename := range godoFiles {
		rel = filename
		filename, err := filepath.Abs(filename)
		if err != nil {
			panic("Could not get absolute path " + filename)
		}
		if !util.FileExists(filename) {
			continue
		}
		src = filename
		break
	}

	if src == "" {
		godo.Usage("")
		fmt.Printf("\n\n%s not found\n", src)
		os.Exit(1)
	}

	exe := buildMain(rel)
	cmd := exe + " " + strings.Join(os.Args[1:], " ")
	cmd = str.Clean(cmd)
	// errors are displayed by tasks

	godo.Run(cmd)
}
예제 #3
0
파일: project_test.go 프로젝트: THEY/godo
func TestTemplatedCommands(t *testing.T) {
	echo := "echo"
	if isWindows {
		echo = "cmd /c echo"

	}
	// in V2 BashOutput accepts an options map
	out, err := RunOutput(echo+" {{.name}}", M{"name": "oy"})
	assert.NoError(t, err)
	assert.Equal(t, "oy", str.Clean(out))

	if isWindows {
		return
	}

	// in V2 BashOutput accepts an options map
	out, err = BashOutput("echo {{.name}}", M{"name": "oy"})
	assert.NoError(t, err)
	assert.Equal(t, "oy", str.Clean(out))
}
예제 #4
0
func TestInnerJoin(t *testing.T) {
	sql, args := Select("u.*, p.*").
		From(`
			users u
			INNER JOIN posts p on (p.author_id = u.id)
		`).
		Where(`u.id = $1`, 1).
		ToSQL()
	sql = str.Clean(sql)
	assert.Equal(t, sql, "SELECT u.*, p.* FROM users u INNER JOIN posts p on (p.author_id = u.id) WHERE (u.id = $1)")
	assert.Exactly(t, args, []interface{}{1})
}
예제 #5
0
func TestScopeJoinOnly(t *testing.T) {
	published := `
		INNER JOIN posts p on (p.author_id = u.id)
	`

	sql, args := Select("u.*, p.*").
		From(`users u`).
		Scope(published).
		Where(`u.id = $1`, 1).
		ToSQL()
	sql = str.Clean(sql)
	assert.Equal(t, "SELECT u.*, p.* FROM users u INNER JOIN posts p on (p.author_id = u.id) WHERE (u.id = $1)", sql)
	assert.Exactly(t, args, []interface{}{1})
}
예제 #6
0
파일: env_test.go 프로젝트: THEY/godo
func TestInheritedRunEnv(t *testing.T) {
	os.Setenv("TEST_RUN_ENV", "fubar")
	SetEnviron("", true)

	var output string

	if isWindows {
		output, _ = RunOutput(`FOO=bar BAH=baz cmd /C "echo %TEST_RUN_ENV% %FOO%"`)
	} else {
		output, _ = RunOutput(`FOO=bar BAH=baz bash -c "echo -n $TEST_RUN_ENV $FOO"`)
	}

	if str.Clean(output) != "fubar bar" {
		t.Error("Environment was not inherited! Got", fmt.Sprintf("%q", output))
	}
}
예제 #7
0
// parseStringEnv parse the package Env string and converts it into an
// environment slice.
func parseStringEnv(s string) []string {
	env := []string{}

	if s == "" {
		return env
	}

	s = str.Clean(s)
	argv := str.ToArgv(s)
	for _, kv := range argv {
		if !strings.Contains(kv, "=") {
			continue
		}
		env = append(env, kv)
	}
	return env
}
예제 #8
0
파일: project_test.go 프로젝트: THEY/godo
func TestInside(t *testing.T) {
	Inside("test", func() {
		var out string
		if isWindows {
			out, _ = RunOutput("foo.cmd")
		} else {
			out, _ = RunOutput("bash foo.sh")
		}

		if str.Clean(out) != "FOOBAR" {
			t.Error("Inside failed. Got", fmt.Sprintf("%q", out))
		}
	})

	version, _ := ioutil.ReadFile("./VERSION.go")
	if !strings.Contains(string(version), "var Version") {
		t.Error("Inside failed to reset work directory")
	}
}
예제 #9
0
func TestDocScopeWhere(t *testing.T) {
	published := `
		INNER JOIN posts p on (p.author_id = u.id)
		WHERE
			p.state = $1
	`
	sql, args := SelectDoc("u.*, p.*").
		From(`users u`).
		Scope(published, "published").
		Where(`u.id = $1`, 1).
		ToSQL()
	sql = str.Clean(sql)
	expected := `
		SELECT row_to_json(dat__item.*)
		FROM (
			SELECT u.*, p.*
			FROM users u
				INNER JOIN posts p on (p.author_id = u.id)
			WHERE (u.id = $1) AND ( p.state = $2 )
		) as dat__item
	`
	assert.Equal(t, stripWS(expected), stripWS(sql))
	assert.Exactly(t, args, []interface{}{1, "published"})
}