(t *testing.T)
| 141 | } |
| 142 | |
| 143 | func TestContentWriter(t *testing.T) { |
| 144 | for _, alg := range []digest.Algorithm{digest.SHA256, digest.SHA512} { |
| 145 | t.Run(alg.String(), func(t *testing.T) { |
| 146 | ctx, tmpdir, cs, cleanup := contentStoreEnv(t) |
| 147 | defer cleanup() |
| 148 | defer testutil.DumpDirOnFailure(t, tmpdir) |
| 149 | |
| 150 | cw, err := cs.Writer(ctx, content.WithRef("myref")) |
| 151 | if err != nil { |
| 152 | t.Fatal(err) |
| 153 | } |
| 154 | if err := cw.Close(); err != nil { |
| 155 | t.Fatal(err) |
| 156 | } |
| 157 | |
| 158 | if _, err := os.Stat(filepath.Join(tmpdir, "ingest")); os.IsNotExist(err) { |
| 159 | t.Fatal("ingest dir should be created", err) |
| 160 | } |
| 161 | |
| 162 | // reopen, so we can test things |
| 163 | cw, err = cs.Writer(ctx, content.WithRef("myref")) |
| 164 | if err != nil { |
| 165 | t.Fatal(err) |
| 166 | } |
| 167 | |
| 168 | // make sure that second resume also fails |
| 169 | if _, err = cs.Writer(ctx, content.WithRef("myref")); err == nil { |
| 170 | // TODO(stevvooe): This also works across processes. Need to find a way |
| 171 | // to test that, as well. |
| 172 | t.Fatal("no error on second resume") |
| 173 | } |
| 174 | |
| 175 | // we should also see this as an active ingestion |
| 176 | ingestions, err := cs.ListStatuses(ctx, "") |
| 177 | if err != nil { |
| 178 | t.Fatal(err) |
| 179 | } |
| 180 | |
| 181 | // clear out the time and meta cause we don't care for this test |
| 182 | for i := range ingestions { |
| 183 | ingestions[i].UpdatedAt = time.Time{} |
| 184 | ingestions[i].StartedAt = time.Time{} |
| 185 | } |
| 186 | |
| 187 | if !reflect.DeepEqual(ingestions, []content.Status{ |
| 188 | { |
| 189 | Ref: "myref", |
| 190 | Offset: 0, |
| 191 | }, |
| 192 | }) { |
| 193 | t.Fatalf("unexpected ingestion set: %v", ingestions) |
| 194 | } |
| 195 | |
| 196 | p := make([]byte, 4<<20) |
| 197 | if _, err := rand.Read(p); err != nil { |
| 198 | t.Fatal(err) |
| 199 | } |
| 200 | expected := alg.FromBytes(p) |
nothing calls this directly
no test coverage detected
searching dependent graphs…