コード例 #1
0
ファイル: eos_test.go プロジェクト: itchio/wharf
func Test_OpenRemoteDownloadBuild(t *testing.T) {
	fakeData := []byte("aaaabbbb")

	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("content-length", fmt.Sprintf("%d", len(fakeData)))
		w.WriteHeader(200)
		w.Write(fakeData)
	}))
	defer server.CloseClientConnections()

	tfs := &testfs{server.URL}
	assert.NoError(t, RegisterHandler(tfs))
	assert.Error(t, RegisterHandler(tfs))
	defer DeregisterHandler(tfs)

	f, err := Open("nofs:///not-quite")
	assert.Error(t, err)

	f, err = Open("testfs:///now/we/are/talking")
	assert.NoError(t, err)

	stats, err := f.Stat()
	assert.NoError(t, err)

	assert.EqualValues(t, len(fakeData), stats.Size())
	assert.NoError(t, f.Close())
}
コード例 #2
0
ファイル: compression_test.go プロジェクト: itchio/wharf
func Test_Compression(t *testing.T) {
	fc := &fakeCompressor{}
	RegisterCompressor(CompressionAlgorithm_GZIP, fc)

	fd := &fakeDecompressor{}
	RegisterDecompressor(CompressionAlgorithm_GZIP, fd)

	assert.EqualValues(t, false, fc.called)

	buf := new(bytes.Buffer)
	wc := wire.NewWriteContext(buf)
	_, err := CompressWire(wc, &CompressionSettings{
		Algorithm: CompressionAlgorithm_BROTLI,
		Quality:   3,
	})
	assert.NotNil(t, err)

	cwc, err := CompressWire(wc, &CompressionSettings{
		Algorithm: CompressionAlgorithm_GZIP,
		Quality:   3,
	})
	assert.NoError(t, err)

	assert.EqualValues(t, true, fc.called)
	assert.EqualValues(t, 3, fc.quality)

	assert.NoError(t, cwc.WriteMessage(&SyncHeader{
		FileIndex: 672,
	}))

	rc := wire.NewReadContext(bytes.NewReader(buf.Bytes()))

	sh := &SyncHeader{}
	assert.NoError(t, rc.ReadMessage(sh))

	assert.EqualValues(t, 672, sh.FileIndex)
	assert.NotNil(t, rc.ReadMessage(sh))
}
コード例 #3
0
ファイル: eos_test.go プロジェクト: itchio/wharf
func Test_HttpFile(t *testing.T) {
	fakeData := []byte("aaaabbbb")

	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("content-length", fmt.Sprintf("%d", len(fakeData)))
		w.WriteHeader(200)
		w.Write(fakeData)
	}))
	defer server.CloseClientConnections()

	f, err := Open(server.URL)
	assert.NoError(t, err)

	s, err := f.Stat()
	assert.NoError(t, err)
	assert.EqualValues(t, len(fakeData), s.Size())

	readData, err := ioutil.ReadAll(f)
	assert.NoError(t, err)
	assert.EqualValues(t, fakeData, readData)

	assert.NoError(t, f.Close())
}
コード例 #4
0
ファイル: eos_test.go プロジェクト: itchio/wharf
func Test_OpenEmptyFile(t *testing.T) {
	f, err := Open("/dev/null")
	assert.NoError(t, err)

	s, err := f.Stat()
	assert.NoError(t, err)

	assert.EqualValues(t, 0, s.Size())
	assert.False(t, s.IsDir())
	assert.EqualValues(t, "/dev/null", s.Name())
	assert.Nil(t, s.Sys())
	assert.EqualValues(t, 0644, s.Mode())
	assert.EqualValues(t, time.Time{}, s.ModTime())

	buf := make([]byte, 1)

	_, err = f.Read(buf)
	assert.Error(t, err)

	_, err = f.ReadAt(buf, 0)
	assert.Error(t, err)

	assert.NoError(t, f.Close())
}
コード例 #5
0
ファイル: eos_test.go プロジェクト: itchio/wharf
func Test_OpenLocalFile(t *testing.T) {
	mainDir, err := ioutil.TempDir("", "eos-local")
	assert.NoError(t, err)
	defer os.RemoveAll(mainDir)

	assert.NoError(t, os.MkdirAll(mainDir, 0755))

	fileName := filepath.Join(mainDir, "some-file")
	assert.NoError(t, ioutil.WriteFile(fileName, []byte{4, 2, 6, 9}, 0644))

	f, err := Open(fileName)
	assert.NoError(t, err)

	s, err := f.Stat()
	assert.NoError(t, err)

	assert.EqualValues(t, 4, s.Size())
	assert.NoError(t, f.Close())
}