Exemplo n.º 1
0
func TestGunzipPipeline(t *testing.T) {
	pipeline := someutils.NewPipeline(Gzip(), Gunzip(), Gzip(), Gunzip())
	input := "hello 123"
	invocation, out, errout := pipeline.InvokeReader(strings.NewReader(input))
	invocation.Wait()
	outString := out.String()
	if invocation.Err != nil {
		t.Logf("Out: %+v\n", outString)
		t.Logf("Errout: %+v\n", errout.String())
		t.Errorf("Error: %d\n", invocation.Err)
	}
	if outString != input {
		t.Logf("Out: %+v\n", outString)
		t.Logf("Errout: %+v\n", errout.String())
		t.Errorf("Error: output doesnt match input: %s != %s\n", outString, input)
	}
}
Exemplo n.º 2
0
func Example_WgetTr() {
	pipeline := someutils.NewPipeline(someutils.Wrap(wget.WgetToOut()), Head(2), Tr("h", "G"))
	invocation, out, errout := pipeline.InvokeReader(strings.NewReader("www.golang.org\n"))
	errinvocation := invocation.Wait()
	outstring := out.String()
	if errinvocation.Err != nil {
		fmt.Printf("errout: %+v\n", errout.String())
		fmt.Printf("stdout: %+v", outstring)
		fmt.Printf("error: %+v, exit code: %d\n", errinvocation.Err, errinvocation.ExitCode)
		if *errinvocation.ExitCode != 0 {
			fmt.Printf("error: %+v\n", errinvocation.Err)
		}
	}
	fmt.Println(outstring)
	// Output:
	// <!DOCTYPE Gtml>
	// <Gtml>
}
Exemplo n.º 3
0
func Example_GzipGunzip() {
	pipeline := someutils.NewPipeline(Gzip(), Gunzip())
	input := "hiya"
	invocation, out, errout := pipeline.InvokeReader(strings.NewReader(input))
	errinvocation := invocation.Wait()
	outstring := out.String()
	if errinvocation.Err != nil {
		fmt.Printf("errout: %+v\n", errout.String())
		fmt.Printf("stdout: %+v", outstring)
		fmt.Printf("error: %+v, exit code: %d\n", errinvocation.Err, errinvocation.ExitCode)
		if *errinvocation.ExitCode != 0 {
			fmt.Printf("error: %+v\n", errinvocation.Err)
		}
	}
	fmt.Println(outstring)
	// Output:
	// hiya
}
Exemplo n.º 4
0
func TestXargsPipeline(t *testing.T) {
	pipeline := someutils.NewPipeline(Xargs(LsFact, "-l"))
	invocation, out, errout := pipeline.InvokeReader(strings.NewReader(".\n..\n"))
	errinvocation := invocation.Wait()
	outstring := out.String()
	if errinvocation == nil {

		t.Errorf("Wait returned nil")
	}
	if errinvocation.Err != nil {
		t.Logf("errout: %+v\n", errout.String())
		t.Logf("stdout: %+v", outstring)
		t.Logf("error: %+v, exit code: %d\n", errinvocation.Err, errinvocation.ExitCode)
		if *errinvocation.ExitCode != 0 {
			t.Errorf("error: %+v\n", errinvocation.Err)
		}
	}
	// TODO: 'Output' string for testing?
}
Exemplo n.º 5
0
/*
func TestFluentTr(t *testing.T) {
	var out bytes.Buffer
	var errout bytes.Buffer
	inPipe, outPipe, errPipe := strings.NewReader("HI"), &out, &errout
	err, code := Tr("I", "O").Invoke(invocation *someutils.Invocation) (error, int) {
invocation.ErrPipe.Drain()
invocation.AutoHandleSignals()
	if err != nil {
		if code != 0 {
			t.Errorf("Error: %v, code: %d\n", err, code)
		}
		t.Logf("Error: %v, code: %d\n", err, code)
	}
	t.Log(out.String())
}

func Test2pipes(t *testing.T) {
	var out bytes.Buffer
	var errout bytes.Buffer
	r, w := io.Pipe()
	in := strings.NewReader("Hi\nHo\nhI\nhO\n")
	inPipe1, outPipe1, errPipe1 := in, w, &errout
	inPipe2, outPipe2, errPipe2 := r, &out, &errout
	tr1 := Tr("H", "O")
	tr2 := Tr("I", "J")
	go tr1.Invoke(invocation *someutils.Invocation) (error, int) {
invocation.ErrPipe.Drain()
invocation.AutoHandleSignals()
	go tr2.Invoke(invocation *someutils.Invocation) (error, int) {
invocation.ErrPipe.Drain()
invocation.AutoHandleSignals()
	time.Sleep(1 * time.Second)
	output := out.String()
	expected := "Oi\nOo\nhJ\nhO\n"
	if output != expected {
		t.Error("Expected ", expected, ", got ", output)
	}
	t.Logf("Errout: %+v\n", errout.String())
}
*/
func TestTrPipeline(t *testing.T) {
	pipeline := someutils.NewPipeline(Tr("H", "O"), Tr("I", "J"))
	invocation, out, errout := pipeline.InvokeReader(strings.NewReader("Hi\nHo\nhI\nhO\n"))
	errinvocation := invocation.Wait()
	outstring := out.String()
	if errinvocation.Err != nil {
		t.Logf("errout: %+v\n", errout.String())
		t.Logf("stdout: %+v", outstring)
		t.Logf("error: %+v, exit code: %d\n", errinvocation.Err, errinvocation.ExitCode)
		if *errinvocation.ExitCode != 0 {
			t.Errorf("error: %+v\n", errinvocation.Err)
		}
	}

	output := out.String()
	expected := "Oi\nOo\nhJ\nhO\n"
	if output != expected {
		t.Error("Expected\n ", expected, ", Got:\n ", output)
	}
}
Exemplo n.º 6
0
func Example_TrFanout() {
	pipeline := someutils.NewPipeline(someutils.FanoutByLine(Tr("w", "v")))
	input := "www.google.com\nwww.bbc.co.uk\nwww.golang.org\n"
	invocation, out, errout := pipeline.InvokeReader(strings.NewReader(input))
	errinvocation := invocation.Wait()
	outstring := out.String()
	if errinvocation.Err != nil {
		fmt.Printf("errout: %+v\n", errout.String())
		fmt.Printf("stdout: %+v", outstring)
		fmt.Printf("error: %+v, exit code: %d\n", errinvocation.Err, errinvocation.ExitCode)
		if *errinvocation.ExitCode != 0 {
			fmt.Printf("error: %+v\n", errinvocation.Err)
		}
	}
	fmt.Println(outstring)
	// Output:
	// vvv.google.com
	// vvv.bbc.co.uk
	// vvv.golang.org
}