Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[v2] Randomize test order for unit tests #3434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ format:
.PHONY: format

unit:
$(GO_TEST) ./...
$(GO_TEST) -shuffle on ./...
.PHONY: unit

coverage:
$(GO_TEST) -covermode count -coverprofile cover.out -coverpkg=./... ./...
$(GO_TEST) -shuffle on -covermode count -coverprofile cover.out -coverpkg=./... ./...
.PHONY: coverage

acceptance: acceptance-basic acceptance-baremetal acceptance-blockstorage acceptance-compute acceptance-container acceptance-containerinfra acceptance-db acceptance-dns acceptance-identity acceptance-image acceptance-keymanager acceptance-loadbalancer acceptance-messaging acceptance-networking acceptance-objectstorage acceptance-orchestration acceptance-placement acceptance-sharedfilesystems acceptance-workflow
Expand Down
12 changes: 6 additions & 6 deletions docs/contributor-tutorial/.template/testing/requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestListResources(t *testing.T) {
HandleListResourcesSuccessfully(t)

count := 0
err := resources.List(client.ServiceClient(), nil).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) {
err := resources.List(client.ServiceClient(fakeServer), nil).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) {
count++

actual, err := resources.ExtractResources(page)
Expand All @@ -35,7 +35,7 @@ func TestListResourcesAllPages(t *testing.T) {
defer th.TeardownHTTP()
HandleListResourcesSuccessfully(t)

allPages, err := resources.List(client.ServiceClient(), nil).AllPages(context.TODO())
allPages, err := resources.List(client.ServiceClient(fakeServer), nil).AllPages(context.TODO())
th.AssertNoErr(t, err)
actual, err := resources.ExtractResources(allPages)
th.AssertNoErr(t, err)
Expand All @@ -47,7 +47,7 @@ func TestGetResource(t *testing.T) {
defer th.TeardownHTTP()
HandleGetResourceSuccessfully(t)

actual, err := resources.Get(context.TODO(), client.ServiceClient(), "9fe1d3").Extract()
actual, err := resources.Get(context.TODO(), client.ServiceClient(fakeServer), "9fe1d3").Extract()
th.AssertNoErr(t, err)
th.AssertDeepEquals(t, SecondResource, *actual)
}
Expand All @@ -61,7 +61,7 @@ func TestCreateResource(t *testing.T) {
Name: "resource two",
}

actual, err := resources.Create(context.TODO(), client.ServiceClient(), createOpts).Extract()
actual, err := resources.Create(context.TODO(), client.ServiceClient(fakeServer), createOpts).Extract()
th.AssertNoErr(t, err)
th.AssertDeepEquals(t, SecondResource, *actual)
}
Expand All @@ -71,7 +71,7 @@ func TestDeleteResource(t *testing.T) {
defer th.TeardownHTTP()
HandleDeleteResourceSuccessfully(t)

res := resources.Delete(context.TODO(), client.ServiceClient(), "9fe1d3")
res := resources.Delete(context.TODO(), client.ServiceClient(fakeServer), "9fe1d3")
th.AssertNoErr(t, res.Err)
}

Expand All @@ -84,7 +84,7 @@ func TestUpdateResource(t *testing.T) {
Description: "Staging Resource",
}

actual, err := resources.Update(context.TODO(), client.ServiceClient(), "9fe1d3", updateOpts).Extract()
actual, err := resources.Update(context.TODO(), client.ServiceClient(fakeServer), "9fe1d3", updateOpts).Extract()
th.AssertNoErr(t, err)
th.AssertDeepEquals(t, SecondResourceUpdated, *actual)
}
8 changes: 4 additions & 4 deletions openstack/baremetal/apiversions/testing/fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ var IronicAllAPIVersionResults = apiversions.APIVersions{
},
}

func MockListResponse(t *testing.T) {
th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
func MockListResponse(t *testing.T, fakeServer th.FakeServer) {
fakeServer.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)

Expand All @@ -93,8 +93,8 @@ func MockListResponse(t *testing.T) {
})
}

func MockGetResponse(t *testing.T) {
th.Mux.HandleFunc("/v1/", func(w http.ResponseWriter, r *http.Request) {
func MockGetResponse(t *testing.T, fakeServer th.FakeServer) {
fakeServer.Mux.HandleFunc("/v1/", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)

Expand Down
16 changes: 8 additions & 8 deletions openstack/baremetal/apiversions/testing/requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ import (
)

func TestListAPIVersions(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
fakeServer := th.SetupHTTP()
defer fakeServer.Teardown()

MockListResponse(t)
MockListResponse(t, fakeServer)

actual, err := apiversions.List(context.TODO(), client.ServiceClient()).Extract()
actual, err := apiversions.List(context.TODO(), client.ServiceClient(fakeServer)).Extract()
th.AssertNoErr(t, err)

th.AssertDeepEquals(t, IronicAllAPIVersionResults, *actual)
}

func TestGetAPIVersion(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
fakeServer := th.SetupHTTP()
defer fakeServer.Teardown()

MockGetResponse(t)
MockGetResponse(t, fakeServer)

actual, err := apiversions.Get(context.TODO(), client.ServiceClient(), "v1").Extract()
actual, err := apiversions.Get(context.TODO(), client.ServiceClient(fakeServer), "v1").Extract()
th.AssertNoErr(t, err)

th.AssertDeepEquals(t, IronicAPIVersion1Result, *actual)
Expand Down
16 changes: 8 additions & 8 deletions openstack/baremetal/v1/allocations/testing/fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ var (
)

// HandleAllocationListSuccessfully sets up the test server to respond to a allocation List request.
func HandleAllocationListSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/allocations", func(w http.ResponseWriter, r *http.Request) {
func HandleAllocationListSuccessfully(t *testing.T, fakeServer th.FakeServer) {
fakeServer.Mux.HandleFunc("/allocations", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.Header().Add("Content-Type", "application/json")
Expand All @@ -132,8 +132,8 @@ func HandleAllocationListSuccessfully(t *testing.T) {

// HandleAllocationCreationSuccessfully sets up the test server to respond to a allocation creation request
// with a given response.
func HandleAllocationCreationSuccessfully(t *testing.T, response string) {
th.Mux.HandleFunc("/allocations", func(w http.ResponseWriter, r *http.Request) {
func HandleAllocationCreationSuccessfully(t *testing.T, fakeServer th.FakeServer, response string) {
fakeServer.Mux.HandleFunc("/allocations", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "POST")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
th.TestJSONRequest(t, r, `{
Expand All @@ -150,17 +150,17 @@ func HandleAllocationCreationSuccessfully(t *testing.T, response string) {
}

// HandleAllocationDeletionSuccessfully sets up the test server to respond to a allocation deletion request.
func HandleAllocationDeletionSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/allocations/344a3e2-978a-444e-990a-cbf47c62ef88", func(w http.ResponseWriter, r *http.Request) {
func HandleAllocationDeletionSuccessfully(t *testing.T, fakeServer th.FakeServer) {
fakeServer.Mux.HandleFunc("/allocations/344a3e2-978a-444e-990a-cbf47c62ef88", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "DELETE")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)

w.WriteHeader(http.StatusNoContent)
})
}

func HandleAllocationGetSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/allocations/344a3e2-978a-444e-990a-cbf47c62ef88", func(w http.ResponseWriter, r *http.Request) {
func HandleAllocationGetSuccessfully(t *testing.T, fakeServer th.FakeServer) {
fakeServer.Mux.HandleFunc("/allocations/344a3e2-978a-444e-990a-cbf47c62ef88", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
th.TestHeader(t, r, "Accept", "application/json")
Expand Down
32 changes: 16 additions & 16 deletions openstack/baremetal/v1/allocations/testing/requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
)

func TestListAllocations(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleAllocationListSuccessfully(t)
fakeServer := th.SetupHTTP()
defer fakeServer.Teardown()
HandleAllocationListSuccessfully(t, fakeServer)

pages := 0
err := allocations.List(client.ServiceClient(), allocations.ListOpts{}).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) {
err := allocations.List(client.ServiceClient(fakeServer), allocations.ListOpts{}).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) {
pages++

actual, err := allocations.ExtractAllocations(page)
Expand All @@ -41,11 +41,11 @@ func TestListAllocations(t *testing.T) {
}

func TestCreateAllocation(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleAllocationCreationSuccessfully(t, SingleAllocationBody)
fakeServer := th.SetupHTTP()
defer fakeServer.Teardown()
HandleAllocationCreationSuccessfully(t, fakeServer, SingleAllocationBody)

actual, err := allocations.Create(context.TODO(), client.ServiceClient(), allocations.CreateOpts{
actual, err := allocations.Create(context.TODO(), client.ServiceClient(fakeServer), allocations.CreateOpts{
Name: "allocation-1",
ResourceClass: "baremetal",
CandidateNodes: []string{"344a3e2-978a-444e-990a-cbf47c62ef88"},
Expand All @@ -57,20 +57,20 @@ func TestCreateAllocation(t *testing.T) {
}

func TestDeleteAllocation(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleAllocationDeletionSuccessfully(t)
fakeServer := th.SetupHTTP()
defer fakeServer.Teardown()
HandleAllocationDeletionSuccessfully(t, fakeServer)

res := allocations.Delete(context.TODO(), client.ServiceClient(), "344a3e2-978a-444e-990a-cbf47c62ef88")
res := allocations.Delete(context.TODO(), client.ServiceClient(fakeServer), "344a3e2-978a-444e-990a-cbf47c62ef88")
th.AssertNoErr(t, res.Err)
}

func TestGetAllocation(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleAllocationGetSuccessfully(t)
fakeServer := th.SetupHTTP()
defer fakeServer.Teardown()
HandleAllocationGetSuccessfully(t, fakeServer)

c := client.ServiceClient()
c := client.ServiceClient(fakeServer)
actual, err := allocations.Get(context.TODO(), c, "344a3e2-978a-444e-990a-cbf47c62ef88").Extract()
if err != nil {
t.Fatalf("Unexpected Get error: %v", err)
Expand Down
12 changes: 6 additions & 6 deletions openstack/baremetal/v1/conductors/testing/fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ var (
)

// HandleConductorListSuccessfully sets up the test server to respond to a server List request.
func HandleConductorListSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/conductors", func(w http.ResponseWriter, r *http.Request) {
func HandleConductorListSuccessfully(t *testing.T, fakeServer th.FakeServer) {
fakeServer.Mux.HandleFunc("/conductors", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.Header().Add("Content-Type", "application/json")
Expand All @@ -161,8 +161,8 @@ func HandleConductorListSuccessfully(t *testing.T) {
}

// HandleConductorListDetailSuccessfully sets up the test server to respond to a server List request.
func HandleConductorListDetailSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/conductors", func(w http.ResponseWriter, r *http.Request) {
func HandleConductorListDetailSuccessfully(t *testing.T, fakeServer th.FakeServer) {
fakeServer.Mux.HandleFunc("/conductors", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.Header().Add("Content-Type", "application/json")
Expand All @@ -174,8 +174,8 @@ func HandleConductorListDetailSuccessfully(t *testing.T) {
})
}

func HandleConductorGetSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/conductors/1234asdf", func(w http.ResponseWriter, r *http.Request) {
func HandleConductorGetSuccessfully(t *testing.T, fakeServer th.FakeServer) {
fakeServer.Mux.HandleFunc("/conductors/1234asdf", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
th.TestHeader(t, r, "Accept", "application/json")
Expand Down
24 changes: 12 additions & 12 deletions openstack/baremetal/v1/conductors/testing/requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
)

func TestListConductors(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleConductorListSuccessfully(t)
fakeServer := th.SetupHTTP()
defer fakeServer.Teardown()
HandleConductorListSuccessfully(t, fakeServer)

pages := 0
err := conductors.List(client.ServiceClient(), conductors.ListOpts{}).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) {
err := conductors.List(client.ServiceClient(fakeServer), conductors.ListOpts{}).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) {
pages++

actual, err := conductors.ExtractConductors(page)
Expand All @@ -41,12 +41,12 @@ func TestListConductors(t *testing.T) {
}

func TestListDetailConductors(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleConductorListDetailSuccessfully(t)
fakeServer := th.SetupHTTP()
defer fakeServer.Teardown()
HandleConductorListDetailSuccessfully(t, fakeServer)

pages := 0
err := conductors.List(client.ServiceClient(), conductors.ListOpts{Detail: true}).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) {
err := conductors.List(client.ServiceClient(fakeServer), conductors.ListOpts{Detail: true}).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) {
pages++

actual, err := conductors.ExtractConductors(page)
Expand Down Expand Up @@ -93,11 +93,11 @@ func TestListOpts(t *testing.T) {
}

func TestGetConductor(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleConductorGetSuccessfully(t)
fakeServer := th.SetupHTTP()
defer fakeServer.Teardown()
HandleConductorGetSuccessfully(t, fakeServer)

c := client.ServiceClient()
c := client.ServiceClient(fakeServer)
actual, err := conductors.Get(context.TODO(), c, "1234asdf").Extract()
if err != nil {
t.Fatalf("Unexpected Get error: %v", err)
Expand Down
16 changes: 8 additions & 8 deletions openstack/baremetal/v1/drivers/testing/fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ var (
)

// HandleListDriversSuccessfully sets up the test server to respond to a drivers ListDrivers request.
func HandleListDriversSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/drivers", func(w http.ResponseWriter, r *http.Request) {
func HandleListDriversSuccessfully(t *testing.T, fakeServer th.FakeServer) {
fakeServer.Mux.HandleFunc("/drivers", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.Header().Add("Content-Type", "application/json")
Expand All @@ -382,8 +382,8 @@ func HandleListDriversSuccessfully(t *testing.T) {
}

// HandleGetDriverDetailsSuccessfully sets up the test server to respond to a drivers GetDriverDetails request.
func HandleGetDriverDetailsSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/drivers/ipmi", func(w http.ResponseWriter, r *http.Request) {
func HandleGetDriverDetailsSuccessfully(t *testing.T, fakeServer th.FakeServer) {
fakeServer.Mux.HandleFunc("/drivers/ipmi", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
th.TestHeader(t, r, "Accept", "application/json")
Expand All @@ -393,8 +393,8 @@ func HandleGetDriverDetailsSuccessfully(t *testing.T) {
}

// HandleGetDriverPropertiesSuccessfully sets up the test server to respond to a drivers GetDriverProperties request.
func HandleGetDriverPropertiesSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/drivers/agent_ipmitool/properties", func(w http.ResponseWriter, r *http.Request) {
func HandleGetDriverPropertiesSuccessfully(t *testing.T, fakeServer th.FakeServer) {
fakeServer.Mux.HandleFunc("/drivers/agent_ipmitool/properties", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
th.TestHeader(t, r, "Accept", "application/json")
Expand All @@ -404,8 +404,8 @@ func HandleGetDriverPropertiesSuccessfully(t *testing.T) {
}

// HandleGetDriverDiskPropertiesSuccessfully sets up the test server to respond to a drivers GetDriverDiskProperties request.
func HandleGetDriverDiskPropertiesSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/drivers/agent_ipmitool/raid/logical_disk_properties", func(w http.ResponseWriter, r *http.Request) {
func HandleGetDriverDiskPropertiesSuccessfully(t *testing.T, fakeServer th.FakeServer) {
fakeServer.Mux.HandleFunc("/drivers/agent_ipmitool/raid/logical_disk_properties", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
th.TestHeader(t, r, "Accept", "application/json")
Expand Down
Loading
Loading