Merge pull request #45 from Paulius-Maruska/bug/crash-without-handlers
Fixes #44, crash when no handlers
This commit is contained in:
		
						commit
						3d199df8a0
					
				
					 2 changed files with 15 additions and 2 deletions
				
			
		
							
								
								
									
										4
									
								
								feed.go
									
										
									
									
									
								
							
							
						
						
									
										4
									
								
								feed.go
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -46,14 +46,18 @@ func (err *UnsupportedFeedError) Error() string {
 | 
			
		|||
type ChannelHandlerFunc func(f *Feed, newchannels []*Channel)
 | 
			
		||||
 | 
			
		||||
func (h ChannelHandlerFunc) ProcessChannels(f *Feed, newchannels []*Channel) {
 | 
			
		||||
	if h != nil {
 | 
			
		||||
		h(f, newchannels)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type ItemHandlerFunc func(f *Feed, ch *Channel, newitems []*Item)
 | 
			
		||||
 | 
			
		||||
func (h ItemHandlerFunc) ProcessItems(f *Feed, ch *Channel, newitems []*Item) {
 | 
			
		||||
	if h != nil {
 | 
			
		||||
		h(f, ch, newitems)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type Handler interface {
 | 
			
		||||
	ChannelHandler
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -29,6 +29,15 @@ func TestFeed(t *testing.T) {
 | 
			
		|||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func Test_NoHandlers(t *testing.T) {
 | 
			
		||||
	feed := New(1, true, nil, nil)
 | 
			
		||||
	content, _ := ioutil.ReadFile("testdata/initial.atom")
 | 
			
		||||
	err := feed.FetchBytes("http://example.com", content, nil)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Error(err)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func Test_NewItem(t *testing.T) {
 | 
			
		||||
	content, _ := ioutil.ReadFile("testdata/initial.atom")
 | 
			
		||||
	feed := New(1, true, chanHandler, itemHandler)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue