-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Proposal
The library currently lacks built-in testing support, forcing users to implement their own mocks or manage complex infrastructure for integration tests. I propose adding a testutil package to provide a flexible MockClient and a TestServer helper.
Proposed Solution
The testutil package will focus on two areas:
- Unit Testing: A function-based
MockClientthat allows users to inject custom behavior per test case without implementing the entire interface manually. - Integration Testing: A
TestServerthat wrapshttptest.Serverto simulate the scaleset API, allowing users to verify their full networking stack.
Mock Implementation
package testutil
import (
"context"
"github.com/actions/scaleset"
)
// MockClient provides a flexible mock for the listener.Client interface.
type MockClient struct {
GetMessageFunc func(ctx context.Context, lastID, cap int) (*scaleset.RunnerScaleSetMessage, error)
DeleteMessageFunc func(ctx context.Context, messageID int) error
SessionFunc func() scaleset.RunnerScaleSetSession
CloseFunc func(ctx context.Context) error
}
func (m *MockClient) GetMessage(ctx context.Context, lastID, cap int) (*scaleset.RunnerScaleSetMessage, error) {
if m.GetMessageFunc != nil {
return m.GetMessageFunc(ctx, lastID, cap)
}
return nil, nil
}
// ... other interface methods implemented similarly ...Integration Helper
// TestServer simulates the scaleset API for end-to-end testing.
type TestServer struct {
URL string
Client *scaleset.Client
}
func NewTestServer(t *testing.T, options ...TestServerOption) *TestServer
func (s *TestServer) EnqueueMessage(msg *scaleset.RunnerScaleSetMessage)
func (s *TestServer) GetReceivedDeleteRequests() []intBenefits
- Reduced Boilerplate: Users don't need to redefine interfaces or mock logic in every downstream project.
- Reliable Integration: The
TestServerensures that user-implemented scalers handle real HTTP interactions, including headers and status codes, correctly. - Consistency: Provides a standard way to test scaleset logic across different implementations.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels