Repository: google/gvisor
File: runsc/config/config_test.go (Go)

Code before:
					t.Fatalf("got no error, but expected one")
				}
				if !strings.Contains(err.Error(), tc.createError.Error()) {
					t.Fatalf("mismatch error: got: %q want: %q", err.Error(), tc.createError.Error())
				}
				return
			}

			if err != nil {
				t.Fatalf("NewFromBundle failed: %v", err)
			}

			toml, err := cfg.ToContainerdConfigTOML(opt)
			if err != nil {
				t.Fatalf("ToContainerdConfigTOML failed: %v", err)
			}
			if diff := cmp.Diff(tc.want, toml); diff != "" {
				t.Fatalf("mismatch strings: %s", diff)
			}

		})
	}

}

func TestParseSerializeOverlay2(t *testing.T) {
	t.Run("Without size", func(t *testing.T) {
		o := Overlay2{}
		err := o.Set("all:memory")
		if err != nil {
			t.Fatalf("Set failed: %v", err)
		}
		if o.RootOverlaySize() != "" || o.RootOverlayMedium() != "" {
			t.Fatalf("Size mismatch, expecting empty, got %q, %q", o.RootOverlaySize(), o.SubMountOverlaySize())
		}
		if o.String() != "all:memory" {
			t.Fatalf("String mismatch, expecting all:memory, got %q", o.String())
		}
	})
	t.Run("With size", func(t *testing.T) {
		o := Overlay2{}
		err := o.Set("root:memory,size=1g")
		if err != nil {
			t.Fatalf("Set failed: %v", err)
		}
		if o.RootOverlaySize() != "1g" || o.SubMountOverlaySize() != "" {
			t.Fatalf("Size mismatch, expecting 1g, empty, got %q, %q", o.RootOverlaySize(), o.SubMountOverlaySize())
		}
		if o.String() != "all:memory,size=1g" {
			t.Fatalf("String mismatch, expecting all:memory, got %q", o.String())
		}

Review comment (bug):
This test is failing:
```
--- FAIL: TestParseSerializeOverlay2 (0.00s)
    --- FAIL: TestParseSerializeOverlay2/Without_size (0.00s)
        config_test.go:798: Size mismatch, expecting empty, got "", ""
    --- FAIL: TestParseSerializeOverlay2/With_size (0.00s)
        config_test.go:814: String mismatch, expecting all:memory, got "root:memory,size=1g"
```

Code after:
					t.Fatalf("got no error, but expected one")
				}
				if !strings.Contains(err.Error(), tc.createError.Error()) {
					t.Fatalf("mismatch error: got: %q want: %q", err.Error(), tc.createError.Error())
				}
				return
			}

			if err != nil {
				t.Fatalf("NewFromBundle failed: %v", err)
			}

			toml, err := cfg.ToContainerdConfigTOML(opt)
			if err != nil {
				t.Fatalf("ToContainerdConfigTOML failed: %v", err)
			}
			if diff := cmp.Diff(tc.want, toml); diff != "" {
				t.Fatalf("mismatch strings: %s", diff)
			}

		})
	}

}

func TestParseSerializeOverlay2(t *testing.T) {
	t.Run("Without size", func(t *testing.T) {
		o := Overlay2{}
		err := o.Set("all:memory")
		if err != nil {
			t.Fatalf("Set failed: %v", err)
		}
		if o.RootOverlaySize() != "" || o.SubMountOverlaySize() != "" {
			t.Fatalf("Size mismatch, expecting empty, got %q, %q", o.RootOverlaySize(), o.SubMountOverlaySize())
		}
		if o.String() != "all:memory" {
			t.Fatalf("String mismatch, expecting all:memory, got %q", o.String())
		}
	})
	t.Run("With size", func(t *testing.T) {
		o := Overlay2{}
		err := o.Set("root:memory,size=1g")
		if err != nil {
			t.Fatalf("Set failed: %v", err)
		}
		if o.RootOverlaySize() != "1g" || o.SubMountOverlaySize() != "" {
			t.Fatalf("Size mismatch, expecting 1g, empty, got %q, %q", o.RootOverlaySize(), o.SubMountOverlaySize())
		}
		if o.String() != "root:memory,size=1g" {
			t.Fatalf("String mismatch, expecting ll:memory,size=1g, got %q", o.String())
		}