Skip to content

Commit 87586cd

Browse files
author
JojiiOfficial
committed
add tests
rename dmfsRoot
1 parent 43ca871 commit 87586cd

File tree

5 files changed

+42
-7
lines changed

5 files changed

+42
-7
lines changed

dmfs/dmfs_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package dmfs
2+
3+
import (
4+
"testing"
5+
6+
"github.com/DataManager-Go/libdatamanager"
7+
)
8+
9+
const (
10+
defaultNsFull = "jojii_default"
11+
defaultNsTimmed = "default"
12+
)
13+
14+
var (
15+
cfg = libdatamanager.RequestConfig{Username: "jojii"}
16+
)
17+
18+
func TestAddNSName(t *testing.T) {
19+
newNsName := addNsName(defaultNsTimmed, &cfg)
20+
21+
if newNsName != defaultNsFull {
22+
t.Errorf("Expected %s but got %s", defaultNsFull, newNsName)
23+
}
24+
}
25+
26+
func TestRemoveNSName(t *testing.T) {
27+
newNsName := removeNsName(defaultNsFull)
28+
29+
if newNsName != defaultNsTimmed {
30+
t.Errorf("Expected %s but got %s", defaultNsTimmed, newNsName)
31+
}
32+
}

dmfs/fsFile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type fileInode struct {
1717

1818
var _ = (fs.NodeGetattrer)((*fileInode)(nil))
1919

20-
// Set attributes for files
20+
// Set file attributes
2121
func (fnode *fileInode) Getattr(ctx context.Context, f fs.FileHandle, out *fuse.AttrOut) syscall.Errno {
2222
out.Size = uint64(fnode.file.Size)
2323
out.Ctime = uint64(fnode.file.CreationDate.Unix())

dmfs/fsGroup.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ type groupInode struct {
1919

2020
var _ = (fs.NodeOnAdder)((*groupInode)(nil))
2121

22+
// List files
2223
func (groupInode *groupInode) OnAdd(ctx context.Context) {
24+
fmt.Println("add group")
2325
groupAdd := []string{groupInode.group}
2426

2527
if len(groupAdd) == 1 && groupAdd[0] == "no_group" {

dmfs/dmfsRoot.go renamed to dmfs/fsRoot.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
/*
1616
* the root fs is supposed to load and interact
1717
* with the namespaces and to show them as directories
18+
* Hierarchy: fsRoot -> fsNamespace -> fsGroup -> fsFile
1819
*/
1920

2021
type rootNode struct {
@@ -93,7 +94,7 @@ func (root *rootNode) load(nsCB func(name string)) error {
9394

9495
// Loop Namespaces and add childs in as folders
9596
for _, namespace := range data.userAttributes.Namespace {
96-
nsName := removeNSName(namespace.Name)
97+
nsName := removeNsName(namespace.Name)
9798

9899
// Find namespace node
99100
v, has := root.nsNodes[nsName]
@@ -136,7 +137,7 @@ func (root *rootNode) Lookup(ctx context.Context, name string, out *fuse.EntryOu
136137

137138
// Delete Namespace if virtual file was unlinked
138139
func (root *rootNode) Rmdir(ctx context.Context, name string) syscall.Errno {
139-
namespace := addNSName(name, data.libdm.Config)
140+
namespace := addNsName(name, data.libdm.Config)
140141

141142
// wait 2 seconds to ensure, user didn't cancel
142143
select {
@@ -163,8 +164,8 @@ func (root *rootNode) Rename(ctx context.Context, name string, newParent fs.Inod
163164
}
164165

165166
// Get real namespace names
166-
oldNSName := addNSName(name, data.libdm.Config)
167-
newNSName := addNSName(newName, data.libdm.Config)
167+
oldNSName := addNsName(name, data.libdm.Config)
168+
newNSName := addNsName(newName, data.libdm.Config)
168169
root.debug("rename namespace", oldNSName, "->", newNSName)
169170

170171
// Make rename request

dmfs/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import (
66
libdm "github.com/DataManager-Go/libdatamanager"
77
)
88

9-
func removeNSName(ns string) string {
9+
func removeNsName(ns string) string {
1010
if !strings.Contains(ns, "_") {
1111
return ns
1212
}
1313

1414
return ns[strings.Index(ns, "_")+1:]
1515
}
1616

17-
func addNSName(ns string, libdm *libdm.RequestConfig) string {
17+
func addNsName(ns string, libdm *libdm.RequestConfig) string {
1818
userPrefix := libdm.Username + "_"
1919
if strings.HasPrefix(ns, userPrefix) {
2020
return ns

0 commit comments

Comments
 (0)