Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Private data indexes with tests #109

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions cmd/release/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,16 @@ var _ = Describe("Main", func() {

indexPath := filepath.Join(tempDir, "statedb", "couchdb", "indexes", "indexOwner.json")
Expect(indexPath).To(BeARegularFile())

assetPrivateDataCollectionIndexPath := filepath.Join(tempDir, "statedb", "couchdb", "collections", "assetCollection", "indexes", "indexOwner.json")
Expect(assetPrivateDataCollectionIndexPath).To(BeARegularFile(), "Private data index should be copied")

fabCarPrivateDataCollectionIndexPath := filepath.Join(tempDir, "statedb", "couchdb", "collections", "fabCarCollection", "indexes", "indexOwner.json")
Expect(fabCarPrivateDataCollectionIndexPath).To(BeARegularFile(), "Private data index should be copied")

textPath := filepath.Join(tempDir, "statedb", "couchdb", "indexes", "test.txt")
Expect(textPath).NotTo(BeAnExistingFile())
Expect(textPath).NotTo(BeAnExistingFile(), "Unexpected files should not be copied")

subdirPath := filepath.Join(
tempDir,
"statedb",
Expand All @@ -58,6 +66,18 @@ var _ = Describe("Main", func() {
"subdir",
"indexOwner.json",
)
Expect(subdirPath).NotTo(BeAnExistingFile())
Expect(subdirPath).NotTo(BeAnExistingFile(), "Files outside indexes directory should not be copied")

privateDataCollectionSubdirPath := filepath.Join(
tempDir,
"statedb",
"couchdb",
"collections",
"fabCarCollection",
"subdir",
"indexes",
"indexOwner.json",
)
Expect(privateDataCollectionSubdirPath).NotTo(BeAnExistingFile(), "Files outside indexes directory should not be copied")
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"index": {
"fields": [
"objectType",
"owner"
]
},
"ddoc": "indexOwnerDoc",
"name": "indexOwner",
"type": "json"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"index": {
"fields": [
"model",
"owner"
]
},
"ddoc": "indexOwnerDoc",
"name": "indexOwner",
"type": "json"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"index":{"fields":["docType","owner"]},"ddoc":"indexOwnerDoc", "name":"indexOwner","type":"json"}
24 changes: 22 additions & 2 deletions internal/util/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

// CopyIndexFiles copies CouchDB index definitions from source to destination directories.
func CopyIndexFiles(logger *log.CmdLogger, src, dest string) error {
indexDir := filepath.Join("statedb", "couchdb", "indexes")
indexDir := filepath.Join("statedb", "couchdb")
indexSrcDir := filepath.Join(src, MetadataDir, indexDir)
indexDestDir := filepath.Join(dest, indexDir)

Expand All @@ -67,7 +67,27 @@

opt := copy.Options{
Skip: func(_ os.FileInfo, src, _ string) (bool, error) {
return !strings.HasSuffix(src, ".json"), nil
logger.Debugf("Checking source copy path: %s", src)
fileInfo, err := os.Lstat(src)
if err != nil {
return true, fmt.Errorf(
"failed to create CouchDB index definitions from folder %s: %w",
src,
err,
)
}
if fileInfo.IsDir() { // copy it recursively
logger.Debugf("This is a folder, copying: %s", src)
return false, nil

Check failure on line 81 in internal/util/copy.go

View workflow job for this annotation

GitHub Actions / lint

return with no blank line before (nlreturn)
} else { // any non JSON will be skipped

Check warning on line 82 in internal/util/copy.go

View workflow job for this annotation

GitHub Actions / lint

indent-error-flow: if block ends with a return statement, so drop this else and outdent its block (revive)
isJsonFile := strings.HasSuffix(src, ".json")

Check warning on line 83 in internal/util/copy.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: var isJsonFile should be isJSONFile (revive)
if isJsonFile {
logger.Debugf("This is a JSON file, copying: %s", src)
} else {
logger.Debugf("This is NOT a JSON file, skipping copy: %s", src)
}
return !isJsonFile, nil

Check failure on line 89 in internal/util/copy.go

View workflow job for this annotation

GitHub Actions / lint

return with no blank line before (nlreturn)
}
},
}

Expand Down
Loading