github.com/vmware/go-vcloud-director/v2@v2.24.0/govcd/task_test.go (about)

     1  //go:build task || functional || ALL
     2  
     3  /*
     4   * Copyright 2022 VMware, Inc.  All rights reserved.  Licensed under the Apache v2 License.
     5   */
     6  
     7  package govcd
     8  
     9  import (
    10  	"fmt"
    11  	"time"
    12  
    13  	"github.com/kr/pretty"
    14  	. "gopkg.in/check.v1"
    15  )
    16  
    17  func (vcd *TestVCD) Test_QueryTaskList(check *C) {
    18  	fmt.Printf("Running: %s\n", check.TestName())
    19  
    20  	adminOrg, err := vcd.client.GetAdminOrgByName(vcd.config.VCD.Org)
    21  	check.Assert(err, IsNil)
    22  
    23  	catalog, err := adminOrg.GetCatalogByName(vcd.config.VCD.Catalog.Name, false)
    24  	check.Assert(err, IsNil)
    25  	adminCatalog, err := adminOrg.GetAdminCatalogByName(vcd.config.VCD.Catalog.Name, false)
    26  	check.Assert(err, IsNil)
    27  	startQuery := time.Now()
    28  	allTasks, err := vcd.client.Client.QueryTaskList(map[string]string{
    29  		"status": "running,preRunning,queued",
    30  	})
    31  	check.Assert(err, IsNil)
    32  	if testVerbose {
    33  		fmt.Printf("%# v\n%s\n", pretty.Formatter(allTasks), time.Since(startQuery))
    34  	}
    35  	// search using a client, giving the org and catalog names
    36  	resultByClient, err := vcd.client.Client.QueryTaskList(map[string]string{
    37  		"orgName":    vcd.config.VCD.Org,
    38  		"objectName": adminCatalog.AdminCatalog.Name,
    39  		"name":       "catalogCreateCatalog"})
    40  	check.Assert(err, IsNil)
    41  
    42  	// search using an admin catalog, which will search by its HREF
    43  	resultByAdminCatalog, err := adminCatalog.QueryTaskList(map[string]string{
    44  		"name": "catalogCreateCatalog",
    45  	})
    46  	check.Assert(err, IsNil)
    47  	// search using a catalog, which will search by its HREF
    48  	resultByCatalog, err := catalog.QueryTaskList(map[string]string{
    49  		"name": "catalogCreateCatalog",
    50  	})
    51  	check.Assert(err, IsNil)
    52  
    53  	check.Assert(len(resultByClient), Equals, len(resultByAdminCatalog))
    54  	check.Assert(len(resultByClient), Equals, len(resultByCatalog))
    55  	if len(resultByAdminCatalog) > 0 {
    56  		// there should be only one task for catalog creation
    57  		check.Assert(len(resultByClient), Equals, 1)
    58  		// check correspondence between task and its related object
    59  		// and also that all sets have returned the same result
    60  		catalogHref, err := adminCatalog.GetCatalogHref()
    61  		check.Assert(err, IsNil)
    62  		check.Assert(resultByAdminCatalog[0].HREF, Equals, resultByClient[0].HREF)
    63  		check.Assert(resultByCatalog[0].HREF, Equals, resultByClient[0].HREF)
    64  		check.Assert(resultByClient[0].Object, Equals, catalogHref)
    65  		check.Assert(resultByAdminCatalog[0].ObjectName, Equals, adminCatalog.AdminCatalog.Name)
    66  		check.Assert(resultByCatalog[0].ObjectName, Equals, adminCatalog.AdminCatalog.Name)
    67  		check.Assert(resultByAdminCatalog[0].ObjectType, Equals, "catalog")
    68  		check.Assert(resultByCatalog[0].ObjectType, Equals, "catalog")
    69  	}
    70  }
    71  
    72  func init() {
    73  	testingTags["task"] = "task_test.go"
    74  }