예제 #1
0
func TestHeaderUnmarshal(t *testing.T) {
	for i, d := range testData {
		if len(d.Raw) != headerSize {
			t.Errorf("testData[%d].Raw is invalid", i)
		}
		h := Header{}
		h.UnmarshalBinary(d.Raw)
		if diff := pretty.Compare(d.Header, h); diff != "" {
			t.Errorf("testData[%d] failed: %v", i, diff)
		}
	}
}
예제 #2
0
func TestHeaderMarshal(t *testing.T) {
	for i, d := range testData {
		b, err := d.Header.MarshalBinary()
		if err != nil {
			t.Errorf("testData[%d] marshal failed: %v", i, err)
			continue
		}
		if diff := pretty.Compare(d.Raw, b); diff != "" {
			t.Errorf("testData[%d] failed: %v", i, diff)
		}
	}
}
예제 #3
0
func ExampleCompare() {
	type ShipManifest struct {
		Name     string
		Crew     map[string]string
		Androids int
		Stolen   bool
	}

	reported := &ShipManifest{
		Name: "Spaceship Heart of Gold",
		Crew: map[string]string{
			"Zaphod Beeblebrox": "Galactic President",
			"Trillian":          "Human",
			"Ford Prefect":      "A Hoopy Frood",
			"Arthur Dent":       "Along for the Ride",
		},
		Androids: 1,
		Stolen:   true,
	}

	expected := &ShipManifest{
		Name: "Spaceship Heart of Gold",
		Crew: map[string]string{
			"Rowan Artosok": "Captain",
		},
		Androids: 1,
		Stolen:   false,
	}

	fmt.Println(pretty.Compare(reported, expected))
	// Output:
	//  {
	//   Name:     "Spaceship Heart of Gold",
	//   Crew:     {
	// -            Arthur Dent:       "Along for the Ride",
	// -            Ford Prefect:      "A Hoopy Frood",
	// -            Trillian:          "Human",
	// -            Zaphod Beeblebrox: "Galactic President",
	// +            Rowan Artosok: "Captain",
	//             },
	//   Androids: 1,
	// - Stolen:   true,
	// + Stolen:   false,
	//  }
}
예제 #4
0
func TestPackageFromPath(t *testing.T) {
	expect := Package{
		Name:     "null",
		Sha1:     "2jmj7l5rSw0yVb/vlWAYkK/YBwk=",
		Sha256:   "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=",
		Size:     0,
		Required: false,
	}

	p := Package{}
	if err := p.FromPath("/dev/null"); err != nil {
		t.Fatal(err)
	}

	if diff := pretty.Compare(expect, p); diff != "" {
		t.Errorf("Hashing /dev/null failed: %v", diff)
	}
}
예제 #5
0
func TestProtocolFromReader(t *testing.T) {
	data := strings.NewReader("testing\n")
	expect := Package{
		Name:     "",
		Sha1:     "mAFznarkTsUpPU4fU9P00tQm2Rw=",
		Sha256:   "EqYfThc/s6EcBdZHH3Ryj3YjG0pfzZZnzvOvh6OuTcI=",
		Size:     8,
		Required: false,
	}

	p := Package{}
	if err := p.FromReader(data); err != nil {
		t.Fatal(err)
	}

	if diff := pretty.Compare(expect, p); diff != "" {
		t.Errorf("Hashing failed: %v", diff)
	}
}