-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change printing
::set-output
to writing to $GITHUB_OUTPUT
- Loading branch information
Showing
14 changed files
with
284 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package testutil | ||
|
||
import ( | ||
"io" | ||
"os" | ||
"path" | ||
"testing" | ||
|
||
"github.com/newrelic/release-toolkit/src/app/gha" | ||
) | ||
|
||
type GithubOutputWriter struct { | ||
File *os.File | ||
} | ||
|
||
func NewGithubOutputWriter(t *testing.T) GithubOutputWriter { | ||
t.Helper() | ||
|
||
ghaOutputFileName := path.Join(t.TempDir(), "temporary_github_output_file") | ||
t.Setenv(gha.GithubOutput, ghaOutputFileName) | ||
|
||
ghaOutputFile, err := os.Create(ghaOutputFileName) | ||
if err != nil { | ||
t.Fatalf("Error creating temporary GHA output file for test: %v", err) | ||
} | ||
|
||
return GithubOutputWriter{ | ||
File: ghaOutputFile, | ||
} | ||
} | ||
|
||
func (ghaOut GithubOutputWriter) Result(t *testing.T) string { | ||
t.Helper() | ||
|
||
actual, err := io.ReadAll(ghaOut.File) | ||
if err != nil { | ||
t.Fatalf("Unable to read temporary GHA output file: %v", err) | ||
} | ||
return string(actual) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package gha_test | ||
|
||
import ( | ||
"strings" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/newrelic/release-toolkit/internal/testutil" | ||
"github.com/newrelic/release-toolkit/src/app/gha" | ||
) | ||
|
||
func TestGHA_FileIsEmptyByDefault(t *testing.T) { | ||
ghaOutput := testutil.NewGithubOutputWriter(t) | ||
if actual := ghaOutput.Result(t); actual != "" { | ||
t.Fatalf("Expected GHA output is empty") | ||
} | ||
} | ||
|
||
func TestGHA_OutputsAreAppended(t *testing.T) { | ||
buf := &strings.Builder{} | ||
buf.WriteString("not-empty=true\nanother-line=true\n") | ||
|
||
gha := gha.New(buf) | ||
|
||
gha.SetOutput("test", 1) | ||
gha.SetOutput("test", "out") | ||
|
||
expected := strings.TrimSpace(` | ||
not-empty=true | ||
another-line=true | ||
test=1 | ||
test=out | ||
`) + "\n" | ||
|
||
if actual := buf.String(); actual != expected { | ||
t.Fatalf("Expected:\n%s\n\ngot:\n%s", expected, actual) | ||
} | ||
} | ||
|
||
func TestGHA_LockWritesAndDoesNotMangleOutput(t *testing.T) { | ||
buf := &strings.Builder{} | ||
wg := sync.WaitGroup{} | ||
|
||
gha := gha.New(buf) | ||
|
||
for range 5 { | ||
wg.Add(1) | ||
go func() { | ||
gha.SetOutput("test", 1) | ||
wg.Done() | ||
}() | ||
} | ||
|
||
expected := strings.TrimSpace(` | ||
test=1 | ||
test=1 | ||
test=1 | ||
test=1 | ||
test=1 | ||
`) + "\n" | ||
|
||
wg.Wait() | ||
|
||
if actual := buf.String(); actual != expected { | ||
t.Fatalf("Expected:\n%s\n\ngot:\n%s", expected, actual) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.