testhelpers

package
v19.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KASUserAgent                 = "kas/v0.1-blabla/asdwd"
	AgentToken    api.AgentToken = "123123"
	AuthSecretKey                = "blablabla"

	ProjectID       int64 = 321
	UserID          int64 = 456
	ConfigProjectID int64 = 5
)

Variables

View Source
var (
	AgentkKey1 = api.AgentKey{
		ID:   123,
		Type: api.AgentTypeKubernetes,
	}
	AgentkKey2 = api.AgentKey{
		ID:   456,
		Type: api.AgentTypeKubernetes,
	}
	AgentwKey1 = api.AgentKey{
		ID:   1123,
		Type: api.AgentTypeWorkspace,
	}
	RunnerControllerKey1 = api.AgentKey{
		ID:   2102,
		Type: api.AgentTypeRunnerController,
	}
	RunnerKey1 = api.AgentKey{
		ID:   3333,
		Type: api.AgentTypeRunner,
	}
)

Validator is the shared protovalidate validator for use in tests. Use this instead of protovalidate.GlobalValidator directly.

Functions

func AgentkInfoObj

func AgentkInfoObj() *server_api.AgentkInfo

func AgentwInfoObj

func AgentwInfoObj() *server_api.AgentwInfo

func AssertCommonRequestParams

func AssertCommonRequestParams(t *testing.T, r *http.Request, traceID trace.TraceID)

func AssertGetJSONRequest

func AssertGetJSONRequest(t *testing.T, r *http.Request)

func AssertGetJSONRequestIsCorrect

func AssertGetJSONRequestIsCorrect(t *testing.T, r *http.Request, traceID trace.TraceID)

func AssertGetRequestIsCorrect

func AssertGetRequestIsCorrect(t *testing.T, r *http.Request, traceID trace.TraceID)

func AssertInvalid

func AssertInvalid(t *testing.T, tests []InvalidTestcase)

func AssertJWTSignature

func AssertJWTSignature(t *testing.T, r *http.Request)

func AssertRequestAccept

func AssertRequestAccept(t *testing.T, r *http.Request, accept string)

func AssertRequestAcceptJSON

func AssertRequestAcceptJSON(t *testing.T, r *http.Request)

func AssertRequestContentTypeJSON

func AssertRequestContentTypeJSON(t *testing.T, r *http.Request) bool

func AssertRequestMethod

func AssertRequestMethod(t *testing.T, r *http.Request, method string)

func AssertRequestUserAgent

func AssertRequestUserAgent(t *testing.T, r *http.Request, userAgent string)

func AssertValid

func AssertValid(t *testing.T, tests []ValidTestcase)

func CtxWithSpanContext

func CtxWithSpanContext(t *testing.T) (context.Context, trace.TraceID)

func GenerateCACert

func GenerateCACert(t *testing.T) (string, string, *x509.Certificate, crypto.PrivateKey)

func GenerateCert

func GenerateCert(t *testing.T, name string, caCert *x509.Certificate, caKey crypto.PrivateKey) (string, string)

func GenerateCertInMem

func GenerateCertInMem(t *testing.T, name string, caCert *x509.Certificate, caKey crypto.PrivateKey) ([]byte, []byte)

func IgnoreProxyEnv added in v19.3.0

func IgnoreProxyEnv(t *testing.T)

IgnoreProxyEnv empties the proxy environment variables for the duration of the test so that a proxy configured on the machine running the tests cannot intercept the requests the test makes. A test that expects a connection to fail needs this in particular: a proxy answers such a request instead of letting it fail.

This is for a test that exercises a client with its default transport. A client the test constructs itself is better told not to use a proxy at all, e.g. with gitlab.WithoutProxy(), which needs neither of the caveats below.

net/http resolves the proxy environment exactly once per process, on the first request made through http.ProxyFromEnvironment, and caches the result. Emptying the variables therefore only has an effect while no such request has been made yet, so every test in a package that makes them should call this: whichever runs first then populates the cache with an empty configuration for all the others.

Cannot be combined with t.Parallel(), because t.Setenv() forbids it.

func InjectSpanContext

func InjectSpanContext(t *testing.T, ctx context.Context) (context.Context, trace.TraceID)

func NewPollConfig

func NewPollConfig(interval time.Duration) retry.PollConfig

func ReadProtoJSONRequest

func ReadProtoJSONRequest(t *testing.T, r *http.Request, m proto.Message) bool

func RecvMsg

func RecvMsg(value any) func(any) error

func RespondWithJSON

func RespondWithJSON(t *testing.T, w http.ResponseWriter, response any)

RespondWithJSON marshals response into JSON and writes it into w.

func RespondWithJSONAndStatus

func RespondWithJSONAndStatus(t *testing.T, w http.ResponseWriter, statusCode int, response any)

func RunnerControllerInfoObj

func RunnerControllerInfoObj() *server_api.RunnerControllerInfo

func SetValue

func SetValue(target, value any)

SetValue sets target to value with special handling for proto.Message. target must be a pointer. i.e. *blaProtoMsgType value must be of the same type as target.

func SkipInCI

func SkipInCI(t testing.TB)

func SkipNotIntegration

func SkipNotIntegration(t testing.TB)

Types

type InvalidTestcase

type InvalidTestcase struct {
	ErrString string
	Invalid   proto.Message
}

type ValidTestcase

type ValidTestcase struct {
	Name  string
	Valid proto.Message
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL