Skip to content

Commit

Permalink
skip some tests when running with root
Browse files Browse the repository at this point in the history
  • Loading branch information
ericzzzzzzz committed Mar 18, 2024
1 parent 9071092 commit dc1ce39
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
1 change: 0 additions & 1 deletion pkg/entrypoint/entrypointer.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ func (e Entrypointer) Go() error {
}

func readArtifacts(fp string) ([]result.RunResult, error) {

file, err := os.ReadFile(fp)
if os.IsNotExist(err) {
return []result.RunResult{}, nil
Expand Down
28 changes: 21 additions & 7 deletions pkg/entrypoint/entrypointer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1090,9 +1090,12 @@ func TestReadArtifactsFileExistNoError(t *testing.T) {

func TestReadArtifactsFileExistReadError(t *testing.T) {
t.Run("readArtifact file exist", func(t *testing.T) {
if os.Getuid() == 0 {
t.Skipf("Test doesn't work when running with root")
}
dir := createTmpDir(t, "")
fp := filepath.Join(dir, "provenance.json")
err := os.WriteFile(fp, []byte{}, 0100)
err := os.WriteFile(fp, []byte{}, 0000)
if err != nil {
t.Fatalf("Did not expect and error but got: %v", err)
}
Expand Down Expand Up @@ -1156,12 +1159,15 @@ func TestLoadStepArtifacts(t *testing.T) {
{
desc: "read artifact, file cannot be read, error",
fileContent: `{"inputs":[{"name":"inputs","values":[{"digest":{"sha256":"cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30"},"uri":"pkg:example.github.com/inputs"}]}],"outputs":[{"name":"output","values":[{"digest":{"sha256":"64d0b157fdf2d7f6548836dd82085fd8401c9481a9f59e554f1b337f134074b0"},"uri":"docker:example.registry.com/outputs"}]}]}`,
mode: 0100,
mode: 0000,
wantErr: true,
},
}
for _, tc := range tests {
t.Run(tc.desc, func(t *testing.T) {
if tc.mode == 0000 && os.Getuid() == 0 {
t.Skipf("Test doesn't work when running with root")
}
dir := createTmpDir(t, "")
name := "step-name"
artifactsPath := getStepArtifactsPath(dir, name)
Expand Down Expand Up @@ -1361,7 +1367,7 @@ func TestGetArtifactValues(t *testing.T) {
{
desc: "fail to load artifacts",
fileContent: `{"inputs":[{"name":"inputs","values":[{"digest":{"sha256":"cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30"},"uri":"pkg:example.github.com/inputs"}]}],"outputs":[{"name":"output","values":[{"digest":{"sha256":"64d0b157fdf2d7f6548836dd82085fd8401c9481a9f59e554f1b337f134074b0"},"uri":"docker:example.registry.com/outputs"}]},{"name":"output2","values":[{"digest":{"sha256":"22222157fdf2d7f6548836dd82085fd8401c9481a9f59e554f1b337f13402222"},"uri":"docker2:example.registry.com/outputs"}]}]}`,
mode: 0100,
mode: 0000,
template: fmt.Sprintf("$(steps.%s.outputs.output2.333)", name),
wantErr: true,
},
Expand All @@ -1376,6 +1382,9 @@ func TestGetArtifactValues(t *testing.T) {

for _, tc := range tests {
t.Run(tc.desc, func(t *testing.T) {
if tc.mode == 0000 && os.Getuid() == 0 {
t.Skipf("Test doesn't work when running with root")
}
dir := createTmpDir(t, "")
artifactsPath := getStepArtifactsPath(dir, "step-"+name)
if tc.fileContent != "" {
Expand Down Expand Up @@ -1427,7 +1436,7 @@ func TestApplyStepArtifactSubstitutionsCommand(t *testing.T) {
desc: "apply substitution script, fail to read artifacts",
fileContent: `{"inputs":[{"name":"inputs","values":[{"digest":{"sha256":"cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30"},"uri":"pkg:example.github.com/inputs"}]}],"outputs":[{"name":"output","values":[{"digest":{"sha256":"64d0b157fdf2d7f6548836dd82085fd8401c9481a9f59e554f1b337f134074b0"},"uri":"docker:example.registry.com/outputs"}]}]}`,
want: []string{filepath.Join(scriptDir, "foo2.sh")},
mode: 0100,
mode: 0000,
wantErr: true,
scriptContent: fmt.Sprintf("echo $(steps.%s.outputs)", stepName),
scriptFile: filepath.Join(scriptDir, "foo2.sh"),
Expand All @@ -1453,14 +1462,17 @@ func TestApplyStepArtifactSubstitutionsCommand(t *testing.T) {
desc: "apply substitution to inline command, fail to read, command no change",
fileContent: `{"inputs":[{"name":"inputs","values":[{"digest":{"sha256":"cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30"},"uri":"pkg:example.github.com/inputs"}]}],"outputs":[{"name":"output","values":[{"digest":{"sha256":"64d0b157fdf2d7f6548836dd82085fd8401c9481a9f59e554f1b337f134074b0"},"uri":"docker:example.registry.com/outputs"}]}]}`,
want: []string{"echo", fmt.Sprintf("$(steps.%s.outputs)", stepName), "|", "jq", "."},
mode: 0100,
mode: 0000,
wantErr: true,
command: []string{"echo", fmt.Sprintf("$(steps.%s.outputs)", stepName), "|", "jq", "."},
},
}

for _, tc := range tests {
t.Run(tc.desc, func(t *testing.T) {
if tc.mode == 0000 && os.Getuid() == 0 {
t.Skipf("Test doesn't work when running with root")
}
stepDir := createTmpDir(t, "")
artifactsPath := getStepArtifactsPath(stepDir, "step-"+stepName)
if tc.fileContent != "" {
Expand Down Expand Up @@ -1494,7 +1506,6 @@ func TestApplyStepArtifactSubstitutionsCommand(t *testing.T) {
}

func TestApplyStepArtifactSubstitutionsEnv(t *testing.T) {

stepName := "name"
scriptDir := createTmpDir(t, "script")
tests := []struct {
Expand Down Expand Up @@ -1525,7 +1536,7 @@ func TestApplyStepArtifactSubstitutionsEnv(t *testing.T) {
{
desc: "apply substitution to env, matches found, read artifacts failed.",
fileContent: `{"inputs":[{"name":"inputs","values":[{"digest":{"sha256":"cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30"},"uri":"pkg:example.github.com/inputs"}]}],"outputs":[{"name":"output","values":[{"digest":{"sha256":"64d0b157fdf2d7f6548836dd82085fd8401c9481a9f59e554f1b337f134074b0"},"uri":"docker:example.registry.com/outputs"}]}]}`,
mode: 0100,
mode: 0000,
envKey: "aaa",
envValue: fmt.Sprintf("abc-$(steps.%s.outputs)", stepName),
want: fmt.Sprintf("abc-$(steps.%s.outputs)", stepName),
Expand All @@ -1535,6 +1546,9 @@ func TestApplyStepArtifactSubstitutionsEnv(t *testing.T) {

for _, tc := range tests {
t.Run(tc.desc, func(t *testing.T) {
if tc.mode == 0000 && os.Getuid() == 0 {
t.Skipf("Test doesn't work when running with root")
}
stepDir := createTmpDir(t, "")
artifactsPath := getStepArtifactsPath(stepDir, "step-"+stepName)
if tc.fileContent != "" {
Expand Down

0 comments on commit dc1ce39

Please sign in to comment.