(obj object, tx *bolt.Tx, db *DB, cs content.Store, sn snapshots.Snapshotter)
| 689 | } |
| 690 | |
| 691 | func create(obj object, tx *bolt.Tx, db *DB, cs content.Store, sn snapshots.Snapshotter) (*gc.Node, error) { |
| 692 | var ( |
| 693 | node *gc.Node |
| 694 | namespace = "test" |
| 695 | ctx = boltutil.WithTransaction(namespaces.WithNamespace(context.Background(), namespace), tx) |
| 696 | ) |
| 697 | |
| 698 | switch v := obj.data.(type) { |
| 699 | case testContent: |
| 700 | expected := digest.FromBytes(v.data) |
| 701 | w, err := cs.Writer(ctx, |
| 702 | content.WithRef("test-ref"), |
| 703 | content.WithDescriptor(ocispec.Descriptor{Size: int64(len(v.data)), Digest: expected})) |
| 704 | if err != nil { |
| 705 | return nil, fmt.Errorf("failed to create writer: %w", err) |
| 706 | } |
| 707 | if _, err := w.Write(v.data); err != nil { |
| 708 | return nil, fmt.Errorf("write blob failed: %w", err) |
| 709 | } |
| 710 | if err := w.Commit(ctx, int64(len(v.data)), expected, content.WithLabels(obj.labels)); err != nil { |
| 711 | return nil, fmt.Errorf("failed to commit blob: %w", err) |
| 712 | } |
| 713 | if !obj.removed { |
| 714 | node = &gc.Node{ |
| 715 | Type: ResourceContent, |
| 716 | Namespace: namespace, |
| 717 | Key: expected.String(), |
| 718 | } |
| 719 | } |
| 720 | case testSnapshot: |
| 721 | if v.active { |
| 722 | _, err := sn.Prepare(ctx, v.key, v.parent, snapshots.WithLabels(obj.labels)) |
| 723 | if err != nil { |
| 724 | return nil, err |
| 725 | } |
| 726 | } else { |
| 727 | akey := fmt.Sprintf("%s-active", v.key) |
| 728 | _, err := sn.Prepare(ctx, akey, v.parent) |
| 729 | if err != nil { |
| 730 | return nil, err |
| 731 | } |
| 732 | if err := sn.Commit(ctx, v.key, akey, snapshots.WithLabels(obj.labels)); err != nil { |
| 733 | return nil, err |
| 734 | } |
| 735 | } |
| 736 | if !obj.removed { |
| 737 | node = &gc.Node{ |
| 738 | Type: ResourceSnapshot, |
| 739 | Namespace: namespace, |
| 740 | Key: fmt.Sprintf("native/%s", v.key), |
| 741 | } |
| 742 | } |
| 743 | case testImage: |
| 744 | image := images.Image{ |
| 745 | Name: v.name, |
| 746 | Target: v.target, |
| 747 | Labels: obj.labels, |
| 748 | } |
no test coverage detected
searching dependent graphs…