Artifact 6399658304ae49091476c3d45fdc2b81adeb4ca1a8ac18c7b8f7d4c2d5ffc750:
- File
internal/oltp/savedview_test.go
— part of check-in
[96181d8fcb]
at
2026-08-23 01:43:17
on branch trunk
— saved views: name a report, keep it in the rail
A saved view is a name for a URL the tracker could already produce, so it stores the name and the query and nothing else. Per account, per listing; forgetting one loses the shortcut and not the listing. (user: dmestas, size: 2269) [annotate] [blame] [check-ins using]
package oltp import ( "path/filepath" "testing" ) // A saved view is a name for a URL. What the store owes: the two // listings never mix, one account cannot see another's, and saving a // name twice corrects it rather than growing a second entry that // shadows the first. func TestSavedViews(t *testing.T) { d, err := Open(filepath.Join(t.TempDir(), "oltp.db")) if err != nil { t.Fatal(err) } t.Cleanup(func() { d.Close() }) if err := d.SaveView("dan", "alpha", "my crashes", "subsystem=web"); err != nil { t.Fatal(err) } if err := d.SaveView("dan", "", "everything mine", "author=dan"); err != nil { t.Fatal(err) } if err := d.SaveView("eve", "alpha", "hers", "author=eve"); err != nil { t.Fatal(err) } // A report saved against one tracker means nothing on another, and // the cross-repository listing is its own place. got, err := d.SavedViews("dan", "alpha") if err != nil { t.Fatal(err) } if len(got) != 1 || got[0].Name != "my crashes" || got[0].Query != "subsystem=web" { t.Fatalf("alpha views = %+v", got) } if got, _ := d.SavedViews("dan", ""); len(got) != 1 || got[0].Name != "everything mine" { t.Fatalf("cross-repository views = %+v", got) } // Nobody sees anybody else's. if got, _ := d.SavedViews("dan", "alpha"); got[0].Query == "author=eve" { t.Fatal("one account's saved view reached another") } // Saving the same name again corrects it. if err := d.SaveView("dan", "alpha", "my crashes", "subsystem=api"); err != nil { t.Fatal(err) } got, _ = d.SavedViews("dan", "alpha") if len(got) != 1 || got[0].Query != "subsystem=api" { t.Fatalf("re-saving a name = %+v, want one corrected view", got) } // Forgetting one that was never there is not an error: the caller // asked for it to be gone and afterwards it is. if err := d.DeleteView("dan", "alpha", "never existed"); err != nil { t.Fatalf("deleting a view nobody has: %v", err) } if err := d.DeleteView("dan", "alpha", "my crashes"); err != nil { t.Fatal(err) } if got, _ := d.SavedViews("dan", "alpha"); len(got) != 0 { t.Fatalf("view survived deletion: %+v", got) } // An anonymous reader has no views rather than everybody's. if got, _ := d.SavedViews("", "alpha"); len(got) != 0 { t.Fatalf("anonymous saw %+v", got) } }