Ejemplo n.º 1
0
func TestCrewRenderPlain(t *testing.T) {
	c := NewCrew("test")

	// Set some variables
	c.Vars = map[string]interface{}{
		"path": "/usr/local/bin",
		"n":    4,
		"x":    3.45,
	}

	// No placeholders
	s, _ := c.Render("python test.py")
	assert.Equal(t, s, "python test.py")

	// Missing key
	s, err := c.Render("{{bindir}}/python test.py")
	assert.NotEqual(t, err, nil)

	// Typical
	s, err = c.Render("{{path}}/python -n {{n}} -x {{x}} test.py")
	assert.Equal(t, s, "/usr/local/bin/python -n 4 -x 3.45 test.py")

	// Single braces aren't affected
	s, err = c.Render("{path}")
	assert.Equal(t, s, "{path}")

	// Escaped braces aren't affected, but replaced
	s, err = c.Render("{\\{path\\}}")
	assert.Equal(t, s, "{{path}}")

	// Escaped braces, round 2
	s, err = c.Render("\\{\\{path\\}\\}")
	assert.Equal(t, s, "{{path}}")
}
Ejemplo n.º 2
0
func TestShortRead(t *testing.T) {
	var result []byte
	var buf [2]byte

	for _, test := range readerTests {
		result = result[:0]

		var (
			r   = NewReader(Rope{test.r})
			n   int
			err error
		)
		for err == nil {
			n, err = r.Read(buf[:])

			if err == nil {
				assert.NotEqual(t, n, 0, "Zero-length Read()")
			}

			result = append(result, buf[:n]...)
		}
		assert.Equal(t, test.want, string(result))
		assert.Equal(t, err, io.EOF, "Non-EOF error: "+err.Error())
	}
}
Ejemplo n.º 3
0
func TestFailedRoutineRun(t *testing.T) {
	r := NewRoutine("git", "flub")
	c := NewCrew("c1")
	rr, err := r.Run(c)

	assert.NotEqual(t, err, nil)
	assert.Equal(t, rr.Done(), true)
	assert.Equal(t, rr.Failed, true)
	assert.Equal(t, rr.Stdin, "")
	assert.Equal(t, rr.Stdout, "")
	assert.Equal(t, rr.Stderr, "git: 'flub' is not a git command. See 'git --help'.\n\nDid you mean this?\n\tpull\n")
}
Ejemplo n.º 4
0
func TestPlayInsertScene(t *testing.T) {
	p := NewPlay("P0", "")
	s0 := NewScene("S0", "")

	// Cannot insert at a position that does not exist
	err := p.InsertScene(0, s0)
	assert.NotEqual(t, err, nil)

	p.AddScene(s0)

	// Insert new scene at position 0
	ns0 := NewScene("New S0", "")
	err = p.InsertScene(0, ns0)
	assert.Equal(t, err, nil)
	assert.Equal(t, p.Scenes[0], ns0)
	assert.Equal(t, p.Scenes[1], s0)
}
Ejemplo n.º 5
0
func TestPlayAddScene(t *testing.T) {
	p := NewPlay("P0", "")
	s0 := NewScene("S0", "")
	s1 := NewScene("S1", "")

	// Yep..
	p.AddScene(s0)
	assert.Equal(t, p.Scenes[0], s0)

	// Yep..
	p.AddScene(s1)
	assert.Equal(t, p.Scenes[1], s1)

	// Nope..
	err := p.AddScene(s1)
	assert.NotEqual(t, err, nil)
}