Skip to content

Commit 64cd5db

Browse files
authored
Merge pull request #121 from markusressel/feature/dynamic-data-loading
Feature/dynamic data loading
2 parents 9efe646 + 7e846fc commit 64cd5db

32 files changed

Lines changed: 1486 additions & 547 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea
22
bin
3-
dist
3+
dist
4+
coverage.out

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ VERSION ?= 0.7.0
1010
test: ## Run all tests
1111
@go clean --testcache && go test -v ./...
1212

13+
coverage: ## Run all tests with coverage and show summary
14+
@go test -coverprofile=coverage.out ./...
15+
@go tool cover -func=coverage.out
16+
17+
coverage-html: ## Run all tests with coverage and open HTML report
18+
@go test -coverprofile=coverage.out ./...
19+
@go tool cover -html=coverage.out
20+
1321
build: ## Builds the CLI
1422
@go build ${GO_FLAGS} \
1523
-ldflags "-w -s \

internal/configuration/validation_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
package configuration
22

3-
import "testing"
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestValidate(t *testing.T) {
10+
// Save original
11+
original := CurrentConfig
12+
defer func() { CurrentConfig = original }()
13+
14+
CurrentConfig = Configuration{
15+
FileBrowser: FileBrowserConfig{Permissions: FileBrowserPermissionsFormatOctal, Owner: FileBrowserOwnerFormatID},
16+
}
17+
18+
err := Validate("test.yaml")
19+
assert.NoError(t, err)
20+
}
421

522
func TestValidateConfig(t *testing.T) {
623
t.Parallel()
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package data
2+
3+
import (
4+
"testing"
5+
"zfs-file-history/internal/data/diff_state"
6+
"zfs-file-history/internal/zfs"
7+
8+
"github.com/stretchr/testify/assert"
9+
)
10+
11+
func TestFileBrowserEntry_HasReal(t *testing.T) {
12+
entry := &FileBrowserEntry{
13+
RealFile: &RealFile{Path: "/foo"},
14+
}
15+
assert.True(t, entry.HasReal())
16+
17+
entry = &FileBrowserEntry{
18+
RealFile: nil,
19+
}
20+
assert.False(t, entry.HasReal())
21+
}
22+
23+
func TestFileBrowserEntry_HasSnapshot(t *testing.T) {
24+
entry := &FileBrowserEntry{
25+
SnapshotFiles: []*SnapshotFile{{Path: "/foo"}},
26+
}
27+
assert.True(t, entry.HasSnapshot())
28+
29+
entry = &FileBrowserEntry{
30+
SnapshotFiles: []*SnapshotFile{},
31+
}
32+
assert.False(t, entry.HasSnapshot())
33+
}
34+
35+
func TestFileBrowserEntry_GetRealPath(t *testing.T) {
36+
realFile := &RealFile{Path: "/real/path"}
37+
snapshotFile := &SnapshotFile{OriginalPath: "/original/path"}
38+
39+
entry := &FileBrowserEntry{
40+
RealFile: realFile,
41+
}
42+
assert.Equal(t, "/real/path", entry.GetRealPath())
43+
44+
entry = &FileBrowserEntry{
45+
RealFile: nil,
46+
SnapshotFiles: []*SnapshotFile{snapshotFile},
47+
}
48+
assert.Equal(t, "/original/path", entry.GetRealPath())
49+
}
50+
51+
func TestFileBrowserEntry_Equal(t *testing.T) {
52+
e1 := FileBrowserEntry{RealFile: &RealFile{Path: "/foo"}}
53+
e2 := FileBrowserEntry{RealFile: &RealFile{Path: "/foo"}}
54+
e3 := FileBrowserEntry{RealFile: &RealFile{Path: "/bar"}}
55+
56+
assert.True(t, e1.Equal(e2))
57+
assert.False(t, e1.Equal(e3))
58+
}
59+
60+
func TestFileBrowserEntry_HasDiff(t *testing.T) {
61+
entry := &FileBrowserEntry{
62+
DiffState: diff_state.Modified,
63+
SnapshotFiles: []*SnapshotFile{{Path: "/foo"}},
64+
}
65+
assert.True(t, entry.HasDiff())
66+
67+
entry.DiffState = diff_state.Equal
68+
assert.False(t, entry.HasDiff())
69+
70+
entry.DiffState = diff_state.Modified
71+
entry.SnapshotFiles = nil
72+
assert.False(t, entry.HasDiff())
73+
}
74+
75+
func TestFileBrowserEntry_TableRowId(t *testing.T) {
76+
entry := FileBrowserEntry{RealFile: &RealFile{Path: "/foo"}}
77+
assert.Equal(t, "/foo", entry.TableRowId())
78+
}
79+
80+
func TestRealFile_Equal(t *testing.T) {
81+
f1 := RealFile{Name: "a", Path: "p"}
82+
f2 := RealFile{Name: "a", Path: "p"}
83+
f3 := RealFile{Name: "b", Path: "p"}
84+
85+
assert.True(t, f1.Equal(f2))
86+
assert.False(t, f1.Equal(f3))
87+
}
88+
89+
func TestSnapshotFile_Equal(t *testing.T) {
90+
snap := &zfs.Snapshot{}
91+
f1 := SnapshotFile{Path: "p", OriginalPath: "o", Snapshot: snap}
92+
f2 := SnapshotFile{Path: "p", OriginalPath: "o", Snapshot: snap}
93+
f3 := SnapshotFile{Path: "p2", OriginalPath: "o", Snapshot: snap}
94+
95+
assert.True(t, f1.Equal(f2))
96+
assert.False(t, f1.Equal(f3))
97+
}

internal/ui/actor.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ import (
1212
// AddActor wires ZFS preload and UI lifecycle into the application run group.
1313
func AddActor(g *run.Group, ctx context.Context, path string) {
1414
g.Add(func() error {
15-
logging.Info("Loading ZFS data...")
16-
pterm.Info.Printfln("Loading ZFS data...")
15+
logging.Info("Initializing ZFS data...")
1716
zfs.RefreshZfsData()
18-
pterm.Info.Printfln("Launching UI...")
1917
logging.Info("Launching UI...")
2018

2119
application := CreateUi(path, true)

0 commit comments

Comments
 (0)