MCPcopy Create free account
hub / github.com/openclaw/gogcli / TestRepositoryAppendValidation

Function TestRepositoryAppendValidation

internal/docsbatch/repository_test.go:87–149  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

85}
86
87func TestRepositoryAppendValidation(t *testing.T) {
88 t.Parallel()
89
90 repository := testRepository(t, nil)
91
92 state, err := repository.Create(State{
93 Service: ServiceDocs,
94 DocumentID: "doc1",
95 Account: "user@example.com",
96 Client: "default",
97 })
98 if err != nil {
99 t.Fatalf("Create: %v", err)
100 }
101 request := []json.RawMessage{json.RawMessage(`{"insertText":{"text":"x"}}`)}
102
103 tests := []struct {
104 name string
105 options AppendOptions
106 }{
107 {
108 name: "document",
109 options: AppendOptions{
110 BatchID: state.BatchID, Command: "docs.insert", Identity: testIdentity("other"),
111 RevisionID: "rev1", Requests: request,
112 },
113 },
114 {
115 name: "empty revision",
116 options: AppendOptions{
117 BatchID: state.BatchID, Command: "docs.insert", Identity: testIdentity("doc1"),
118 Requests: request,
119 },
120 },
121 }
122 for _, tt := range tests {
123 if _, appendErr := repository.Append(tt.options); appendErr == nil {
124 t.Fatalf("%s: Append succeeded", tt.name)
125 }
126 }
127
128 first := AppendOptions{
129 BatchID: state.BatchID, Command: "docs.insert", Identity: testIdentity("doc1"),
130 RevisionID: "rev1", Requests: request,
131 }
132 if _, err := repository.Append(first); err != nil {
133 t.Fatalf("first Append: %v", err)
134 }
135
136 revisionMismatch := first
137
138 revisionMismatch.RevisionID = "rev2"
139 if _, err := repository.Append(revisionMismatch); err == nil {
140 t.Fatal("revision mismatch succeeded")
141 }
142
143 requireEmpty := first
144

Callers

nothing calls this directly

Calls 5

testRepositoryFunction · 0.85
testIdentityFunction · 0.85
CreateMethod · 0.80
AppendMethod · 0.80
RawMessageMethod · 0.65

Tested by

no test coverage detected