func TestFileServeHandler(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)
	data := "Been there, done that!"
	// Setup the test file.
	dir, err := ioutil.TempDir("", "gorest")
	assert.Nil(err)
	defer os.RemoveAll(dir)
	filename := filepath.Join(dir, "foo.txt")
	f, err := os.Create(filename)
	assert.Nil(err)
	_, err = f.WriteString(data)
	assert.Nil(err)
	assert.Logf("written %s", f.Name())
	err = f.Close()
	assert.Nil(err)
	// Setup the test server.
	mux := newMultiplexer(assert)
	ts := restaudit.StartServer(mux, assert)
	defer ts.Close()
	err = mux.Register("test", "files", handlers.NewFileServeHandler("files", dir))
	assert.Nil(err)
	// Perform test requests.
	req := restaudit.NewRequest("GET", "/test/files/foo.txt")
	resp := ts.DoRequest(req)
	resp.AssertBodyContains(data)
	req = restaudit.NewRequest("GET", "/test/files/does.not.exist")
	resp = ts.DoRequest(req)
	resp.AssertBodyContains("404 page not found")
}
// TestFileServeHandler tests the serving of files.
TestFileServeHandler tests the serving of files.
// TestFileServeHandler tests the serving of files .
func TestFileServeHandler(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)
	data := "Been there, done that!"
	dir, err := ioutil.TempDir("", "gorest")
	assert.Nil(err)
	defer os.RemoveAll(dir)
	filename := filepath.Join(dir, "foo.txt")
	f, err := os.Create(filename)
	assert.Nil(err)
	_, err = f.WriteString(data)
	assert.Nil(err)
	assert.Logf("written %s", f.Name())
	err = f.Close()
	assert.Nil(err)
	mux := newMultiplexer(assert)
	ts := restaudit.StartServer(mux, assert)
	defer ts.Close()
	err = mux.Register("test", "files", handlers.NewFileServeHandler("files", dir))
	assert.Nil(err)
	req := restaudit.NewRequest("GET", "/test/files/foo.txt")
	resp := ts.DoRequest(req)
	resp.AssertBodyContains(data)
	req = restaudit.NewRequest("GET", "/test/files/does.not.exist")
	resp = ts.DoRequest(req)
	resp.AssertBodyContains("404 page not found")
}
func TestFileServeHandler ( t * testing . T ) { assert := audit . NewTestingAssertion ( t , true ) data := " " dir , err := ioutil . TempDir ( " " , " " ) assert . Nil ( err ) defer os . RemoveAll ( dir ) filename := filepath . Join ( dir , " " ) f , err := os . Create ( filename ) assert . Nil ( err ) _ , err = f . WriteString ( data ) assert . Nil ( err ) assert . Logf ( " " , f . Name ( ) ) err = f . Close ( ) assert . Nil ( err ) mux := newMultiplexer ( assert ) ts := restaudit . StartServer ( mux , assert ) defer ts . Close ( ) err = mux . Register ( " " , " " , handlers . NewFileServeHandler ( " " , dir ) ) assert . Nil ( err ) req := restaudit . NewRequest ( " " , " " ) resp := ts . DoRequest ( req ) resp . AssertBodyContains ( data ) req = restaudit . NewRequest ( " " , " " ) resp = ts . DoRequest ( req ) resp . AssertBodyContains ( " " ) }
TestFileServeHandler tests the serving of files.
TestFileServeHandler tests the serving of files .
// Setup the test file. // Setup the test server. // Perform test requests.