Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
100 lines
2.3 KiB
Go
100 lines
2.3 KiB
Go
package calendar
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"github.com/google/uuid"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"sync"
|
|
"testing"
|
|
)
|
|
|
|
func TestCalendarPrettyNamesDefaultsAndRename(t *testing.T) {
|
|
r, d, a, c := fixture(t)
|
|
ctx := context.Background()
|
|
c, e := r.Settings(ctx, d, c.ID, a, c.Version, c.Name, false, nil, "work")
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
second, e := r.Create(ctx, d, a, "Personal", "personal")
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if _, e = r.Create(ctx, d, a, "Duplicate", "WORK"); !errors.Is(e, ErrNameTaken) {
|
|
t.Fatal(e)
|
|
}
|
|
for _, name := range []string{"", "a,b", "../private", "two words", uuid.NewString()} {
|
|
if _, e = r.Create(ctx, d, a, "Invalid", name); !errors.Is(e, ErrInvalid) {
|
|
t.Fatal(name, e)
|
|
}
|
|
}
|
|
if e = r.SaveDefaults(ctx, d, a, []string{c.ID, second.ID}); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
v := sample(t, "meeting", "2026-09-01T09:00:00Z", "2026-09-01T10:00:00Z", false)
|
|
if _, e = r.Change(ctx, d, c.ID, a, v.UID, "*", &v); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
c, e = r.Get(d, c.ID, a)
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
c, e = r.Settings(ctx, d, c.ID, a, c.Version, c.Name, false, nil, "office")
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
ids, e := r.Defaults(d, a)
|
|
if e != nil || len(ids) != 2 || ids[0] != c.ID {
|
|
t.Fatal(ids, e)
|
|
}
|
|
dir, _ := r.dir(d, c.ID)
|
|
for m, h := range c.Months {
|
|
b, e := os.ReadFile(filepath.Join(dir, m+"."+h+".ics"))
|
|
if e != nil || !strings.Contains(string(b), "NAME:office\r\n") {
|
|
t.Fatal(string(b), e)
|
|
}
|
|
}
|
|
got, e := r.Event(ctx, d, c.ID, a, v.UID)
|
|
if e != nil || got.ETag != v.ETag {
|
|
t.Fatal("rename changed event identity", e)
|
|
}
|
|
other := uuid.NewString()
|
|
if e = r.SaveDefaults(ctx, d, other, []string{c.ID}); !errors.Is(e, ErrMissing) {
|
|
t.Fatal("private default accepted", e)
|
|
}
|
|
ids, e = r.Defaults(d, other)
|
|
if e != nil || len(ids) != 0 {
|
|
t.Fatal(ids, e)
|
|
}
|
|
}
|
|
func TestCalendarConcurrentNameReservation(t *testing.T) {
|
|
r, d, a, _ := fixture(t)
|
|
var wg sync.WaitGroup
|
|
results := make(chan error, 2)
|
|
for range 2 {
|
|
wg.Add(1)
|
|
go func() {
|
|
defer wg.Done()
|
|
_, e := r.Create(context.Background(), d, a, "Shared", "shared")
|
|
results <- e
|
|
}()
|
|
}
|
|
wg.Wait()
|
|
close(results)
|
|
success, conflict := 0, 0
|
|
for e := range results {
|
|
if e == nil {
|
|
success++
|
|
} else if errors.Is(e, ErrNameTaken) {
|
|
conflict++
|
|
} else {
|
|
t.Fatal(e)
|
|
}
|
|
}
|
|
if success != 1 || conflict != 1 {
|
|
t.Fatal(success, conflict)
|
|
}
|
|
}
|