Skip to content

Commit

Permalink
Merge pull request #9 from gadget-inc/tighten_remove_cte
Browse files Browse the repository at this point in the history
Tighten remove object CTE
  • Loading branch information
angelini authored Oct 4, 2022
2 parents b721089 + e6d3304 commit 082bd24
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/db/queryBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (qb *queryBuilder) removedObjectsCTE() string {
SELECT o.path, o.mode, 0 AS size, ''::bytea as bytes, o.packed, true AS deleted, null::hash as hash
FROM possible_objects o
WHERE o.project = __project__
AND o.start_version <= __stop_version__
AND o.start_version <= __start_version__
AND o.stop_version > __start_version__
AND o.stop_version <= __stop_version__
%s
Expand Down
38 changes: 38 additions & 0 deletions test/client_rebuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,41 @@ func TestRebuildWithManyObjects(t *testing.T) {

verifyDir(t, tmpDir, 1, expectedFiles)
}

func TestRebuildWithUpdatedObjectToDirectory(t *testing.T) {
tc := util.NewTestCtx(t, auth.Project, 1)
defer tc.Close()

writeProject(tc, 1, 4)
writeObject(tc, 1, 1, nil, "a", "a v1")
writeObject(tc, 1, 2, i(3), "b", "b v2")
writeObject(tc, 1, 3, i(4), "b/c", "b/c v3")
writeObject(tc, 1, 3, nil, "b/d", "b/d v3")
writeObject(tc, 1, 4, nil, "b/e", "b/e v4")

c, _, close := createTestClient(tc)
defer close()

tmpDir := emptyTmpDir(t)
defer os.RemoveAll(tmpDir)

rebuild(tc, c, 1, i(1), tmpDir, expectedResponse{
version: 1,
count: 1,
})

verifyDir(t, tmpDir, 1, map[string]expectedFile{
"a": {content: "a v1"},
})

rebuild(tc, c, 1, nil, tmpDir, expectedResponse{
version: 4,
count: 2,
})

verifyDir(t, tmpDir, 4, map[string]expectedFile{
"a": {content: "a v1"},
"b/d": {content: "b/d v3"},
"b/e": {content: "b/e v4"},
})
}

0 comments on commit 082bd24

Please sign in to comment.