Skip to content
Merged
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
11 changes: 10 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,13 @@ jobs:
run: go build ./...

- name: Test
run: go test ./...
run: go test -coverprofile=coverage.out -coverpkg=./... ./...

- name: Coverage report
run: go tool cover -func=coverage.out

- name: Upload coverage profile
uses: actions/upload-artifact@v4
with:
name: coverage
path: coverage.out
39 changes: 39 additions & 0 deletions internal/core/git_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package core_test

import (
"testing"

"github.com/aissat/sysfig/internal/core"
)

// TestSanitizeBranchName verifies that dot-prefixed path components are
// replaced with "dot-" so Git accepts them as ref names.
func TestSanitizeBranchName(t *testing.T) {
tests := []struct {
input string
want string
}{
// Plain paths — must be unchanged.
{"etc/nginx/nginx.conf", "etc/nginx/nginx.conf"},
{"home/user/config", "home/user/config"},
// Dot-prefixed file at the end.
{"home/alice/.zshrc", "home/alice/dot-zshrc"},
// Dot-prefixed directory component.
{"home/aye7/.config/nvim/init.lua", "home/aye7/dot-config/nvim/init.lua"},
// Multiple dot-prefixed components.
{"home/aye7/.config/.nvim", "home/aye7/dot-config/dot-nvim"},
// Dot-prefixed first component (unusual but possible with a custom SysRoot).
{".bashrc", "dot-bashrc"},
// No dots at all.
{"etc/hosts", "etc/hosts"},
// Component that starts with "dot-" already — must not be double-escaped.
{"home/user/dot-zshrc", "home/user/dot-zshrc"},
}

for _, tc := range tests {
got := core.SanitizeBranchName(tc.input)
if got != tc.want {
t.Errorf("SanitizeBranchName(%q) = %q, want %q", tc.input, got, tc.want)
}
}
}
45 changes: 45 additions & 0 deletions internal/core/platform_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package core_test

import (
"runtime"
"testing"

"github.com/aissat/sysfig/internal/core"
)

// TestDetectPlatformTags_ContainsGOOS verifies that the result always contains
// at least one tag and that the first tag matches the current runtime.GOOS.
func TestDetectPlatformTags_ContainsGOOS(t *testing.T) {
tags := core.DetectPlatformTags()
if len(tags) == 0 {
t.Fatal("DetectPlatformTags must return at least one tag")
}
if tags[0] != runtime.GOOS {
t.Errorf("first tag = %q, want %q (runtime.GOOS)", tags[0], runtime.GOOS)
}
}

// TestDetectPlatformTags_NonEmpty verifies that no returned tag is an empty string.
func TestDetectPlatformTags_NonEmpty(t *testing.T) {
tags := core.DetectPlatformTags()
for i, tag := range tags {
if tag == "" {
t.Errorf("tag[%d] is an empty string — all tags must be non-empty", i)
}
}
}

// TestDetectPlatformTags_LinuxHasDistro verifies that on Linux we get at least
// two tags (OS family + distro) when /etc/os-release is readable.
// This test is skipped on non-Linux platforms.
func TestDetectPlatformTags_LinuxHasDistro(t *testing.T) {
if runtime.GOOS != "linux" {
t.Skip("distro tag detection only applies to Linux")
}
tags := core.DetectPlatformTags()
// On Linux we expect at least ["linux", "<distro>"].
// If /etc/os-release is missing (unusual) we still get ["linux"].
if len(tags) < 1 {
t.Errorf("expected at least 1 tag on Linux, got %v", tags)
}
}
Loading
Loading