mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-09-10 18:50: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:
parent
66bb63ea18
commit
0520ff4e05
22 changed files with 126 additions and 153 deletions
|
@ -229,8 +229,7 @@ func TestRunner_RunEvent(t *testing.T) {
|
|||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
tables := []TestJobFileInfo{
|
||||
// Shells
|
||||
|
@ -370,8 +369,7 @@ func TestRunner_DryrunEvent(t *testing.T) {
|
|||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(common.WithDryrun(context.Background(), true))
|
||||
defer cancel()
|
||||
ctx := common.WithDryrun(t.Context(), true)
|
||||
|
||||
tables := []TestJobFileInfo{
|
||||
// Shells
|
||||
|
@ -400,8 +398,7 @@ func TestRunner_DockerActionForcePullForceRebuild(t *testing.T) {
|
|||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
config := &Config{
|
||||
ForcePull: true,
|
||||
|
@ -434,7 +431,7 @@ func TestRunner_RunDifferentArchitecture(t *testing.T) {
|
|||
platforms: platforms,
|
||||
}
|
||||
|
||||
tjfi.runTest(context.Background(), t, &Config{ContainerArchitecture: "linux/arm64"})
|
||||
tjfi.runTest(t.Context(), t, &Config{ContainerArchitecture: "linux/arm64"})
|
||||
}
|
||||
|
||||
type runSkippedHook struct {
|
||||
|
@ -469,7 +466,7 @@ func TestRunner_RunSkipped(t *testing.T) {
|
|||
}
|
||||
|
||||
h := &runSkippedHook{resultKey: what + "Result"}
|
||||
ctx := common.WithLoggerHook(context.Background(), h)
|
||||
ctx := common.WithLoggerHook(t.Context(), h)
|
||||
|
||||
jobLoggerLevel := log.InfoLevel
|
||||
tjfi.runTest(ctx, t, &Config{ContainerArchitecture: "linux/arm64", JobLoggerLevel: &jobLoggerLevel})
|
||||
|
@ -514,7 +511,7 @@ func TestRunner_MaskValues(t *testing.T) {
|
|||
}
|
||||
|
||||
logger := &maskJobLoggerFactory{}
|
||||
tjfi.runTest(WithJobLoggerFactory(common.WithLogger(context.Background(), logger.WithJobLogger()), logger), t, &Config{})
|
||||
tjfi.runTest(WithJobLoggerFactory(common.WithLogger(t.Context(), logger.WithJobLogger()), logger), t, &Config{})
|
||||
output := logger.Output.String()
|
||||
|
||||
assertNoSecret(output, "secret value")
|
||||
|
@ -540,7 +537,7 @@ func TestRunner_RunEventSecrets(t *testing.T) {
|
|||
secrets, _ := godotenv.Read(filepath.Join(workdir, workflowPath, ".secrets"))
|
||||
assert.NoError(t, err, "Failed to read .secrets")
|
||||
|
||||
tjfi.runTest(context.Background(), t, &Config{Secrets: secrets, Env: env})
|
||||
tjfi.runTest(t.Context(), t, &Config{Secrets: secrets, Env: env})
|
||||
}
|
||||
|
||||
func TestRunner_RunWithService(t *testing.T) {
|
||||
|
@ -549,8 +546,7 @@ func TestRunner_RunWithService(t *testing.T) {
|
|||
}
|
||||
|
||||
log.SetLevel(log.DebugLevel)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
platforms := map[string]string{
|
||||
"ubuntu-latest": "code.forgejo.org/oci/node:22",
|
||||
|
@ -599,7 +595,7 @@ func TestRunner_RunActionInputs(t *testing.T) {
|
|||
"SOME_INPUT": "input",
|
||||
}
|
||||
|
||||
tjfi.runTest(context.Background(), t, &Config{Inputs: inputs})
|
||||
tjfi.runTest(t.Context(), t, &Config{Inputs: inputs})
|
||||
}
|
||||
|
||||
func TestRunner_RunEventPullRequest(t *testing.T) {
|
||||
|
@ -617,7 +613,7 @@ func TestRunner_RunEventPullRequest(t *testing.T) {
|
|||
platforms: platforms,
|
||||
}
|
||||
|
||||
tjfi.runTest(context.Background(), t, &Config{EventPath: filepath.Join(workdir, workflowPath, "event.json")})
|
||||
tjfi.runTest(t.Context(), t, &Config{EventPath: filepath.Join(workdir, workflowPath, "event.json")})
|
||||
}
|
||||
|
||||
func TestRunner_RunMatrixWithUserDefinedInclusions(t *testing.T) {
|
||||
|
@ -644,5 +640,5 @@ func TestRunner_RunMatrixWithUserDefinedInclusions(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
tjfi.runTest(context.Background(), t, &Config{Matrix: matrix})
|
||||
tjfi.runTest(t.Context(), t, &Config{Matrix: matrix})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue