示例#1
0
func TestNewWriter_1Sample(t *testing.T) {
	t.Parallel()
	is := is.New(t)
	f, err := ioutil.TempFile("", "wavPkgtest")
	is.NoErr(err)
	wr, err := wf.NewWriter(f)
	is.NoErr(err)

	err = wr.WriteSample([]byte{1, 1})
	is.NoErr(err)

	is.Nil(wr.Close())

	f, err = os.Open(f.Name())
	is.NoErr(err)

	b, err := ioutil.ReadAll(f)
	is.NoErr(err)
	is.Equal(len(b), 46)

	is.True(bytes.Contains(b, riff))
	is.True(bytes.Contains(b, wave))
	is.True(bytes.Contains(b, fmt20))

	is.Nil(os.Remove(f.Name()))
}
示例#2
0
func TestCat(t *testing.T) {
	is := is.New(t)
	s := NewShell(shellUrl)

	rc, err := s.Cat(fmt.Sprintf("/ipfs/%s/readme", examplesHash))
	is.Nil(err)

	md5 := md5.New()
	_, err = io.Copy(md5, rc)
	is.Nil(err)
	is.Equal(fmt.Sprintf("%x", md5.Sum(nil)), "3fdcaad186e79983a6920b4c7eeda949")
}
示例#3
0
func TestPatch_rmLink(t *testing.T) {
	is := is.New(t)
	s := NewShell(shellUrl)
	newRoot, err := s.Patch(examplesHash, "rm-link", "about")
	is.Nil(err)
	is.Equal(newRoot, "QmNjJ3naRhHCn14E895R1xtGmDgKQb8vnVvQar6RrnraC1")
}
示例#4
0
func TestFileList(t *testing.T) {
	is := is.New(t)
	s := NewShell(shellUrl)

	list, err := s.FileList(fmt.Sprintf("/ipfs/%s", examplesHash))
	is.Nil(err)

	is.Equal(list.Type, "Directory")
	is.Equal(list.Size, 0)
	is.Equal(len(list.Links), 6)

	// TODO: document difference in sice betwen 'ipfs ls' and 'ipfs file ls -v'. additional object encoding in data block?
	expected := map[string]UnixLsLink{
		"about":          {Type: "File", Hash: "QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V", Name: "about", Size: 1677},
		"contact":        {Type: "File", Hash: "QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y", Name: "contact", Size: 189},
		"help":           {Type: "File", Hash: "QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7", Name: "help", Size: 311},
		"quick-start":    {Type: "File", Hash: "QmUzLxaXnM8RYCPEqLDX5foToi5aNZHqfYr285w2BKhkft", Name: "quick-start", Size: 1686},
		"readme":         {Type: "File", Hash: "QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB", Name: "readme", Size: 1091},
		"security-notes": {Type: "File", Hash: "QmTumTjvcYCAvRRwQ8sDRxh8ezmrcr88YFU7iYNroGGTBZ", Name: "security-notes", Size: 1016},
	}
	for _, l := range list.Links {
		el, ok := expected[l.Name]
		is.True(ok)
		is.NotNil(el)
		is.Equal(*l, el)
	}
}
示例#5
0
func TestAdd(t *testing.T) {
	is := is.New(t)
	s := NewShell(shellUrl)

	mhash, err := s.Add(bytes.NewBufferString("Hello IPFS Shell tests"))
	is.Nil(err)
	is.Equal(mhash, "QmUfZ9rAdhV5ioBzXKdUTh2ZNsz9bzbkaLVyQ8uc8pj21F")
}
示例#6
0
func TestResolvePath(t *testing.T) {
	is := is.New(t)
	s := NewShell(shellUrl)

	childHash, err := s.ResolvePath(fmt.Sprintf("/ipfs/%s/about", examplesHash))
	is.Nil(err)
	is.Equal(childHash, "QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V")
}
示例#7
0
func TestPatchLink(t *testing.T) {
	is := is.New(t)
	s := NewShell(shellUrl)

	newRoot, err := s.PatchLink(examplesHash, "about", "QmUXTtySmd7LD4p6RG6rZW6RuUuPZXTtNMmRQ6DSQo3aMw", true)
	is.Nil(err)
	is.Equal(newRoot, "QmQwWjFnEPxwmkb5Ukn6UnbrBVebSAYnM11nmMs89e7zH9")
}
示例#8
0
文件: slice_test.go 项目: etcenter/c4
func TestSliceIDFile(t *testing.T) {
	is := is.New(t)

	id, err := asset.Identify(errorReader(true))
	is.Err(err)
	is.Nil(id)
	is.Equal(err.Error(), "errorReader triggered error.")
}
示例#9
0
func TestMatch(t *testing.T) {
	is := is.New(t)

	e1 := &testEncoder{}
	e2 := &testEncoder{}
	e3 := &testEncoder{}

	e := encoding.New()
	e.Default = respond.JSON
	e.Add("json", e1)
	e.Add("XML", e2)

	// Match
	json, ok := e.Match("application/JSON")
	is.True(ok)
	is.Equal(json, e1)
	json = e.EncoderFunc(nil, testRequestWithAccept("application/json"))
	is.Equal(json, e1)
	xml, ok := e.Match("text/xml")
	is.True(ok)
	is.Equal(xml, e2)
	xml = e.EncoderFunc(nil, testRequestWithAccept("text/xml"))
	is.True(ok)
	is.Equal(xml, e2)

	// no responder
	csv, ok := e.Match("text/csv")
	is.False(ok)
	is.Nil(csv)
	csv = e.EncoderFunc(nil, testRequestWithAccept("text/csv"))
	is.Nil(csv)
	is.Equal(e.Default, csv)

	// add
	e.Add("csv", e3)
	csv, ok = e.Match("text/xml")
	is.True(ok)
	is.Equal(csv, e3)

	// remove
	e.Del(e2)
	xml, ok = e.Match("text/xml")
	is.False(ok)
	is.Nil(xml)

}
示例#10
0
文件: jv_test.go 项目: ashb/jqrepl
func TestJvFromJSONString(t *testing.T) {
	is := is.New(t)

	jv, err := jq.JvFromJSONString("[]")
	is.NoErr(err)
	is.OK(jv)
	is.Equal(jv.Kind(), jq.JV_KIND_ARRAY)

	jv, err = jq.JvFromJSONString("not valid")
	is.Err(err)
	is.Nil(jv)
}
示例#11
0
func TestWithUserWithNotAllDataInBody(t *testing.T) {
	is := is.New(t)
	userContext := &ApplicationContext{}
	r := getRequest(userContext, `{}`)
	w := httptest.NewRecorder()
	withUser := WithUser{
		next: func(u *User) http.Handler {
			return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
		},
	}

	withUser.ServeHTTP(w, r)

	is.Equal(w.Code, http.StatusBadRequest)
	var body map[string]interface{}
	is.NoErr(json.Unmarshal(w.Body.Bytes(), &body))
	is.Nil(body["firstName"])
	is.Nil(body["lastName"])
	is.Nil(body["password"])
	is.Nil(body["email"])
}
示例#12
0
文件: set_test.go 项目: dahernan/m
func TestSet(t *testing.T) {
	is := is.New(t)
	for _, test := range setTests {
		//log.Println(test)
		ok := m.SetOK(test.M, test.K, test.V)
		if test.X == nil {
			is.Nil(test.M)
		} else {
			is.Equal(test.M, test.X)
		}
		is.Equal(test.OK, ok)
	}
}
func TestPublic(t *testing.T) {
	is := is.New(t)

	o := &obj{
		value1: "value1",
		value2: "value2",
		value3: "value3",
	}

	v, ok := meander.Public(o).(map[string]interface{})
	is.Equal(true, ok) // "Result should be msi"
	is.Equal(v["one"], "value1")
	is.Nil(v["two"]) // value2
	is.Equal(v["three"], "value3")
}
func TestUnpackObject_blob(t *testing.T) {
	is := is.New(t)
	tcases := []struct {
		Fname  string
		Object *Object
	}{

		// blobs
		{
			Fname: "tests/blob/1f7a7a472abf3dd9643fd615f6da379c4acb3e3a",
			Object: &Object{
				Type: BlobT,
				Size: 10,
				blob: newBlob([]byte("version 2\n")),
			},
		},
		{
			Fname: "tests/blob/d670460b4b4aece5915caf5c68d12f560a9fe3e4",
			Object: &Object{
				Type: BlobT,
				Size: 13,
				blob: newBlob([]byte("test content\n")),
			},
		},

		// trees
		{
			Fname: "tests/tree/3c4e9cd789d88d8d89c1073707c3585e41b0e614",
			Object: &Object{Type: TreeT, Size: 101,
				tree: []Tree{
					{"40000", "bak", shaFromStr("\xd82\x9f\xc1̓\x87\x80\xffݟ\x94\xe0\xd3d\xe0\xeat\xf5y")},
					{"100644", "new.txt", shaFromStr("\xfaI\xb0w\x97#\x91\xadX\x03pP\xf2\xa7_t\xe3g\x1e\x92")},
					{"100644", "test.txt", shaFromStr("\x1fzzG*\xbf=\xd9d?\xd6\x15\xf6\xda7\x9cJ\xcb>:")},
				},
			},
		},
		{
			Fname: "tests/tree/0155eb4229851634a0f03eb265b69f5a2d56f341",
			Object: &Object{Type: TreeT, Size: 71,
				tree: []Tree{
					{"100644", "new.txt", shaFromStr("\xfaI\xb0w\x97#\x91\xadX\x03pP\xf2\xa7_t\xe3g\x1e\x92")},
					{"100644", "test.txt", shaFromStr("\x1fzzG*\xbf=\xd9d?\xd6\x15\xf6\xda7\x9cJ\xcb>:")},
				},
			},
		},

		// commit
		{
			Fname: "tests/commit/de70159e4a5842aed0aae9380e3006e909c8feb4",
			Object: &Object{Type: CommitT, Size: 165,
				commit: &Commit{
					Tree:      "d8329fc1cc938780ffdd9f94e0d364e0ea74f579",
					Author:    &Stamp{Name: "Henry", Email: "*****@*****.**", When: time.Unix(1438988455, 0)},
					Committer: &Stamp{Name: "Henry", Email: "*****@*****.**", When: time.Unix(1438988455, 0)},
					Message:   "first commit",
				},
			},
		},
		{
			Fname: "tests/commit/ad8fdc888c6f6caed63af0fb08484901e4e7e41e",
			Object: &Object{Type: CommitT, Size: 165,
				commit: &Commit{
					Tree:      "d8329fc1cc938780ffdd9f94e0d364e0ea74f579",
					Author:    &Stamp{Name: "Henry", Email: "*****@*****.**", When: time.Unix(1438995813, 0)},
					Committer: &Stamp{Name: "Henry", Email: "*****@*****.**", When: time.Unix(1438995813, 0)},
					Message:   "first commit",
				},
			},
			// TODO(cryptix): add example with Parent
		},
	}

	for _, tc := range tcases {
		f, err := os.Open(tc.Fname)
		is.Nil(err)
		obj, err := DecodeObject(f)
		is.Nil(err)
		diff := diff.Diff(obj.String(), tc.Object.String())
		is.Equal(diff, "")
		is.Nil(f.Close())
	}
}