From 02aa5b4587d5ff9f0b35c2e453a9800959ddd160 Mon Sep 17 00:00:00 2001 From: Taichi Sasaki Date: Mon, 21 Sep 2020 07:53:23 +0900 Subject: [PATCH 1/4] Add tests for expr.Container.EvalName() --- expr/container_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 expr/container_test.go diff --git a/expr/container_test.go b/expr/container_test.go new file mode 100644 index 00000000..43c6e278 --- /dev/null +++ b/expr/container_test.go @@ -0,0 +1,29 @@ +package expr + +import ( + "testing" +) + +func TestContainerEvalName(t *testing.T) { + t.Parallel() + tests := []struct { + name, want string + }{ + {name: "", want: "unnamed container"}, + {name: "foo", want: `container "foo"`}, + } + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + container := Container{ + Element: &Element{ + Name: tt.name, + }, + } + if got := container.EvalName(); got != tt.want { + t.Errorf("got %s, want %s", got, tt.want) + } + }) + } +} From f3f42902e7cc48049da1cb65599686527afedf5b Mon Sep 17 00:00:00 2001 From: Taichi Sasaki Date: Mon, 21 Sep 2020 07:56:32 +0900 Subject: [PATCH 2/4] Add tests for expr.Container.Finalize() --- expr/container_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/expr/container_test.go b/expr/container_test.go index 43c6e278..4d7542fc 100644 --- a/expr/container_test.go +++ b/expr/container_test.go @@ -1,6 +1,7 @@ package expr import ( + "fmt" "testing" ) @@ -27,3 +28,31 @@ func TestContainerEvalName(t *testing.T) { }) } } + +func TestContainerFinalize(t *testing.T) { + t.Parallel() + container := Container{ + Element: &Element{ + Name: "foo", + }, + } + tests := []struct { + pre func() + want string + }{ + {want: ""}, + {pre: func() { container.Tags = "foo" }, want: "foo"}, + {pre: func() { container.Finalize() }, want: "Element,Container,foo"}, + } + for i, tt := range tests { + tt := tt + t.Run(fmt.Sprint(i), func(t *testing.T) { + if tt.pre != nil { + tt.pre() + } + if got := container.Tags; got != tt.want { + t.Errorf("got %s, want %s", got, tt.want) + } + }) + } +} From 4687c8770cfd020a73f2fcfecf84fe6c75066648 Mon Sep 17 00:00:00 2001 From: Taichi Sasaki Date: Mon, 21 Sep 2020 07:58:17 +0900 Subject: [PATCH 3/4] Add tests for expr.Container.Elements() --- expr/container_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/expr/container_test.go b/expr/container_test.go index 4d7542fc..74ba55ee 100644 --- a/expr/container_test.go +++ b/expr/container_test.go @@ -56,3 +56,15 @@ func TestContainerFinalize(t *testing.T) { }) } } + +func TestContainersElements(t *testing.T) { + t.Parallel() + containers := Containers{ + {Element: &Element{Name: "foo"}}, + {Element: &Element{Name: "bar"}}, + {Element: &Element{Name: "baz"}}, + } + if got := containers.Elements(); len(got) != len(containers) { + t.Errorf("got %d, want %d", len(got), len(containers)) + } +} From d09fc0ccf728e1ee397cd7ed7fc3c0f7e2c13ed9 Mon Sep 17 00:00:00 2001 From: Taichi Sasaki Date: Mon, 21 Sep 2020 09:09:32 +0900 Subject: [PATCH 4/4] Add tests for expr.Container.Component() --- expr/container_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/expr/container_test.go b/expr/container_test.go index 74ba55ee..31ec3d41 100644 --- a/expr/container_test.go +++ b/expr/container_test.go @@ -68,3 +68,29 @@ func TestContainersElements(t *testing.T) { t.Errorf("got %d, want %d", len(got), len(containers)) } } + +func TestContainerComponent(t *testing.T) { + t.Parallel() + container := Container{ + Components: Components{ + {Element: &Element{Name: "foo"}}, + {Element: &Element{Name: "bar"}}, + {Element: &Element{Name: "baz"}}, + }, + } + tests := []struct { + name string + want *Component + }{ + {name: "thud", want: nil}, + {name: "bar", want: container.Components[1]}, + } + for i, tt := range tests { + tt := tt + t.Run(fmt.Sprint(i), func(t *testing.T) { + if got := container.Component(tt.name); got != tt.want { + t.Errorf("got %#v, want %#v", got.Element, tt.want.Element) + } + }) + } +}