Skip to content

Commit

Permalink
chore: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ericzzzzzzz committed Apr 15, 2024
1 parent ae265bf commit 16f854d
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 3 deletions.
4 changes: 1 addition & 3 deletions internal/sidecarlogartifacts/sidecarlogartifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"context"
"encoding/json"
"fmt"
"log"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -117,7 +116,7 @@ func GetArtifactsFromSidecarLogs(ctx context.Context, clientset kubernetes.Inter
func LookForArtifacts(names []string, runDir string) (SidecarArtifacts, error) {
err := waitForStepsToFinish(runDir)
if err != nil {
log.Fatal(err)
return nil, err
}
artifacts := SidecarArtifacts{}
for _, name := range names {
Expand All @@ -132,7 +131,6 @@ func LookForArtifacts(names []string, runDir string) (SidecarArtifacts, error) {
return artifacts, err
}
artifacts[name] = v1.Artifacts{Inputs: subRes.Inputs, Outputs: subRes.Outputs}

}
return artifacts, nil
}
85 changes: 85 additions & 0 deletions internal/sidecarlogartifacts/sidecarlogartifacts_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
Copyright 2024 The Tekton Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package sidecarlogartifacts

import (
"os"
"path/filepath"
"testing"
)

func TestLookForArtifacts_WaitForFiles(t *testing.T) {

tests := []struct {
desc string
wantErr bool
runDirMode os.FileMode
stepDir string
outFile string
}{
{
desc: "fail to read runDir, err",
wantErr: true,
runDirMode: 0o000,
},
{
desc: "out.err file exist, no err",
runDirMode: 0o755,
stepDir: "first",
outFile: "out.err",
},
{
desc: "out file exist, no err",
runDirMode: 0o755,
stepDir: "first",
outFile: "out.err",
},
}

for _, tc := range tests {
t.Run(tc.desc, func(t *testing.T) {
dir := t.TempDir()
_ = os.Chmod(dir, tc.runDirMode)
if tc.stepDir != "" {
_ = os.MkdirAll(filepath.Join(dir, tc.stepDir), os.ModePerm)

outFile := filepath.Join(dir, tc.stepDir, tc.outFile)
_, err := os.Create(outFile)
if err != nil {
t.Fatalf("failed to create file %v", err)
}
}
_, err := LookForArtifacts([]string{}, dir)
if (err != nil) != tc.wantErr {
t.Fatalf("error checking failed, err: %v", err)
}
})
}
}

func TestLookForArtifacts(t *testing.T) {

tests := []struct {
desc string
wantErr bool
runDirMode os.FileMode
}{{}}

for _, tc := range tests {

}
}

0 comments on commit 16f854d

Please sign in to comment.