Skip to content
Merged
Show file tree
Hide file tree
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
40 changes: 20 additions & 20 deletions pkg/util/docker/dockerfile/dockerfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ WORKDIR /home
t.Errorf("%s: parse error: %v", name, err)
continue
}
got := ParseTreeToDockerfile(node)
got := ParseTreeToDockerfile(node.AST)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@smarterclayton check pls, this moved in rebase...

Copy link
Owner

Choose a reason for hiding this comment

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

This is fine, I've made that move myself several times already.

want := []byte(tc.want)
if !reflect.DeepEqual(got, want) {
t.Errorf("ParseTreeToDockerfile: %s:\ngot:\n%swant:\n%s", name, got, want)
Expand Down Expand Up @@ -129,7 +129,7 @@ ENV PATH=/bin
command.Maintainer: nil,
"UnknownCommand": nil,
} {
got := FindAll(node, cmd)
got := FindAll(node.AST, cmd)
if !reflect.DeepEqual(got, want) {
t.Errorf("FindAll(node, %q) = %#v; want %#v", cmd, got, want)
}
Expand Down Expand Up @@ -211,7 +211,7 @@ ENV PATH=/bin
t.Errorf("InsertInstructions: %s: parse error: %v", name, err)
continue
}
err = InsertInstructions(got, tc.index, tc.newInstructions)
err = InsertInstructions(got.AST, tc.index, tc.newInstructions)
if err != nil {
t.Errorf("InsertInstructions: %s: %v", name, err)
continue
Expand All @@ -221,7 +221,7 @@ ENV PATH=/bin
t.Errorf("InsertInstructions: %s: parse error: %v", name, err)
continue
}
if !bytes.Equal(ParseTreeToDockerfile(got), ParseTreeToDockerfile(want)) {
if !bytes.Equal(ParseTreeToDockerfile(got.AST), ParseTreeToDockerfile(want.AST)) {
t.Errorf("InsertInstructions: %s: got %#v; want %#v", name, got, want)
}
}
Expand All @@ -247,7 +247,7 @@ ENV PATH=/bin
t.Fatalf("parse error: %v", err)
}
for _, pos := range []int{-1, 3, 4} {
err := InsertInstructions(node, pos, "")
err := InsertInstructions(node.AST, pos, "")
if err == nil {
t.Errorf("InsertInstructions(node, %d, \"\"): got nil; want error", pos)
}
Expand All @@ -268,7 +268,7 @@ ENV PATH=/bin
"env without value": `ENV PATH`,
"nested json": `CMD [ "echo", [ "nested json" ] ]`,
} {
err = InsertInstructions(node, 1, instructions)
err = InsertInstructions(node.AST, 1, instructions)
if err == nil {
t.Errorf("InsertInstructions: %s: got nil; want error", name)
}
Expand Down Expand Up @@ -307,7 +307,7 @@ FROM centos:7`,
t.Errorf("%s: parse error: %v", name, err)
continue
}
got := LastBaseImage(node)
got := LastBaseImage(node.AST)
if !reflect.DeepEqual(got, tc.want) {
t.Errorf("LastBaseImage: %s: got %#v; want %#v", name, got, tc.want)
}
Expand Down Expand Up @@ -354,7 +354,7 @@ FROM centos:7`,
t.Errorf("%s: parse error: %v", name, err)
continue
}
got := baseImages(node)
got := baseImages(node.AST)
if !reflect.DeepEqual(got, tc.want) {
t.Errorf("baseImages: %s: got %#v; want %#v", name, got, tc.want)
}
Expand Down Expand Up @@ -413,7 +413,7 @@ EXPOSE 9090 9091
t.Errorf("%s: parse error: %v", name, err)
continue
}
got := LastExposedPorts(node)
got := LastExposedPorts(node.AST)
if !reflect.DeepEqual(got, tc.want) {
t.Errorf("LastExposedPorts: %s: got %#v; want %#v", name, got, tc.want)
}
Expand Down Expand Up @@ -473,7 +473,7 @@ EXPOSE 9090 9091
t.Errorf("%s: parse error: %v", name, err)
continue
}
got := exposedPorts(node)
got := exposedPorts(node.AST)
if !reflect.DeepEqual(got, tc.want) {
t.Errorf("exposedPorts: %s: got %#v; want %#v", name, got, tc.want)
}
Expand Down Expand Up @@ -510,15 +510,15 @@ func TestNextValues(t *testing.T) {
if err != nil {
t.Fatalf("parse error: %s: %v", original, err)
}
if len(node.Children) != 1 {
if len(node.AST.Children) != 1 {
t.Fatalf("unexpected number of children in test case: %s", original)
}
// The Docker parser always wrap instructions in a root node.
// Look at the node representing the first instruction, the one
// and only one in each test case.
node = node.Children[0]
if got := nextValues(node); !reflect.DeepEqual(got, want) {
t.Errorf("nextValues(%+v) = %#v; want %#v", node, got, want)
newNode := node.AST.Children[0]
if got := nextValues(newNode); !reflect.DeepEqual(got, want) {
t.Errorf("nextValues(%+v) = %#v; want %#v", newNode, got, want)
}
}
}
Expand All @@ -535,19 +535,19 @@ func TestNextValuesOnbuild(t *testing.T) {
if err != nil {
t.Fatalf("parse error: %s: %v", original, err)
}
if len(node.Children) != 1 {
if len(node.AST.Children) != 1 {
t.Fatalf("unexpected number of children in test case: %s", original)
}
// The Docker parser always wrap instructions in a root node.
// Look at the node representing the instruction following
// ONBUILD, the one and only one in each test case.
node = node.Children[0].Next
if node == nil || len(node.Children) != 1 {
nextNode := node.AST.Children[0].Next
if nextNode == nil || len(nextNode.Children) != 1 {
t.Fatalf("unexpected number of children in ONBUILD instruction of test case: %s", original)
}
node = node.Children[0]
if got := nextValues(node); !reflect.DeepEqual(got, want) {
t.Errorf("nextValues(%+v) = %#v; want %#v", node, got, want)
nextNode = nextNode.Children[0]
if got := nextValues(nextNode); !reflect.DeepEqual(got, want) {
t.Errorf("nextValues(%+v) = %#v; want %#v", nextNode, got, want)
}
}
}
Expand Down
19 changes: 10 additions & 9 deletions pkg/util/ovs/ovs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (
"testing"

"k8s.io/utils/exec"
fakeexec "k8s.io/utils/exec/testing"
)

func normalSetup() *exec.FakeExec {
return &exec.FakeExec{
func normalSetup() *fakeexec.FakeExec {
return &fakeexec.FakeExec{
LookPathFunc: func(prog string) (string, error) {
if prog == "ovs-ofctl" || prog == "ovs-vsctl" {
return "/sbin/" + prog, nil
Expand All @@ -20,17 +21,17 @@ func normalSetup() *exec.FakeExec {
}
}

func missingSetup() *exec.FakeExec {
return &exec.FakeExec{
func missingSetup() *fakeexec.FakeExec {
return &fakeexec.FakeExec{
LookPathFunc: func(prog string) (string, error) {
return "", fmt.Errorf("%s not found", prog)
},
}
}

func addTestResult(t *testing.T, fexec *exec.FakeExec, command string, output string, err error) {
fcmd := exec.FakeCmd{
CombinedOutputScript: []exec.FakeCombinedOutputAction{
func addTestResult(t *testing.T, fexec *fakeexec.FakeExec, command string, output string, err error) {
fcmd := fakeexec.FakeCmd{
CombinedOutputScript: []fakeexec.FakeCombinedOutputAction{
func() ([]byte, error) { return []byte(output), err },
},
}
Expand All @@ -40,11 +41,11 @@ func addTestResult(t *testing.T, fexec *exec.FakeExec, command string, output st
if execCommand != command {
t.Fatalf("Unexpected command: wanted %q got %q", command, execCommand)
}
return exec.InitFakeCmd(&fcmd, cmd, args...)
return fakeexec.InitFakeCmd(&fcmd, cmd, args...)
})
}

func ensureTestResults(t *testing.T, fexec *exec.FakeExec) {
func ensureTestResults(t *testing.T, fexec *fakeexec.FakeExec) {
if fexec.CommandCalls != len(fexec.CommandScript) {
t.Fatalf("Only used %d of %d expected commands", fexec.CommandCalls, len(fexec.CommandScript))
}
Expand Down