Skip to content

Commit

Permalink
Small entrypoint unit test fixes prior to 0.27 release
Browse files Browse the repository at this point in the history
post_writer_test.go previously used os.ReadFile which was only introduced in Go
1.16. This commit replaces os.ReadFile with ioutil.ReadFile for compatibility
with older Go versions.

entrypointer_test.go previously wrote a termination file to the developer's git
repo which meant it showed up running `git status`.  This commit creates a
random TempFile for termination paths which are then cleaned up at the end of
the test.
  • Loading branch information
Scott authored and tekton-robot committed Aug 12, 2021
1 parent edcaa97 commit 42a632f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cmd/entrypoint/post_writer_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"io/ioutil"
"os"
"testing"
)
Expand All @@ -27,7 +28,7 @@ func TestRealPostWriter_WriteFileContent(t *testing.T) {
if _, err := os.Stat(tt.file); err != nil {
t.Fatalf("Failed to create a file %q", tt.file)
}
b, err := os.ReadFile(tt.file)
b, err := ioutil.ReadFile(tt.file)
if err != nil {
t.Fatalf("Failed to read the file %q", tt.file)
}
Expand Down
9 changes: 8 additions & 1 deletion pkg/entrypoint/entrypointer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ func TestEntrypointerFailures(t *testing.T) {
fr = &fakeRunner{}
}
fpw := &fakePostWriter{}
terminationPath := "termination"
if terminationFile, err := ioutil.TempFile("", "termination"); err != nil {
t.Fatalf("unexpected error creating temporary termination file: %v", err)
} else {
terminationPath = terminationFile.Name()
defer os.Remove(terminationFile.Name())
}
err := Entrypointer{
Entrypoint: "echo",
WaitFiles: c.waitFiles,
Expand All @@ -94,7 +101,7 @@ func TestEntrypointerFailures(t *testing.T) {
Waiter: fw,
Runner: fr,
PostWriter: fpw,
TerminationPath: "termination",
TerminationPath: terminationPath,
Timeout: &c.timeout,
}.Go()
if err == nil {
Expand Down

0 comments on commit 42a632f

Please sign in to comment.