소스 검색

testutil: inline filters in tests

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 2 년 전
부모
커밋
c0c4a16053
4개의 변경된 파일12개의 추가작업 그리고 16개의 파일을 삭제
  1. 4 3
      testutil/daemon/service.go
  2. 1 3
      testutil/environment/clean.go
  3. 6 7
      testutil/environment/environment.go
  4. 1 3
      testutil/environment/protect.go

+ 4 - 3
testutil/daemon/service.go

@@ -55,9 +55,10 @@ func (d *Daemon) GetServiceTasks(t testing.TB, service string, additionalFilters
 	cli := d.NewClientT(t)
 	cli := d.NewClientT(t)
 	defer cli.Close()
 	defer cli.Close()
 
 
-	filterArgs := filters.NewArgs()
-	filterArgs.Add("desired-state", "running")
-	filterArgs.Add("service", service)
+	filterArgs := filters.NewArgs(
+		filters.Arg("desired-state", "running"),
+		filters.Arg("service", service),
+	)
 	for _, filter := range additionalFilters {
 	for _, filter := range additionalFilters {
 		filterArgs.Add(filter.Key, filter.Value)
 		filterArgs.Add(filter.Key, filter.Value)
 	}
 	}

+ 1 - 3
testutil/environment/clean.go

@@ -48,10 +48,8 @@ func unpauseAllContainers(t testing.TB, client client.ContainerAPIClient) {
 
 
 func getPausedContainers(ctx context.Context, t testing.TB, client client.ContainerAPIClient) []types.Container {
 func getPausedContainers(ctx context.Context, t testing.TB, client client.ContainerAPIClient) []types.Container {
 	t.Helper()
 	t.Helper()
-	filter := filters.NewArgs()
-	filter.Add("status", "paused")
 	containers, err := client.ContainerList(ctx, types.ContainerListOptions{
 	containers, err := client.ContainerList(ctx, types.ContainerListOptions{
-		Filters: filter,
+		Filters: filters.NewArgs(filters.Arg("status", "paused")),
 		All:     true,
 		All:     true,
 	})
 	})
 	assert.Check(t, err, "failed to list containers")
 	assert.Check(t, err, "failed to list containers")

+ 6 - 7
testutil/environment/environment.go

@@ -197,13 +197,12 @@ func (e *Execution) IsUserNamespaceInKernel() bool {
 // Note that this is done by filtering and then checking whether there were any
 // Note that this is done by filtering and then checking whether there were any
 // results -- so ambiguous references might result in false-positives.
 // results -- so ambiguous references might result in false-positives.
 func (e *Execution) HasExistingImage(t testing.TB, reference string) bool {
 func (e *Execution) HasExistingImage(t testing.TB, reference string) bool {
-	client := e.APIClient()
-	filter := filters.NewArgs()
-	filter.Add("dangling", "false")
-	filter.Add("reference", reference)
-	imageList, err := client.ImageList(context.Background(), types.ImageListOptions{
-		All:     true,
-		Filters: filter,
+	imageList, err := e.APIClient().ImageList(context.Background(), types.ImageListOptions{
+		All: true,
+		Filters: filters.NewArgs(
+			filters.Arg("dangling", "false"),
+			filters.Arg("reference", reference),
+		),
 	})
 	})
 	assert.NilError(t, err, "failed to list images")
 	assert.NilError(t, err, "failed to list images")
 
 

+ 1 - 3
testutil/environment/protect.go

@@ -100,11 +100,9 @@ func ProtectImages(t testing.TB, testEnv *Execution) {
 func getExistingImages(t testing.TB, testEnv *Execution) []string {
 func getExistingImages(t testing.TB, testEnv *Execution) []string {
 	t.Helper()
 	t.Helper()
 	client := testEnv.APIClient()
 	client := testEnv.APIClient()
-	filter := filters.NewArgs()
-	filter.Add("dangling", "false")
 	imageList, err := client.ImageList(context.Background(), types.ImageListOptions{
 	imageList, err := client.ImageList(context.Background(), types.ImageListOptions{
 		All:     true,
 		All:     true,
-		Filters: filter,
+		Filters: filters.NewArgs(filters.Arg("dangling", "false")),
 	})
 	})
 	assert.NilError(t, err, "failed to list images")
 	assert.NilError(t, err, "failed to list images")