c8cc7b2448
Establishes a simple framework for supporting workflow commands. Fully implements `::add-mask::`, `::debug::`, and `::stop-commands::`. Addresses #148 Co-authored-by: Jason Song <i@wolfogre.com> Reviewed-on: https://gitea.com/gitea/act_runner/pulls/149 Reviewed-by: Jason Song <i@wolfogre.com> Co-authored-by: Søren L. Hansen <sorenisanerd@gmail.com> Co-committed-by: Søren L. Hansen <sorenisanerd@gmail.com>
148 lines
2.9 KiB
Go
148 lines
2.9 KiB
Go
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package report
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
"gotest.tools/v3/assert"
|
|
)
|
|
|
|
func TestReporter_parseLogRow(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
debugOutputEnabled bool
|
|
args []string
|
|
want []string
|
|
}{
|
|
{
|
|
"No command", false,
|
|
[]string{"Hello, world!"},
|
|
[]string{"Hello, world!"},
|
|
},
|
|
{
|
|
"Add-mask", false,
|
|
[]string{
|
|
"foo mysecret bar",
|
|
"::add-mask::mysecret",
|
|
"foo mysecret bar",
|
|
},
|
|
[]string{
|
|
"foo mysecret bar",
|
|
"<nil>",
|
|
"foo *** bar",
|
|
},
|
|
},
|
|
{
|
|
"Debug enabled", true,
|
|
[]string{
|
|
"::debug::GitHub Actions runtime token access controls",
|
|
},
|
|
[]string{
|
|
"GitHub Actions runtime token access controls",
|
|
},
|
|
},
|
|
{
|
|
"Debug not enabled", false,
|
|
[]string{
|
|
"::debug::GitHub Actions runtime token access controls",
|
|
},
|
|
[]string{
|
|
"<nil>",
|
|
},
|
|
},
|
|
{
|
|
"notice", false,
|
|
[]string{
|
|
"::notice file=file.name,line=42,endLine=48,title=Cool Title::Gosh, that's not going to work",
|
|
},
|
|
[]string{
|
|
"::notice file=file.name,line=42,endLine=48,title=Cool Title::Gosh, that's not going to work",
|
|
},
|
|
},
|
|
{
|
|
"warning", false,
|
|
[]string{
|
|
"::warning file=file.name,line=42,endLine=48,title=Cool Title::Gosh, that's not going to work",
|
|
},
|
|
[]string{
|
|
"::warning file=file.name,line=42,endLine=48,title=Cool Title::Gosh, that's not going to work",
|
|
},
|
|
},
|
|
{
|
|
"error", false,
|
|
[]string{
|
|
"::error file=file.name,line=42,endLine=48,title=Cool Title::Gosh, that's not going to work",
|
|
},
|
|
[]string{
|
|
"::error file=file.name,line=42,endLine=48,title=Cool Title::Gosh, that's not going to work",
|
|
},
|
|
},
|
|
{
|
|
"group", false,
|
|
[]string{
|
|
"::group::",
|
|
"::endgroup::",
|
|
},
|
|
[]string{
|
|
"::group::",
|
|
"::endgroup::",
|
|
},
|
|
},
|
|
{
|
|
"stop-commands", false,
|
|
[]string{
|
|
"::add-mask::foo",
|
|
"::stop-commands::myverycoolstoptoken",
|
|
"::add-mask::bar",
|
|
"::debug::Stuff",
|
|
"myverycoolstoptoken",
|
|
"::add-mask::baz",
|
|
"::myverycoolstoptoken::",
|
|
"::add-mask::wibble",
|
|
"foo bar baz wibble",
|
|
},
|
|
[]string{
|
|
"<nil>",
|
|
"<nil>",
|
|
"::add-mask::bar",
|
|
"::debug::Stuff",
|
|
"myverycoolstoptoken",
|
|
"::add-mask::baz",
|
|
"<nil>",
|
|
"<nil>",
|
|
"*** bar baz ***",
|
|
},
|
|
},
|
|
{
|
|
"unknown command", false,
|
|
[]string{
|
|
"::set-mask::foo",
|
|
},
|
|
[]string{
|
|
"::set-mask::foo",
|
|
},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
r := &Reporter{
|
|
logReplacer: strings.NewReplacer(),
|
|
debugOutputEnabled: tt.debugOutputEnabled,
|
|
}
|
|
for idx, arg := range tt.args {
|
|
rv := r.parseLogRow(&log.Entry{Message: arg})
|
|
got := "<nil>"
|
|
|
|
if rv != nil {
|
|
got = rv.Content
|
|
}
|
|
|
|
assert.Equal(t, tt.want[idx], got)
|
|
}
|
|
})
|
|
}
|
|
}
|