mirror of
https://github.com/hanzoai/graph.git
synced 2026-10-30 18:35:37 +00:00
Derived from Dgraph (github.com/dgraph-io/dgraph) at commit 64804bd2, Apache-2.0. See NOTICE. WHAT THIS IS. The graph engine as a Go library: posting lists, the DQL parser, the type and tokenizer system, the index and schema layers, and the wire types. 39,170 lines of the upstream's 166,337. THE STORE is github.com/luxfi/zapdb, a Badger fork that kept the package name, the subpackages (options, pb, y) and the API — Open, OpenManaged, DB, Options — so the 74 import sites are aliased rather than rewritten. THE CODEC is ZAP. zapdb serializes with ZAP, not protobuf: its pb package builds the ZAP types by default and the protobuf ones only under `-tags grpc`, a path that does not compile (table/builder.go calls pb.Marshal, which that tag removes). One call site in posting needed converting; every other type here is Hanzo's own protobuf and is untouched. NO TRANSPORT. An embedded engine dials nothing, so nothing here imports google.golang.org/grpc. Removed: 20 transport functions in x, the generated service stubs for Raft, Zero and Worker (1,657 lines), and the JWT helper — identity belongs to IAM. The core called none of them. NOT KEPT: worker, conn, raftwal, the cluster commands, the GraphQL layer and the test harnesses. `query`, the DQL execution engine, went with them because it depends on worker; parsing DQL is available here, executing it is not. The history of the upstream project lives at github.com/dgraph-io/dgraph. This repository begins at the derivation because three quarters of that history describes code this fork does not carry.
96 lines
2.7 KiB
Go
96 lines
2.7 KiB
Go
/*
|
|
* SPDX-FileCopyrightText: © 2017-2026 Istari Digital, Inc.
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
package x
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestFindDataFiles(t *testing.T) {
|
|
_, thisFile, _, _ := runtime.Caller(0)
|
|
dir := [2]string{"test-files-valid", "test-files-invalid"}
|
|
require.NoError(t, os.MkdirAll(dir[0], os.ModePerm))
|
|
require.NoError(t, os.MkdirAll(dir[1], os.ModePerm))
|
|
defer deleteDirs(t, dir[0])
|
|
defer deleteDirs(t, dir[1])
|
|
validTestFiles := filepath.Join(filepath.Dir(thisFile), "test-files-valid")
|
|
invalidTestFiles := filepath.Join(filepath.Dir(thisFile), "test-files-invalid")
|
|
expectedFilesArray := []string{
|
|
"test-files-valid/test-2.rdf.gz",
|
|
"test-files-valid/test-3.json",
|
|
"test-files-valid/test-4.json.gz",
|
|
}
|
|
file_data := [7]string{
|
|
"test-1.txt",
|
|
"test-2.rdf.gz",
|
|
"test-3.json",
|
|
"test-4.json.gz",
|
|
"test-5.txt",
|
|
"test-6.txt.gz",
|
|
"test-7.go",
|
|
}
|
|
|
|
for i, data := range file_data {
|
|
var filePath string
|
|
|
|
if i <= 4 {
|
|
filePath = filepath.Join(validTestFiles, data)
|
|
} else {
|
|
filePath = filepath.Join(invalidTestFiles, data)
|
|
}
|
|
f, err := os.Create(filePath)
|
|
require.NoError(t, err)
|
|
defer f.Close()
|
|
}
|
|
filesList := FindDataFiles("./test-files-valid", []string{".rdf", ".rdf.gz", ".json", ".json.gz"})
|
|
require.Equal(t, expectedFilesArray, filesList)
|
|
|
|
filesList = FindDataFiles(invalidTestFiles, []string{".rdf", ".rdf.gz", ".json", ".json.gz"})
|
|
require.Equal(t, 0, len(filesList))
|
|
|
|
filesList = FindDataFiles("", []string{".rdf", ".rdf.gz", ".json", ".json.gz"})
|
|
require.Equal(t, 0, len(filesList))
|
|
}
|
|
|
|
func TestIsMissingOrEmptyDir(t *testing.T) {
|
|
_, thisFile, _, _ := runtime.Caller(0)
|
|
dir := "test-files"
|
|
require.NoError(t, os.MkdirAll(dir, os.ModePerm))
|
|
defer deleteDirs(t, dir)
|
|
testFilesDir := filepath.Join(filepath.Dir(thisFile), "test-files")
|
|
file_data := [2]string{"test-1.txt", "test-2.txt"}
|
|
for _, data := range file_data {
|
|
filePath := filepath.Join(testFilesDir, data)
|
|
f, err := os.Create(filePath)
|
|
require.NoError(t, err)
|
|
defer f.Close()
|
|
}
|
|
//checking function with file which exist
|
|
output := IsMissingOrEmptyDir("./test-files/test-1.txt")
|
|
require.Equal(t, nil, output)
|
|
//checking function with file which does not exist
|
|
output = IsMissingOrEmptyDir("./test-files/doesnotexist.txt")
|
|
require.NotEqual(t, nil, output)
|
|
//checking function with directory which exist
|
|
output = IsMissingOrEmptyDir("./test-files")
|
|
require.Equal(t, nil, output)
|
|
//checking function with directory which does not exist
|
|
output = IsMissingOrEmptyDir("./doesnotexist")
|
|
require.NotEqual(t, nil, output)
|
|
}
|
|
|
|
func deleteDirs(t *testing.T, dir string) {
|
|
if err := os.RemoveAll(dir); err != nil {
|
|
fmt.Printf("Error removing direcotory: %s", err.Error())
|
|
}
|
|
}
|