mirror of
https://github.com/moby/buildkit.git
synced 2025-11-27 04:01:46 +03:00
This makes destination more symetrical with sources. Signed-off-by: Brian Goff <cpuguy83@gmail.com>
116 lines
3.2 KiB
Go
116 lines
3.2 KiB
Go
package sourcepolicy
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/moby/buildkit/solver/pb"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestMutate(t *testing.T) {
|
|
type testCaseOp struct {
|
|
op *pb.Op
|
|
dest string
|
|
destAttrs map[string]string
|
|
expected bool
|
|
expectedOp *pb.Op
|
|
expectedErr string
|
|
}
|
|
|
|
testCases := []testCaseOp{
|
|
{
|
|
op: &pb.Op{
|
|
Op: &pb.Op_Source{
|
|
Source: &pb.SourceOp{
|
|
Identifier: "docker-image://docker.io/library/busybox:1.34.1-uclibc",
|
|
},
|
|
},
|
|
},
|
|
dest: "docker-image://docker.io/library/busybox:1.34.1-uclibc@sha256:3614ca5eacf0a3a1bcc361c939202a974b4902b9334ff36eb29ffe9011aaad83",
|
|
expected: true,
|
|
expectedOp: &pb.Op{
|
|
Op: &pb.Op_Source{
|
|
Source: &pb.SourceOp{
|
|
Identifier: "docker-image://docker.io/library/busybox:1.34.1-uclibc@sha256:3614ca5eacf0a3a1bcc361c939202a974b4902b9334ff36eb29ffe9011aaad83",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
op: &pb.Op{
|
|
Op: &pb.Op_Source{
|
|
Source: &pb.SourceOp{
|
|
Identifier: "docker-image://docker.io/library/busybox",
|
|
},
|
|
},
|
|
},
|
|
dest: "docker-image://docker.io/library/busybox:latest@sha256:3614ca5eacf0a3a1bcc361c939202a974b4902b9334ff36eb29ffe9011aaad83",
|
|
expected: true,
|
|
expectedOp: &pb.Op{
|
|
Op: &pb.Op_Source{
|
|
Source: &pb.SourceOp{
|
|
Identifier: "docker-image://docker.io/library/busybox:latest@sha256:3614ca5eacf0a3a1bcc361c939202a974b4902b9334ff36eb29ffe9011aaad83",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
// Discard the existing digest that might have been resolved by the Dockerfile frontend's MetaResolver.
|
|
op: &pb.Op{
|
|
Op: &pb.Op_Source{
|
|
Source: &pb.SourceOp{
|
|
Identifier: "docker-image://docker.io/library/busybox:latest@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
},
|
|
},
|
|
},
|
|
dest: "docker-image://docker.io/library/busybox:latest@sha256:3614ca5eacf0a3a1bcc361c939202a974b4902b9334ff36eb29ffe9011aaad83",
|
|
expected: true,
|
|
expectedOp: &pb.Op{
|
|
Op: &pb.Op_Source{
|
|
Source: &pb.SourceOp{
|
|
Identifier: "docker-image://docker.io/library/busybox:latest@sha256:3614ca5eacf0a3a1bcc361c939202a974b4902b9334ff36eb29ffe9011aaad83",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
op: &pb.Op{
|
|
Op: &pb.Op_Source{
|
|
Source: &pb.SourceOp{
|
|
Identifier: "https://raw.githubusercontent.com/moby/buildkit/v0.10.1/README.md",
|
|
},
|
|
},
|
|
},
|
|
dest: "https://raw.githubusercontent.com/moby/buildkit/v0.10.1/README.md",
|
|
destAttrs: map[string]string{pb.AttrHTTPChecksum: "sha256:6e4b94fc270e708e1068be28bd3551dc6917a4fc5a61293d51bb36e6b75c4b53"},
|
|
expected: true,
|
|
expectedOp: &pb.Op{
|
|
Op: &pb.Op_Source{
|
|
Source: &pb.SourceOp{
|
|
Identifier: "https://raw.githubusercontent.com/moby/buildkit/v0.10.1/README.md",
|
|
Attrs: map[string]string{
|
|
pb.AttrHTTPChecksum: "sha256:6e4b94fc270e708e1068be28bd3551dc6917a4fc5a61293d51bb36e6b75c4b53",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
ctx := context.Background()
|
|
for _, tc := range testCases {
|
|
op := *tc.op
|
|
|
|
t.Run(op.String(), func(t *testing.T) {
|
|
mutated, err := Mutate(ctx, op.GetSource(), tc.dest, tc.destAttrs)
|
|
require.Equal(t, tc.expected, mutated)
|
|
if tc.expectedErr != "" {
|
|
require.Error(t, err, tc.expectedErr)
|
|
} else {
|
|
require.Equal(t, tc.expectedOp, &op)
|
|
}
|
|
})
|
|
}
|
|
}
|