mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-07-03 01:18:55 +00:00
Reviewed-on: https://gitea.com/gitea/runner/pulls/1055 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: bircni <bircni@icloud.com>
64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package model
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestReadActionDefaultsAndCaseInsensitiveUsing(t *testing.T) {
|
|
action, err := ReadAction(strings.NewReader(`
|
|
name: example
|
|
runs:
|
|
using: NoDe24
|
|
main: dist/index.js
|
|
`))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if action.Runs.Using != ActionRunsUsingNode24 {
|
|
t.Fatalf("using = %q, want %q", action.Runs.Using, ActionRunsUsingNode24)
|
|
}
|
|
if action.Runs.PreIf != "always()" {
|
|
t.Fatalf("pre-if = %q, want always()", action.Runs.PreIf)
|
|
}
|
|
if action.Runs.PostIf != "always()" {
|
|
t.Fatalf("post-if = %q, want always()", action.Runs.PostIf)
|
|
}
|
|
}
|
|
|
|
func TestReadActionPreservesExplicitConditions(t *testing.T) {
|
|
action, err := ReadAction(strings.NewReader(`
|
|
runs:
|
|
using: composite
|
|
pre-if: success()
|
|
post-if: failure()
|
|
steps:
|
|
- run: echo hello
|
|
`))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if action.Runs.PreIf != "success()" || action.Runs.PostIf != "failure()" {
|
|
t.Fatalf("conditions = %q/%q, want explicit values", action.Runs.PreIf, action.Runs.PostIf)
|
|
}
|
|
if !action.Runs.Using.IsComposite() || action.Runs.Using.IsDocker() || action.Runs.Using.IsNode() {
|
|
t.Fatalf("unexpected using predicates for %q", action.Runs.Using)
|
|
}
|
|
}
|
|
|
|
func TestReadActionRejectsUnknownUsing(t *testing.T) {
|
|
_, err := ReadAction(strings.NewReader(`
|
|
runs:
|
|
using: node99
|
|
`))
|
|
if err == nil {
|
|
t.Fatal("expected unknown runs.using to fail")
|
|
}
|
|
if !strings.Contains(err.Error(), "node99") {
|
|
t.Fatalf("error = %q, want invalid value", err)
|
|
}
|
|
}
|