| 1 | package tinyclient |
| 2 | |
| 3 | import ( |
| 4 | "os/exec" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/FelineStateMachine/tinyrelay/internal/sites" |
| 9 | event "github.com/FelineStateMachine/tinyrelay/protocol/nostr" |
| 10 | ) |
| 11 | |
| 12 | func TestSitePresentationMatchesRelayManifests(t *testing.T) { |
| 13 | for _, kind := range []int{15128, 35128, 5128, 1} { |
| 14 | for _, key := range []string{strings.Repeat("0" , 63) + "1" , strings.Repeat("f" , 64), "invalid" } { |
| 15 | e := event.Event{Kind: kind, PubKey: key, ID: key, Tags: [][]string{{"d" , "demo" }, {"path" , "/index.html" , "hash" }, {"path" }, {"other" }}} |
| 16 | if got, want := siteLabel(e), sites.SiteLabel(e); got != want { |
| 17 | t.Errorf("label kind=%d key=%s: %s want %s" , kind, key, got, want) |
| 18 | } |
| 19 | if got, want := sitePathCount(e), len(sites.SitePaths(e)); got != want { |
| 20 | t.Errorf("path count=%d want %d" , got, want) |
| 21 | } |
| 22 | } |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | func TestFrontendBuildDoesNotLinkRelayStorage(t *testing.T) { |
| 27 | command := exec.Command("go" , "list" , "-deps" , "github.com/FelineStateMachine/tinyrelay/cmd/tinyclient" ) |
| 28 | out, err := command.CombinedOutput() |
| 29 | if err != nil { |
| 30 | t.Fatalf("list frontend dependencies: %v %s" , err, out) |
| 31 | } |
| 32 | for _, dependency := range strings.Fields(string(out)) { |
| 33 | if strings.Contains(dependency, "/internal/storage" ) || strings.Contains(dependency, "/internal/daemon" ) || strings.Contains(dependency, "modernc.org/sqlite" ) || strings.HasSuffix(dependency, "/tinygit" ) { |
| 34 | t.Errorf("frontend links backend implementation %s" , dependency) |
| 35 | } |
| 36 | } |
| 37 | } |