소스 검색

integration/container: combine TestResize tests into subtests

Reduce some of the boiler-plating, and by combining the tests, we skip
the testenv.Clean() in between each of the tests. Performance gain isn't
really measurable, but every bit should help :)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 1 년 전
부모
커밋
5f59f7bb49
1개의 변경된 파일30개의 추가작업 그리고 28개의 파일을 삭제
  1. 30 28
      integration/container/resize_test.go

+ 30 - 28
integration/container/resize_test.go

@@ -18,37 +18,39 @@ func TestResize(t *testing.T) {
 	ctx := setupTest(t)
 	ctx := setupTest(t)
 	apiClient := testEnv.APIClient()
 	apiClient := testEnv.APIClient()
 
 
-	cID := container.Run(ctx, t, apiClient, container.WithTty(true))
-	err := apiClient.ContainerResize(ctx, cID, types.ResizeOptions{
-		Height: 40,
-		Width:  40,
+	t.Run("success", func(t *testing.T) {
+		cID := container.Run(ctx, t, apiClient, container.WithTty(true))
+		err := apiClient.ContainerResize(ctx, cID, types.ResizeOptions{
+			Height: 40,
+			Width:  40,
+		})
+		assert.NilError(t, err)
+		// TODO(thaJeztah): also check if the resize happened
+		//
+		// Note: container inspect shows the initial size that was
+		// set when creating the container. Actual resize happens in
+		// containerd, and currently does not update the container's
+		// config after running (but does send a "resize" event).
 	})
 	})
-	assert.NilError(t, err)
-}
 
 
-func TestResizeWithInvalidSize(t *testing.T) {
-	skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.32"), "broken in earlier versions")
-	ctx := setupTest(t)
-	apiClient := testEnv.APIClient()
+	t.Run("invalid size", func(t *testing.T) {
+		skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.32"), "broken in earlier versions")
+		cID := container.Run(ctx, t, apiClient)
 
 
-	cID := container.Run(ctx, t, apiClient)
-
-	// Manually creating a request here, as the APIClient would invalidate
-	// these values before they're sent.
-	res, _, err := req.Post(ctx, "/containers/"+cID+"/resize?h=foo&w=bar")
-	assert.NilError(t, err)
-	assert.Check(t, is.DeepEqual(http.StatusBadRequest, res.StatusCode))
-}
-
-func TestResizeWhenContainerNotStarted(t *testing.T) {
-	ctx := setupTest(t)
-	apiClient := testEnv.APIClient()
+		// Manually creating a request here, as the APIClient would invalidate
+		// these values before they're sent.
+		res, _, err := req.Post(ctx, "/containers/"+cID+"/resize?h=foo&w=bar")
+		assert.NilError(t, err)
+		assert.Check(t, is.DeepEqual(http.StatusBadRequest, res.StatusCode))
+	})
 
 
-	cID := container.Create(ctx, t, apiClient, container.WithCmd("echo"))
-	err := apiClient.ContainerResize(ctx, cID, types.ResizeOptions{
-		Height: 40,
-		Width:  40,
+	t.Run("invalid state", func(t *testing.T) {
+		cID := container.Create(ctx, t, apiClient, container.WithCmd("echo"))
+		err := apiClient.ContainerResize(ctx, cID, types.ResizeOptions{
+			Height: 40,
+			Width:  40,
+		})
+		assert.Check(t, is.ErrorType(err, errdefs.IsConflict))
+		assert.Check(t, is.ErrorContains(err, "is not running"))
 	})
 	})
-	assert.Check(t, is.ErrorType(err, errdefs.IsConflict))
-	assert.Check(t, is.ErrorContains(err, "is not running"))
 }
 }