Exemplo n.º 1
0
func TestNoArticles(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()

	mockClient := mediawiki.NewMockClient(mockCtrl)
	mockClient.EXPECT().ListArticleTitles().Return([]string{}, nil)

	err := export(mockClient, "outputFolder", nil)
	if err == nil {
		t.Errorf("Should have failed on no names")
	}
}
Exemplo n.º 2
0
func TestDuplicateNames(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()

	mockClient := mediawiki.NewMockClient(mockCtrl)
	mockClient.EXPECT().ListArticleTitles().Return([]string{
		"FirstArticle",
		"SecondArticle",
		"Third One",
		"Third_One",
	}, nil)

	err := export(mockClient, "outputFolder", nil)
	if err == nil {
		t.Errorf("Should have failed on duplicate names")
	}
}
Exemplo n.º 3
0
func TestExport(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()

	mockClient := mediawiki.NewMockClient(mockCtrl)
	mockClient.EXPECT().ListArticleTitles().Return([]string{
		"FirstArticle",
		"SecondArticle",
	}, nil)

	mockClient.EXPECT().GetArticle("FirstArticle").Return("This is the first article", nil)
	mockClient.EXPECT().GetArticle("SecondArticle").Return("This is the second article", nil)

	mockFileSystem := NewMockfileSystem(mockCtrl)
	fileMode := os.FileMode(0644)
	mockFileSystem.EXPECT().WriteFile("FirstArticle.txt", []byte("This is the first article"), fileMode).Return(nil)
	mockFileSystem.EXPECT().WriteFile("SecondArticle.txt", []byte("This is the second article"), fileMode).Return(nil)

	err := export(mockClient, "outputFolder", mockFileSystem)
	if err != nil {
		t.Errorf("Unexpected error: %v", err)
	}
}