1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-09-05 18:40:59 +00:00

chore: use t.Context for tests, activate usetesting for lint + add t.TempDir and t.Chdir (#844)

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- other
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/844): <!--number 844 --><!--line 0 --><!--description Y2hvcmU6IHVzZSB0LkNvbnRleHQgZm9yIHRlc3RzLCBhY3RpdmF0ZSB1c2V0ZXN0aW5nIGZvciBsaW50ICsgYWRkIHQuVGVtcERpciBhbmQgdC5DaGRpciBbc2tpcCBjYXNjYWRlXQ==-->chore: use t.Context for tests, activate usetesting for lint + add t.TempDir and t.Chdir [skip cascade]<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/844
Reviewed-by: Gusted <gusted@noreply.code.forgejo.org>
Co-authored-by: Earl Warren <contact@earl-warren.org>
Co-committed-by: Earl Warren <contact@earl-warren.org>
This commit is contained in:
Earl Warren 2025-08-11 13:21:42 +00:00 committed by earl-warren
parent 66bb63ea18
commit 0520ff4e05
No known key found for this signature in database
GPG key ID: F128CBE6AB3A7201
22 changed files with 126 additions and 153 deletions

View file

@ -2,7 +2,6 @@ package runner
import (
"bytes"
"context"
"io"
"os"
"testing"
@ -16,7 +15,7 @@ import (
func TestCommandSetEnv(t *testing.T) {
a := assert.New(t)
ctx := context.Background()
ctx := t.Context()
rc := new(RunContext)
handler := rc.commandHandler(ctx)
@ -26,7 +25,7 @@ func TestCommandSetEnv(t *testing.T) {
func TestCommandSetOutput(t *testing.T) {
a := assert.New(t)
ctx := context.Background()
ctx := t.Context()
rc := new(RunContext)
rc.StepResults = make(map[string]*model.StepResult)
handler := rc.commandHandler(ctx)
@ -56,7 +55,7 @@ func TestCommandSetOutput(t *testing.T) {
func TestCommandAddpath(t *testing.T) {
a := assert.New(t)
ctx := context.Background()
ctx := t.Context()
rc := new(RunContext)
handler := rc.commandHandler(ctx)
@ -71,7 +70,7 @@ func TestCommandStopCommands(t *testing.T) {
logger, hook := test.NewNullLogger()
a := assert.New(t)
ctx := common.WithLogger(context.Background(), logger)
ctx := common.WithLogger(t.Context(), logger)
rc := new(RunContext)
handler := rc.commandHandler(ctx)
@ -94,7 +93,7 @@ func TestCommandStopCommands(t *testing.T) {
func TestCommandAddpathADO(t *testing.T) {
a := assert.New(t)
ctx := context.Background()
ctx := t.Context()
rc := new(RunContext)
handler := rc.commandHandler(ctx)
@ -109,7 +108,7 @@ func TestCommandAddmask(t *testing.T) {
logger, hook := test.NewNullLogger()
a := assert.New(t)
ctx := context.Background()
ctx := t.Context()
loggerCtx := common.WithLogger(ctx, logger)
rc := new(RunContext)
@ -163,7 +162,7 @@ func TestCommandAddmaskUsemask(t *testing.T) {
}
re := captureOutput(t, func() {
ctx := context.Background()
ctx := t.Context()
ctx = WithJobLogger(ctx, "0", "testjob", config, &rc.Masks, map[string]interface{}{})
handler := rc.commandHandler(ctx)
@ -180,7 +179,7 @@ func TestCommandSaveState(t *testing.T) {
StepResults: map[string]*model.StepResult{},
}
ctx := context.Background()
ctx := t.Context()
handler := rc.commandHandler(ctx)
handler("::save-state name=state-name::state-value\n")