summaryrefslogtreecommitdiff
path: root/runconfig/config_test.go
diff options
context:
space:
mode:
authorSebastiaan van Stijn <github@gone.nl>2022-04-08 23:27:50 +0200
committerSebastiaan van Stijn <github@gone.nl>2022-04-11 21:44:45 +0200
commitb6d58d749c6d671f0dc19a88b948b772272e145d (patch)
tree9c0600be9bd5f31c9548fa779cf1f048023e7d2c /runconfig/config_test.go
parentff5f70e55f8cd303efbaee3eafda9dfe86a3da36 (diff)
downloaddocker-b6d58d749c6d671f0dc19a88b948b772272e145d.tar.gz
runconfig: ContainerDecoder(): fix handling of invalid JSON
Implement similar logic as is used in httputils.ReadJSON(). Before this patch, endpoints using the ContainerDecoder would incorrectly return a 500 (internal server error) status. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Diffstat (limited to 'runconfig/config_test.go')
-rw-r--r--runconfig/config_test.go37
1 files changed, 20 insertions, 17 deletions
diff --git a/runconfig/config_test.go b/runconfig/config_test.go
index 5325f5a754..bbadcce297 100644
--- a/runconfig/config_test.go
+++ b/runconfig/config_test.go
@@ -42,27 +42,30 @@ func TestDecodeContainerConfig(t *testing.T) {
}
for _, f := range fixtures {
- b, err := os.ReadFile(f.file)
- if err != nil {
- t.Fatal(err)
- }
+ f := f
+ t.Run(f.file, func(t *testing.T) {
+ b, err := os.ReadFile(f.file)
+ if err != nil {
+ t.Fatal(err)
+ }
- c, h, _, err := decodeContainerConfig(bytes.NewReader(b), sysinfo.New())
- if err != nil {
- t.Fatal(fmt.Errorf("Error parsing %s: %v", f, err))
- }
+ c, h, _, err := decodeContainerConfig(bytes.NewReader(b), sysinfo.New())
+ if err != nil {
+ t.Fatal(err)
+ }
- if c.Image != image {
- t.Fatalf("Expected %s image, found %s\n", image, c.Image)
- }
+ if c.Image != image {
+ t.Fatalf("Expected %s image, found %s", image, c.Image)
+ }
- if len(c.Entrypoint) != len(f.entrypoint) {
- t.Fatalf("Expected %v, found %v\n", f.entrypoint, c.Entrypoint)
- }
+ if len(c.Entrypoint) != len(f.entrypoint) {
+ t.Fatalf("Expected %v, found %v", f.entrypoint, c.Entrypoint)
+ }
- if h != nil && h.Memory != 1000 {
- t.Fatalf("Expected memory to be 1000, found %d\n", h.Memory)
- }
+ if h != nil && h.Memory != 1000 {
+ t.Fatalf("Expected memory to be 1000, found %d", h.Memory)
+ }
+ })
}
}