Skip to content

Commit

Permalink
Merge pull request #53 from brotherlogic/branching
Browse files Browse the repository at this point in the history
Cleaned up tests to pass
  • Loading branch information
brotherlogic committed Dec 29, 2018
2 parents 35ae134 + b0ca6c9 commit 4ab40df
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: go

go:
- 1.7
- 1.9

branches:
only:
Expand Down
2 changes: 1 addition & 1 deletion cdprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (rc *prodGetter) updateRecord(ctx context.Context, rec *pbrc.Record) {
defer cancel()
client := pbrc.NewRecordCollectionServiceClient(conn)
_, err = client.UpdateRecord(ctx, &pbrc.UpdateRecordRequest{Update: rec})
rc.log(fmt.Sprintf("Error: (%v) - %v", rec.GetRelease().Id, err))
rc.log(fmt.Sprintf("Updated %v (%v)", rec.GetRelease().Id, err))
}

type gh interface {
Expand Down
9 changes: 4 additions & 5 deletions cdprocessorapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io/ioutil"
"log"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -53,12 +52,10 @@ func (i *testIo) readDir() ([]os.FileInfo, error) {
return make([]os.FileInfo, 0), fmt.Errorf("Build to fail")
}

log.Printf("WHAT: %v", i.dir)
return ioutil.ReadDir(i.dir)
}

func (i *testIo) convert(name string) (int32, error) {
log.Printf("HERE: %v", name)
if i.failConv {
return -1, fmt.Errorf("Build to fail")
}
Expand Down Expand Up @@ -117,8 +114,10 @@ func TestGetMissing(t *testing.T) {
t.Fatalf("Error getting missing: %v", err)
}

if len(missing.GetMissing()) != 3 || missing.GetMissing()[0].GetRelease().Id != 12346 {
t.Errorf("Rips reported missing: %v", missing)
if len(missing.GetMissing()) != 6 || missing.GetMissing()[0].GetRelease().Id != 12346 {
for i := range missing.GetMissing() {
t.Errorf("%v. Missing: %v", i, missing.GetMissing()[i].GetRelease().Id)
}
}
}

Expand Down
5 changes: 2 additions & 3 deletions cdprocessorutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func (s *Server) adjustExisting(ctx context.Context) {
return
}

s.adjust = 0
for _, r := range m.Ripped {
rec, err := s.getter.getRecord(ctx, r.Id)
if err != nil {
Expand All @@ -28,10 +27,10 @@ func (s *Server) adjustExisting(ctx context.Context) {
s.RaiseIssue(ctx, "Nil Record Fail", fmt.Sprintf("Nil record?: %v -> %v", r.Id, err), false)
}
} else {
if rec.GetMetadata().FilePath != r.Path {
if rec.GetMetadata().FilePath == "" {
rec.GetMetadata().FilePath = r.Path
s.getter.updateRecord(ctx, rec)
s.adjust = 1
s.adjust++
break
}
}
Expand Down
48 changes: 36 additions & 12 deletions cdprocessorutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,38 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

pbgd "github.com/brotherlogic/godiscogs"
pbrc "github.com/brotherlogic/recordcollection/proto"
)

type testGetter struct {
fail bool
updates int
fail bool
updates int
adjusted map[int32]bool
}

func (t *testGetter) getRecord(ctx context.Context, id int32) (*pbrc.Record, error) {
if t.fail {
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("Built to fail"))
}
return &pbrc.Record{Metadata: &pbrc.ReleaseMetadata{FilePath: ""}}, nil
filepath := ""
if t.adjusted[id] {
filepath = fmt.Sprintf("%v", id)
}
return &pbrc.Record{Release: &pbgd.Release{Id: id}, Metadata: &pbrc.ReleaseMetadata{FilePath: filepath}}, nil
}

func (t *testGetter) updateRecord(ctx context.Context, rec *pbrc.Record) {
t.updates++
if t.adjusted == nil {
t.adjusted = make(map[int32]bool)
}
t.adjusted[rec.GetRelease().Id] = true
}

func InitTestServer() *Server {
s := Init("testdata")
s.io = &testIo{dir: "testdata"}
func InitTestServer(dir string) *Server {
s := Init(dir)
s.io = &testIo{dir: dir}
s.rc = &testRc{}
gh := &testGh{}
s.gh = gh
Expand All @@ -38,7 +48,7 @@ func InitTestServer() *Server {
}

func TestAdjust(t *testing.T) {
s := InitTestServer()
s := InitTestServer("testdata")
tg := &testGetter{}
s.getter = tg

Expand All @@ -50,7 +60,7 @@ func TestAdjust(t *testing.T) {
}

func TestAdjustFail(t *testing.T) {
s := InitTestServer()
s := InitTestServer("testdata")
tg := &testGetter{}
s.io = &testIo{failRead: true}
s.getter = tg
Expand All @@ -63,7 +73,7 @@ func TestAdjustFail(t *testing.T) {
}

func TestAdjustFailOnFailedGet(t *testing.T) {
s := InitTestServer()
s := InitTestServer("testdata")
tg := &testGetter{fail: true}
s.io = &testIo{dir: "testdata"}
s.getter = tg
Expand All @@ -76,7 +86,7 @@ func TestAdjustFailOnFailedGet(t *testing.T) {
}

func TestLogMissing(t *testing.T) {
s := Init("testdata")
s := InitTestServer("testdata")
s.io = &testIo{dir: "testdata"}
s.rc = &testRc{}
gh := &testGh{}
Expand All @@ -91,7 +101,7 @@ func TestLogMissing(t *testing.T) {
}

func TestLogMissingFailOnMissing(t *testing.T) {
s := Init("testdata")
s := InitTestServer("testdata")
s.io = &testIo{dir: "testdata", failRead: true}
s.rc = &testRc{}
gh := &testGh{}
Expand All @@ -107,7 +117,7 @@ func TestLogMissingFailOnMissing(t *testing.T) {
}

func TestLogMissingFailOnBadLog(t *testing.T) {
s := Init("testdata")
s := InitTestServer("testdata")
s.io = &testIo{dir: "testdata"}
s.rc = &testRc{}
gh := &testGh{fail: true}
Expand All @@ -121,3 +131,17 @@ func TestLogMissingFailOnBadLog(t *testing.T) {
}

}

func TestMultiAdjustPasses(t *testing.T) {
s := InitTestServer("testmulti")
getter := &testGetter{adjusted: make(map[int32]bool)}
s.getter = getter

for i := 0; i < 3; i++ {
s.adjustExisting(context.Background())
}

if len(getter.adjusted) != 2 {
t.Errorf("Not enough records have been adjusted: %v", getter.adjusted)
}
}
1 change: 1 addition & 0 deletions testmulti/12345_1/madeup.wav
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
madeup
1 change: 1 addition & 0 deletions testmulti/12345_2/madeup.wav
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
madeup
1 change: 1 addition & 0 deletions testmulti/12346/madeup.wav
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
madeup

0 comments on commit 4ab40df

Please sign in to comment.