fixes and improvements for new server settings menu
This commit is contained in:
parent
902f3606c2
commit
66f9c0bc1e
27 changed files with 2244 additions and 40 deletions
95
internal/identity/identity_test.go
Normal file
95
internal/identity/identity_test.go
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
package identity
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestStoreTextRoundTrip(t *testing.T) {
|
||||
s := NewStore(t.TempDir())
|
||||
|
||||
info, err := s.Get()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if info != (Info{}) {
|
||||
t.Fatalf("expected zero-value Info before any write, got %+v", info)
|
||||
}
|
||||
|
||||
if err := s.SetText(" OwpenGram ", " A self-hosted server. "); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
info, err = s.Get()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if info.Name != "OwpenGram" || info.Description != "A self-hosted server." {
|
||||
t.Fatalf("got %+v", info)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStoreIconRoundTrip(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
s := NewStore(dir)
|
||||
|
||||
if _, _, ok := s.Icon(); ok {
|
||||
t.Fatal("expected no icon before any upload")
|
||||
}
|
||||
|
||||
png := []byte{0x89, 'P', 'N', 'G', 1, 2, 3}
|
||||
if err := s.SetIcon(png, ".png"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data, ext, ok := s.Icon()
|
||||
if !ok || ext != ".png" || string(data) != string(png) {
|
||||
t.Fatalf("Icon() = %v, %q, %v", data, ext, ok)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(dir, "icon.png")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Replacing with a different extension removes the old file.
|
||||
jpg := []byte{0xFF, 0xD8, 0xFF}
|
||||
if err := s.SetIcon(jpg, ".jpg"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(dir, "icon.png")); !os.IsNotExist(err) {
|
||||
t.Fatal("old icon.png should have been removed")
|
||||
}
|
||||
data, ext, ok = s.Icon()
|
||||
if !ok || ext != ".jpg" || string(data) != string(jpg) {
|
||||
t.Fatalf("Icon() after replace = %v, %q, %v", data, ext, ok)
|
||||
}
|
||||
|
||||
if err := s.RemoveIcon(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, _, ok := s.Icon(); ok {
|
||||
t.Fatal("expected no icon after RemoveIcon")
|
||||
}
|
||||
|
||||
// Name/description set earlier (none here) must survive icon churn --
|
||||
// Get() after all this should still report a clean, non-error zero name.
|
||||
info, err := s.Get()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if info.IconExt != "" {
|
||||
t.Fatalf("IconExt should be empty after removal, got %q", info.IconExt)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStorePreservesIconAcrossTextEdits(t *testing.T) {
|
||||
s := NewStore(t.TempDir())
|
||||
if err := s.SetIcon([]byte{1, 2, 3}, ".webp"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.SetText("New Name", "New description"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, ext, ok := s.Icon()
|
||||
if !ok || ext != ".webp" {
|
||||
t.Fatalf("icon lost after unrelated SetText: ext=%q ok=%v", ext, ok)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue