Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests cases for malformed and conflicting patches #524

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,54 @@ func TestSourceDockerImage(t *testing.T) {
})
}

func TestPatchSource_MalformedPatch(t *testing.T) {
worker := llb.Scratch()
sourceState := llb.Scratch().File(
llb.Mkfile("/file.txt", 0644, []byte("Hello World")),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use the updated octal format 0o644 for everything?

)
sourceToState := map[string]llb.State{
"malformed_patch": llb.Scratch().File(
llb.Mkfile("/malformed.patch", 0644, []byte("invalid patch content")),
),
}
patchNames := []PatchSpec{
{
Source: "malformed_patch",
},
}

assert.Assert(t, func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this is testing that the closure is not nil which doesn't look correct.

I think the easiest way to test these is in the integration tests (under test/) where we can get it to actually run the patch and produce an error.

patchSource(worker, sourceState, sourceToState, patchNames)
} != nil, "patch -p1 < /patch: exit status 1")
}

func TestPatchSource_ConflictingPatches(t *testing.T) {
worker := llb.Scratch()
sourceState := llb.Scratch().File(
llb.Mkfile("/file.txt", 0644, []byte("Hello World")),
)
sourceToState := map[string]llb.State{
"patch1": llb.Scratch().File(
llb.Mkfile("/patch1.patch", 0644, []byte("diff --git a/file.txt b/file.txt\nindex 123..456 100644\n--- a/file.txt\n+++ b/file.txt\n@@ -1 +1 @@\n-Decaf Bad\n+Cafe Good")),
),
"patch2": llb.Scratch().File(
llb.Mkfile("/patch2.patch", 0644, []byte("diff --git a/file.txt b/file.txt\nindex 123..789 100644\n--- a/file.txt\n+++ b/file.txt\n@@ -1 +1 @@\n-Decaf Bad\n+Caffeine Good")),
),
}
patchNames := []PatchSpec{
{
Source: "patch1",
},
{
Source: "patch2",
},
}

assert.Assert(t, func() {
patchSource(worker, sourceState, sourceToState, patchNames)
} != nil, "patch -p1 < /patch: exit status 1")
}

func getChildren(op *pb.Op, ops []*pb.Op, digests map[*pb.Op]digest.Digest) []*pb.Op {
children := make([]*pb.Op, 0, len(ops))
for _, maybeChild := range ops {
Expand Down
Loading