tinyrelayfile
tinyrelay/internal/community/agent_grant_requests_test.go/

internal/community/agent_grant_requests_test.go raw
1package community
2
3import (
4 "reflect"
5 "testing"
6)
7
8func TestGrantRequestTagsPatchOnlyRequestedEntries(t *testing.T) {
9 old := [][]string{
10 {"d", "agent"}, {"p", "agent"}, {"expiration", "200"},
11 {"k", "1"}, {"k", "9"}, {"room", "alpha"}, {"room", "beta"},
12 {"repo", "owner:one:read"}, {"repo", "owner:two:maintain"},
13 {"grant-request", "old"}, {"grant-base", "old"}, {"e", "old", "", "grant-request"},
14 }
15 want := [][]string{
16 {"d", "agent"}, {"p", "agent"}, {"expiration", "200"},
17 {"k", "1"}, {"k", "9"}, {"room", "alpha"}, {"room", "beta"},
18 {"repo", "owner:one:read"}, {"repo", "owner:two:maintain"},
19 {"k", "11"},
20 }
21 got := grantRequestTags(old, AgentGrantChanges{Kinds: []int{11}, Rooms: []string{"alpha"}})
22 if !reflect.DeepEqual(got, want) {
23 t.Fatalf("patch tags = %#v, want %#v", got, want)
24 }
25}
26
27func TestGrantRequestPatchKeepsOtherRepositoriesAndSites(t *testing.T) {
28 old := [][]string{{"repo", "owner:one:read"}, {"repo", "owner:two:maintain"}, {"sites", "one", "encrypted"}, {"sites", "two", "ttl=7"}}
29 changed := grantRequestTags(old, AgentGrantChanges{Repos: []AgentRepo{{Owner: "owner", Identifier: "one", Level: "maintain"}}, Sites: []AgentSite{{Label: "one", TTLDays: 3}}})
30 want := [][]string{{"repo", "owner:two:maintain"}, {"sites", "two", "ttl=7"}, {"repo", "owner:one:maintain"}, {"sites", "one", "ttl=3"}}
31 if !reflect.DeepEqual(changed, want) {
32 t.Fatalf("patch changed unrelated entries: %v", changed)
33 }
34}

About

ownerc01503e8035f
visibilitypublic
headd730679639bf

Maintainers

  • c01503e8035f owner
  • ba1b5beed5b5 agent hermes

Clone

  • https://012.run/npub1cq2s86qrtadf36eqq3epm38wmhdynrrcwxf84eldk3f94dkv7ttsrulrz5/tinyrelay.git

Refs