Skip to content
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

Test Integration: Remove framework/util #7688

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
710ae56
Test Integration: Remove framework/util
JoshVanL Apr 11, 2024
43910c7
Fix eventually checks in operator informer int tests
JoshVanL May 6, 2024
0c4ef08
Remove new references to `framework/util`
JoshVanL May 7, 2024
d266129
Merge branch 'master' into test-integration-remove-util
dapr-bot May 24, 2024
fdcf8eb
Merge branch 'master' into test-integration-remove-util
artursouza May 25, 2024
a5c3a48
Merge branch 'master' into test-integration-remove-util
dapr-bot May 28, 2024
69f8078
Merge branch 'master' into test-integration-remove-util
dapr-bot May 31, 2024
73a98b6
Merge branch 'master' into test-integration-remove-util
dapr-bot Jun 1, 2024
e0a8a57
Merge branch 'master' into test-integration-remove-util
dapr-bot Jun 3, 2024
2d7d9ca
Merge branch 'master' into test-integration-remove-util
dapr-bot Jun 6, 2024
484a19e
Merge branch 'master' into test-integration-remove-util
dapr-bot Jun 6, 2024
bc77751
Merge branch 'master' into test-integration-remove-util
dapr-bot Jun 11, 2024
7c82eaa
Merge branch 'master' into test-integration-remove-util
dapr-bot Jun 13, 2024
dc89bff
Merge branch 'master' into test-integration-remove-util
dapr-bot Jun 14, 2024
c2157b9
Merge branch 'master' into test-integration-remove-util
dapr-bot Jun 17, 2024
a82cbc7
Merge branch 'master' into test-integration-remove-util
dapr-bot Jun 18, 2024
85bdba2
Merge branch 'master' into test-integration-remove-util
dapr-bot Jun 18, 2024
4a292df
Merge branch 'master' into test-integration-remove-util
dapr-bot Jun 19, 2024
37f3ab1
Merge branch 'master' into test-integration-remove-util
dapr-bot Jun 19, 2024
862a880
Merge branch 'master' into test-integration-remove-util
dapr-bot Jun 20, 2024
fbc24e6
Merge branch 'master' into test-integration-remove-util
dapr-bot Jun 20, 2024
cf490fc
Merge branch 'master' into test-integration-remove-util
dapr-bot Jun 20, 2024
ec365f9
Merge branch 'master' into test-integration-remove-util
dapr-bot Jun 21, 2024
779d27b
Merge branch 'master' into test-integration-remove-util
dapr-bot Jun 21, 2024
7a645eb
Merge branch 'master' into test-integration-remove-util
dapr-bot Jun 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 The Dapr Authors
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand All @@ -11,19 +11,19 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package util
package client

import (
"net/http"
"testing"
"time"
)

// HTTPClient returns a Go http.Client which has a default timeout of 10
// seconds, and separate connection pool to the default allowing tests to be
// properly isolated when running in parallel.
// HTTP returns a Go http.Client which has a default timeout of 10 seconds,
// and separate connection pool to the default allowing tests to be properly
// isolated when running in parallel.
// The returned client will call CloseIdleConnections on test cleanup.
func HTTPClient(t *testing.T) *http.Client {
func HTTP(t *testing.T) *http.Client {
client := &http.Client{
Timeout: time.Second * 10,
Transport: http.DefaultTransport.(*http.Transport).Clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,44 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package util
package file

import (
"crypto/rand"
"math/big"
"path/filepath"
"testing"

"github.com/stretchr/testify/require"
)

// RandomString generates a random string of length n.
func RandomString(t *testing.T, n int) string {
t.Helper()
func Names(t *testing.T, num int) []string {
require.GreaterOrEqual(t, num, 1)

names := make([]string, num)
for i := 0; i < num; i++ {
names[i] = name(t)
}

return names
}

func Paths(t *testing.T, num int) []string {
require.GreaterOrEqual(t, num, 1)

dir := t.TempDir()
names := make([]string, num)
for i := 0; i < num; i++ {
names[i] = filepath.Join(dir, name(t))
}

return names
}

func name(t *testing.T) string {
const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
bytes := make([]byte, n)

bytes := make([]byte, 10)
_, err := rand.Read(bytes)
require.NoError(t, err)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package util
package parallel

import (
"os"
Expand All @@ -23,17 +23,17 @@ import (
"github.com/stretchr/testify/require"
)

// ParallelTest is a helper for running tests in parallel without having to
// create new Go test functions.
type ParallelTest struct {
// Test is a helper for running tests in parallel without having to create new
// Go test functions.
type Test struct {
lock sync.Mutex
fns []func(*assert.CollectT)
}

// NewParallel creates a new ParallelTest.
// New creates a new Test.
// Tests are executed during given test's cleanup.
func NewParallel(t *testing.T, fns ...func(*assert.CollectT)) *ParallelTest {
p := &ParallelTest{
func New(t *testing.T, fns ...func(*assert.CollectT)) *Test {
p := &Test{
fns: fns,
}
t.Cleanup(func() {
Expand Down Expand Up @@ -77,15 +77,15 @@ func NewParallel(t *testing.T, fns ...func(*assert.CollectT)) *ParallelTest {
return p
}

func (p *ParallelTest) worker(jobs <-chan func()) {
func (t *Test) worker(jobs <-chan func()) {
for j := range jobs {
j()
}
}

// Add adds a test function to be executed in parallel.
func (p *ParallelTest) Add(fn func(*assert.CollectT)) {
p.lock.Lock()
defer p.lock.Unlock()
p.fns = append(p.fns, fn)
func (t *Test) Add(fn func(*assert.CollectT)) {
t.lock.Lock()
defer t.lock.Unlock()
t.fns = append(t.fns, fn)
}
10 changes: 5 additions & 5 deletions tests/integration/framework/process/daprd/daprd.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ import (

rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework/binary"
"github.com/dapr/dapr/tests/integration/framework/client"
"github.com/dapr/dapr/tests/integration/framework/process"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
prochttp "github.com/dapr/dapr/tests/integration/framework/process/http"
"github.com/dapr/dapr/tests/integration/framework/process/ports"
"github.com/dapr/dapr/tests/integration/framework/util"
)

type Daprd struct {
Expand Down Expand Up @@ -160,7 +160,7 @@ func New(t *testing.T, fopts ...Option) *Daprd {
return &Daprd{
exec: exec.New(t, binary.EnvValue("daprd"), args, opts.execOpts...),
ports: fp,
httpClient: util.HTTPClient(t),
httpClient: client.HTTP(t),
appHTTP: appHTTP,
appID: opts.appID,
namespace: ns,
Expand Down Expand Up @@ -199,7 +199,7 @@ func (d *Daprd) WaitUntilTCPReady(t *testing.T, ctx context.Context) {
}

func (d *Daprd) WaitUntilRunning(t *testing.T, ctx context.Context) {
client := util.HTTPClient(t)
client := client.HTTP(t)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("http://%s/v1.0/healthz", d.HTTPAddress()), nil)
require.NoError(t, err)
require.Eventually(t, func() bool {
Expand All @@ -215,7 +215,7 @@ func (d *Daprd) WaitUntilRunning(t *testing.T, ctx context.Context) {
func (d *Daprd) WaitUntilAppHealth(t *testing.T, ctx context.Context) {
switch d.appProtocol {
case "http":
client := util.HTTPClient(t)
client := client.HTTP(t)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("http://%s/v1.0/healthz", d.HTTPAddress()), nil)
require.NoError(t, err)
assert.Eventually(t, func() bool {
Expand Down Expand Up @@ -384,7 +384,7 @@ func (d *Daprd) http2xx(t *testing.T, ctx context.Context, method, path string,
require.Less(t, resp.StatusCode, 300, "expected 2xx status code")
}

func (d *Daprd) GetMetaRegistedComponents(t assert.TestingT, ctx context.Context) []*rtv1.RegisteredComponents {
func (d *Daprd) GetMetaRegisteredComponents(t assert.TestingT, ctx context.Context) []*rtv1.RegisteredComponents {
return d.meta(t, ctx).RegisteredComponents
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import (
"github.com/stretchr/testify/require"

"github.com/dapr/dapr/pkg/runtime/pubsub"
"github.com/dapr/dapr/tests/integration/framework/client"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/http/app"
"github.com/dapr/dapr/tests/integration/framework/util"
)

type Option func(*options)
Expand Down Expand Up @@ -129,7 +129,7 @@ func New(t *testing.T, fopts ...Option) *Subscriber {

return &Subscriber{
app: app.New(t, appOpts...),
client: util.HTTPClient(t),
client: client.HTTP(t),
inCh: inCh,
inBulk: inBulk,
closeCh: closeCh,
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/framework/process/injector/injector.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import (
admissionregistrationv1 "k8s.io/api/admissionregistration/v1"

"github.com/dapr/dapr/tests/integration/framework/binary"
"github.com/dapr/dapr/tests/integration/framework/client"
"github.com/dapr/dapr/tests/integration/framework/process"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/kubernetes"
"github.com/dapr/dapr/tests/integration/framework/process/ports"
"github.com/dapr/dapr/tests/integration/framework/util"
)

type Injector struct {
Expand Down Expand Up @@ -127,7 +127,7 @@ func (i *Injector) Cleanup(t *testing.T) {
}

func (i *Injector) WaitUntilRunning(t *testing.T, ctx context.Context) {
client := util.HTTPClient(t)
client := client.HTTP(t)
//nolint:testifylint
assert.EventuallyWithT(t, func(t *assert.CollectT) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("http://localhost:%d/healthz", i.healthzPort), nil)
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/framework/process/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ import (
operatorv1pb "github.com/dapr/dapr/pkg/proto/operator/v1"
"github.com/dapr/dapr/pkg/security"
"github.com/dapr/dapr/tests/integration/framework/binary"
"github.com/dapr/dapr/tests/integration/framework/client"
"github.com/dapr/dapr/tests/integration/framework/process"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/ports"
"github.com/dapr/dapr/tests/integration/framework/process/sentry"
"github.com/dapr/dapr/tests/integration/framework/util"
"github.com/dapr/kit/ptr"
)

Expand Down Expand Up @@ -116,7 +116,7 @@ func (o *Operator) Cleanup(t *testing.T) {
}

func (o *Operator) WaitUntilRunning(t *testing.T, ctx context.Context) {
client := util.HTTPClient(t)
client := client.HTTP(t)
assert.Eventually(t, func() bool {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("http://localhost:%d/healthz", o.healthzPort), nil)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/framework/process/placement/placement.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ import (

placementv1pb "github.com/dapr/dapr/pkg/proto/placement/v1"
"github.com/dapr/dapr/tests/integration/framework/binary"
"github.com/dapr/dapr/tests/integration/framework/client"
"github.com/dapr/dapr/tests/integration/framework/process"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/ports"
"github.com/dapr/dapr/tests/integration/framework/util"
)

type Placement struct {
Expand Down Expand Up @@ -133,7 +133,7 @@ func (p *Placement) Cleanup(t *testing.T) {
}

func (p *Placement) WaitUntilRunning(t *testing.T, ctx context.Context) {
client := util.HTTPClient(t)
client := client.HTTP(t)
assert.Eventually(t, func() bool {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("http://127.0.0.1:%d/healthz", p.healthzPort), nil)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/framework/process/sentry/sentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ import (

"github.com/dapr/dapr/pkg/sentry/server/ca"
"github.com/dapr/dapr/tests/integration/framework/binary"
"github.com/dapr/dapr/tests/integration/framework/client"
"github.com/dapr/dapr/tests/integration/framework/process"
"github.com/dapr/dapr/tests/integration/framework/process/exec"
"github.com/dapr/dapr/tests/integration/framework/process/ports"
"github.com/dapr/dapr/tests/integration/framework/util"
)

type Sentry struct {
Expand Down Expand Up @@ -155,7 +155,7 @@ func (s *Sentry) Cleanup(t *testing.T) {
}

func (s *Sentry) WaitUntilRunning(t *testing.T, ctx context.Context) {
client := util.HTTPClient(t)
client := client.HTTP(t)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("http://localhost:%d/healthz", s.healthzPort), nil)
require.NoError(t, err)

Expand Down
6 changes: 3 additions & 3 deletions tests/integration/framework/socket/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/stretchr/testify/require"
"golang.org/x/net/nettest"

"github.com/dapr/dapr/tests/integration/framework/util"
"github.com/dapr/dapr/tests/integration/framework/file"
)

// Socket is a helper to create a temporary directory hosting unix socket files
Expand All @@ -46,7 +46,7 @@ func New(t *testing.T) *Socket {
tmp, err := nettest.LocalPath()
require.NoError(t, err)

socketDir := filepath.Join(tmp, util.RandomString(t, 4))
socketDir := filepath.Join(tmp, file.Names(t, 1)[0])
require.NoError(t, os.MkdirAll(socketDir, 0o700))
t.Cleanup(func() { require.NoError(t, os.RemoveAll(tmp)) })

Expand All @@ -60,7 +60,7 @@ func (s *Socket) Directory() string {
}

func (s *Socket) File(t *testing.T) *File {
socketFile := util.RandomString(t, 8)
socketFile := file.Names(t, 1)[0]
return &File{
name: socketFile,
filename: filepath.Join(s.dir, socketFile+".sock"),
Expand Down
63 changes: 0 additions & 63 deletions tests/integration/framework/util/file.go

This file was deleted.