-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package ldsview | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
) | ||
|
||
// CountEntities returns the number of entities in the input file | ||
func (parser LdifParser) CountEntities() (count int, err error) { | ||
Logger.Info("Opening ldif file: " + parser.filename) | ||
dumpFile, err := os.Open(parser.filename) | ||
if err != nil { | ||
return | ||
} | ||
defer dumpFile.Close() | ||
|
||
Logger.Info("Finding first entity block") | ||
entityScanner := parser.findFirstEntityBlock(dumpFile) | ||
if entityScanner == nil { | ||
return count, errors.New("Unable to find first entity block") | ||
} | ||
|
||
for entityScanner.Scan() { | ||
titleLine := entityScanner.Text() | ||
if parser.isEntityTitle(titleLine) { | ||
count++ | ||
} | ||
} | ||
|
||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package ldsview | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestLdifParser_CountEntities(t *testing.T) { | ||
a := assert.New(t) | ||
|
||
parser := NewLdifParser(TESTFILE) | ||
a.NotNil(parser) | ||
|
||
count, err := parser.CountEntities() | ||
a.NoError(err) | ||
a.Equal(count, NUMENTITIES) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
package ldsview | ||
|
||
const TESTFILE = "../testdata/test_users.ldif" | ||
const NUMENTITIES = 3 |