(t *testing.T)
| 85 | } |
| 86 | |
| 87 | func 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 |
nothing calls this directly
no test coverage detected