From 9e0c77f644e6b42b4fc8845bcda819979d75a662 Mon Sep 17 00:00:00 2001 From: aswinkarthik93 Date: Sun, 15 Apr 2018 16:12:43 +0530 Subject: [PATCH] Stop serializing base file to output --- cmd/digest.go | 2 +- pkg/digest/digest.go | 8 ++++---- pkg/digest/digest_test.go | 9 +++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/cmd/digest.go b/cmd/digest.go index 9c185b2..49d68d6 100644 --- a/cmd/digest.go +++ b/cmd/digest.go @@ -50,7 +50,7 @@ func runDigest() { Writer: config.GetWriter(), } - err := digest.DigestForFile(digestConfig) + _, err := digest.Create(digestConfig) if err != nil { log.Fatal(err) } diff --git a/pkg/digest/digest.go b/pkg/digest/digest.go index 59b13e6..3bb3cb9 100644 --- a/pkg/digest/digest.go +++ b/pkg/digest/digest.go @@ -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) @@ -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 } diff --git a/pkg/digest/digest_test.go b/pkg/digest/digest_test.go index 1a8dbb1..8530098 100644 --- a/pkg/digest/digest_test.go +++ b/pkg/digest/digest_test.go @@ -2,7 +2,6 @@ package digest import ( "bytes" - "fmt" "strings" "testing" @@ -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)