Skip to content
Merged
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
bin
dist
dist
coverage.out
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ VERSION ?= 0.7.0
test: ## Run all tests
@go clean --testcache && go test -v ./...

coverage: ## Run all tests with coverage and show summary
@go test -coverprofile=coverage.out ./...
@go tool cover -func=coverage.out

coverage-html: ## Run all tests with coverage and open HTML report
@go test -coverprofile=coverage.out ./...
@go tool cover -html=coverage.out

build: ## Builds the CLI
@go build ${GO_FLAGS} \
-ldflags "-w -s \
Expand Down
19 changes: 18 additions & 1 deletion internal/configuration/validation_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
package configuration

import "testing"
import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestValidate(t *testing.T) {
// Save original
original := CurrentConfig
defer func() { CurrentConfig = original }()

CurrentConfig = Configuration{
FileBrowser: FileBrowserConfig{Permissions: FileBrowserPermissionsFormatOctal, Owner: FileBrowserOwnerFormatID},
}

err := Validate("test.yaml")
assert.NoError(t, err)
}

func TestValidateConfig(t *testing.T) {
t.Parallel()
Expand Down
97 changes: 97 additions & 0 deletions internal/data/file_browser_entry_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package data

import (
"testing"
"zfs-file-history/internal/data/diff_state"
"zfs-file-history/internal/zfs"

"github.com/stretchr/testify/assert"
)

func TestFileBrowserEntry_HasReal(t *testing.T) {
entry := &FileBrowserEntry{
RealFile: &RealFile{Path: "/foo"},
}
assert.True(t, entry.HasReal())

entry = &FileBrowserEntry{
RealFile: nil,
}
assert.False(t, entry.HasReal())
}

func TestFileBrowserEntry_HasSnapshot(t *testing.T) {
entry := &FileBrowserEntry{
SnapshotFiles: []*SnapshotFile{{Path: "/foo"}},
}
assert.True(t, entry.HasSnapshot())

entry = &FileBrowserEntry{
SnapshotFiles: []*SnapshotFile{},
}
assert.False(t, entry.HasSnapshot())
}

func TestFileBrowserEntry_GetRealPath(t *testing.T) {
realFile := &RealFile{Path: "/real/path"}
snapshotFile := &SnapshotFile{OriginalPath: "/original/path"}

entry := &FileBrowserEntry{
RealFile: realFile,
}
assert.Equal(t, "/real/path", entry.GetRealPath())

entry = &FileBrowserEntry{
RealFile: nil,
SnapshotFiles: []*SnapshotFile{snapshotFile},
}
assert.Equal(t, "/original/path", entry.GetRealPath())
}

func TestFileBrowserEntry_Equal(t *testing.T) {
e1 := FileBrowserEntry{RealFile: &RealFile{Path: "/foo"}}
e2 := FileBrowserEntry{RealFile: &RealFile{Path: "/foo"}}
e3 := FileBrowserEntry{RealFile: &RealFile{Path: "/bar"}}

assert.True(t, e1.Equal(e2))
assert.False(t, e1.Equal(e3))
}

func TestFileBrowserEntry_HasDiff(t *testing.T) {
entry := &FileBrowserEntry{
DiffState: diff_state.Modified,
SnapshotFiles: []*SnapshotFile{{Path: "/foo"}},
}
assert.True(t, entry.HasDiff())

entry.DiffState = diff_state.Equal
assert.False(t, entry.HasDiff())

entry.DiffState = diff_state.Modified
entry.SnapshotFiles = nil
assert.False(t, entry.HasDiff())
}

func TestFileBrowserEntry_TableRowId(t *testing.T) {
entry := FileBrowserEntry{RealFile: &RealFile{Path: "/foo"}}
assert.Equal(t, "/foo", entry.TableRowId())
}

func TestRealFile_Equal(t *testing.T) {
f1 := RealFile{Name: "a", Path: "p"}
f2 := RealFile{Name: "a", Path: "p"}
f3 := RealFile{Name: "b", Path: "p"}

assert.True(t, f1.Equal(f2))
assert.False(t, f1.Equal(f3))
}

func TestSnapshotFile_Equal(t *testing.T) {
snap := &zfs.Snapshot{}
f1 := SnapshotFile{Path: "p", OriginalPath: "o", Snapshot: snap}
f2 := SnapshotFile{Path: "p", OriginalPath: "o", Snapshot: snap}
f3 := SnapshotFile{Path: "p2", OriginalPath: "o", Snapshot: snap}

assert.True(t, f1.Equal(f2))
assert.False(t, f1.Equal(f3))
}
4 changes: 1 addition & 3 deletions internal/ui/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ import (
// AddActor wires ZFS preload and UI lifecycle into the application run group.
func AddActor(g *run.Group, ctx context.Context, path string) {
g.Add(func() error {
logging.Info("Loading ZFS data...")
pterm.Info.Printfln("Loading ZFS data...")
logging.Info("Initializing ZFS data...")
zfs.RefreshZfsData()
pterm.Info.Printfln("Launching UI...")
logging.Info("Launching UI...")

application := CreateUi(path, true)
Expand Down
Loading
Loading