Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/entrypoint: clean after running tests #4175

Merged
merged 1 commit into from
Aug 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions pkg/entrypoint/entrypointer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ func TestEntrypointer(t *testing.T) {
t.Run(c.desc, func(t *testing.T) {
fw, fr, fpw := &fakeWaiter{}, &fakeRunner{}, &fakePostWriter{}
timeout := time.Duration(0)
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: c.entrypoint,
WaitFiles: c.waitFiles,
Expand All @@ -175,7 +182,7 @@ func TestEntrypointer(t *testing.T) {
Waiter: fw,
Runner: fr,
PostWriter: fpw,
TerminationPath: "termination",
TerminationPath: terminationPath,
Timeout: &timeout,
BreakpointOnFailure: c.breakpointOnFailure,
StepMetadataDir: c.stepDir,
Expand Down Expand Up @@ -221,7 +228,7 @@ func TestEntrypointer(t *testing.T) {
if c.postFile == "" && fpw.wrote != nil {
t.Errorf("Wrote post file when not required")
}
fileContents, err := ioutil.ReadFile("termination")
fileContents, err := ioutil.ReadFile(terminationPath)
if err == nil {
var entries []v1alpha1.PipelineResourceResult
if err := json.Unmarshal([]byte(fileContents), &entries); err == nil {
Expand All @@ -239,7 +246,7 @@ func TestEntrypointer(t *testing.T) {
} else if !os.IsNotExist(err) {
t.Error("Wanted termination file written, got nil")
}
if err := os.Remove("termination"); err != nil {
if err := os.Remove(terminationPath); err != nil {
t.Errorf("Could not remove termination path: %s", err)
}

Expand Down Expand Up @@ -309,6 +316,13 @@ func TestEntrypointer_OnError(t *testing.T) {
}} {
t.Run(c.desc, func(t *testing.T) {
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: []string{},
Expand All @@ -317,7 +331,7 @@ func TestEntrypointer_OnError(t *testing.T) {
Waiter: &fakeWaiter{},
Runner: c.runner,
PostWriter: fpw,
TerminationPath: "termination",
TerminationPath: terminationPath,
OnError: c.onError,
}.Go()

Expand Down