GPLv3's "How to Apply These Terms" asks for a notice in each source file; this is the modern two-line SPDX form of it rather than the full paragraph. 82 files, including tests. The blank line after the header is load-bearing. In Go a comment block immediately preceding `package X` becomes the package doc comment, so without the separator the SPDX lines would be absorbed into the doc for the eleven packages whose doc.go (or main.go) opens with one, and `go doc` would print them. Verified it doesn't.
59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
// SPDX-FileCopyrightText: 2026 LINUXexpert-org
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package preflight
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestDirSize(t *testing.T) {
|
|
dir := t.TempDir()
|
|
if err := os.WriteFile(filepath.Join(dir, "a.bin"), make([]byte, 100), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sub := filepath.Join(dir, "sub")
|
|
if err := os.Mkdir(sub, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(sub, "b.bin"), make([]byte, 250), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
got, err := DirSize(dir)
|
|
if err != nil {
|
|
t.Fatalf("DirSize: %v", err)
|
|
}
|
|
if got != 350 {
|
|
t.Errorf("DirSize = %d, want 350", got)
|
|
}
|
|
}
|
|
|
|
func TestFreeBytes(t *testing.T) {
|
|
got, err := FreeBytes(t.TempDir())
|
|
if err != nil {
|
|
t.Fatalf("FreeBytes: %v", err)
|
|
}
|
|
if got == 0 {
|
|
t.Error("FreeBytes = 0, want > 0 for a live filesystem")
|
|
}
|
|
}
|
|
|
|
func TestHumanBytes(t *testing.T) {
|
|
cases := []struct {
|
|
in uint64
|
|
want string
|
|
}{
|
|
{500, "500 B"},
|
|
{1536, "1.5 KiB"},
|
|
{5 * 1024 * 1024, "5.0 MiB"},
|
|
}
|
|
for _, tc := range cases {
|
|
if got := humanBytes(tc.in); got != tc.want {
|
|
t.Errorf("humanBytes(%d) = %q, want %q", tc.in, got, tc.want)
|
|
}
|
|
}
|
|
}
|