lib9p

Go 9P library.
Log | Files | Refs | LICENSE

fcall_test.go (839B)


      1 package lib9p
      2 
      3 import (
      4 	"bytes"
      5 	"io"
      6 	"os"
      7 	"testing"
      8 )
      9 
     10 // TestFcallParse parses 9P message and marshals it back, and
     11 // checks whether they are identical.
     12 func TestFcallParse(t *testing.T) {
     13 	tFile, err := os.Open("testdata/test_Tmsg.dat")
     14 	if err != nil {
     15 		t.Fatalf("open file: %v", err)
     16 	}
     17 	defer tFile.Close()
     18 	rFile, err := os.Open("testdata/test_Rmsg.dat")
     19 	if err != nil {
     20 		t.Fatalf("open file: %v", err)
     21 	}
     22 	defer rFile.Close()
     23 	rawFile := io.MultiReader(tFile, rFile)
     24 	for {
     25 		mb, err := readMsg(rawFile)
     26 		if err == io.EOF {
     27 			break
     28 		} else if err != nil {
     29 			t.Errorf("read msg: %v", err)
     30 			continue
     31 		}
     32 		m, err := unmarshal(mb)
     33 		if err != nil {
     34 			t.Errorf("unmarshal: %v", err)
     35 			continue
     36 		}
     37 		//t.Log(m)
     38 		if !bytes.Equal(m.marshal(), mb) {
     39 			t.Errorf("data mismatch: %v, %v != %v", m, m.marshal(), mb)
     40 		}
     41 	}
     42 }