Skip to content

Commit

Permalink
Stop serializing base file to output
Browse files Browse the repository at this point in the history
  • Loading branch information
aswinkarthik committed Apr 15, 2018
1 parent 9a0da7f commit 9e0c77f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func runDigest() {
Writer: config.GetWriter(),
}

err := digest.DigestForFile(digestConfig)
_, err := digest.Create(digestConfig)
if err != nil {
log.Fatal(err)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/digest/digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type DigestConfig struct {
Writer io.Writer
}

func DigestForFile(config DigestConfig) error {
func Create(config DigestConfig) (map[uint64]uint64, error) {
reader := csv.NewReader(config.Reader)

output := make(map[uint64]uint64)
Expand All @@ -48,12 +48,12 @@ func DigestForFile(config DigestConfig) error {
if err == io.EOF {
break
}
return err
return nil, err
}
digest := CreateDigest(line, config.KeyPositions)
output[digest.Key] = digest.Value
}

config.Encoder.Encode(output, config.Writer)
return nil
// config.Encoder.Encode(output, config.Writer)
return output, nil
}
9 changes: 5 additions & 4 deletions pkg/digest/digest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package digest

import (
"bytes"
"fmt"
"strings"
"testing"

Expand Down Expand Up @@ -41,10 +40,12 @@ func TestDigestForFile(t *testing.T) {
KeyPositions: []int{0},
}

err := DigestForFile(testConfig)
actualDigest, err := Create(testConfig)

actualDigest := outputBuffer.String()
expectedDigest := fmt.Sprintf(`{"%d":%d,"%d":%d}`, firstKey, firstDigest, secondKey, secondDigest)
//actualDigest := outputBuffer.String()
//expectedDigest := fmt.Sprintf(`{"%d":%d,"%d":%d}`, firstKey, firstDigest, secondKey, secondDigest)

expectedDigest := map[uint64]uint64{firstKey: firstDigest, secondKey: secondDigest}

assert.Nil(t, err, "error at DigestForFile")
assert.Equal(t, expectedDigest, actualDigest)
Expand Down

0 comments on commit 9e0c77f

Please sign in to comment.