esync

Directory watching and remote syncing
Log | Files | Refs | README | LICENSE

sync_test.go (1544B)


      1 package cmd
      2 
      3 import (
      4 	"testing"
      5 
      6 	"github.com/louloulibs/esync/internal/syncer"
      7 )
      8 
      9 func TestGroupFilesByTopLevel_MultiFile(t *testing.T) {
     10 	files := []syncer.FileEntry{
     11 		{Name: "cmd/sync.go", Bytes: 100},
     12 		{Name: "cmd/root.go", Bytes: 200},
     13 		{Name: "main.go", Bytes: 50},
     14 	}
     15 
     16 	groups := groupFilesByTopLevel(files)
     17 
     18 	if len(groups) != 2 {
     19 		t.Fatalf("got %d groups, want 2", len(groups))
     20 	}
     21 
     22 	// First group: cmd/ with 2 files
     23 	g := groups[0]
     24 	if g.name != "cmd/" {
     25 		t.Errorf("group[0].name = %q, want %q", g.name, "cmd/")
     26 	}
     27 	if g.count != 2 {
     28 		t.Errorf("group[0].count = %d, want 2", g.count)
     29 	}
     30 	if len(g.files) != 2 {
     31 		t.Fatalf("group[0].files has %d entries, want 2", len(g.files))
     32 	}
     33 	if g.files[0] != "cmd/sync.go" || g.files[1] != "cmd/root.go" {
     34 		t.Errorf("group[0].files = %v, want [cmd/sync.go cmd/root.go]", g.files)
     35 	}
     36 
     37 	// Second group: root file
     38 	g = groups[1]
     39 	if g.name != "main.go" {
     40 		t.Errorf("group[1].name = %q, want %q", g.name, "main.go")
     41 	}
     42 	if g.files != nil {
     43 		t.Errorf("group[1].files should be nil for root file, got %v", g.files)
     44 	}
     45 }
     46 
     47 func TestGroupFilesByTopLevel_SingleFileDir(t *testing.T) {
     48 	files := []syncer.FileEntry{
     49 		{Name: "internal/config/config.go", Bytes: 300},
     50 	}
     51 
     52 	groups := groupFilesByTopLevel(files)
     53 
     54 	if len(groups) != 1 {
     55 		t.Fatalf("got %d groups, want 1", len(groups))
     56 	}
     57 
     58 	g := groups[0]
     59 	if g.name != "internal/config/config.go" {
     60 		t.Errorf("name = %q, want full path", g.name)
     61 	}
     62 	if g.files != nil {
     63 		t.Errorf("files should be nil for single-file dir, got %v", g.files)
     64 	}
     65 }