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

Use 8-core runners for tests and updating third-party rules #633

Merged
merged 2 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/go-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ permissions:

jobs:
test:
runs-on: ubuntu-latest
runs-on: mal-ubuntu-latest-8-core

steps:
- uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/third-party.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ permissions:
jobs:
update:
if: ${{ github.repository }} == 'chainguard-dev/malcontent'
runs-on: ubuntu-latest
runs-on: mal-ubuntu-latest-8-core
permissions:
contents: write
id-token: write
Expand Down
3 changes: 2 additions & 1 deletion pkg/action/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func TestExtractionMethod(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got := extractionMethod(tt.ext)
if (got == nil) != (tt.want == nil) {
t.Errorf("extractionMethod() for extension %v did not return expected result", tt.ext)
Expand All @@ -48,7 +49,6 @@ func TestExtractionMethod(t *testing.T) {
}

func TestExtractionMultiple(t *testing.T) {
t.Parallel()
tests := []struct {
path string
want []string
Expand Down Expand Up @@ -317,6 +317,7 @@ func TestGetExt(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.path, func(t *testing.T) {
t.Parallel()
if got := getExt(tt.path); got != tt.want {
t.Errorf("Ext() = %v, want %v", got, tt.want)
}
Expand Down
83 changes: 43 additions & 40 deletions pkg/action/scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,6 @@ import (
)

func TestCleanPath(t *testing.T) {
// create a temporary directory
tempDir, err := os.MkdirTemp("", "TestCleanPath")
if err != nil {
t.Fatalf("failed to create temp directory: %v", err)
}
defer os.RemoveAll(tempDir)

// create and symlink a nested directory
// create a file within the nested directory
nestedDir := filepath.Join(tempDir, "nested")
if err := os.Mkdir(nestedDir, 0o755); err != nil {
t.Fatalf("failed to create nested directory: %v", err)
}
symlinkPath := filepath.Join(tempDir, "symlink")
if err := os.Symlink(nestedDir, symlinkPath); err != nil {
t.Fatalf("failed to create symlink: %v", err)
}

filePath := filepath.Join(nestedDir, "test.txt")
file, err := os.Create(filePath)
if err != nil {
t.Fatalf("failed to create file: %v", err)
}
defer file.Close()

tests := []struct {
name string
path string
Expand All @@ -42,33 +17,33 @@ func TestCleanPath(t *testing.T) {
}{
{
name: "expected behavior",
path: filepath.Join(nestedDir, "test.txt"),
prefix: nestedDir,
path: "nested/test.txt",
prefix: "nested",
want: "/test.txt",
},
{
name: "symlink in path",
path: filepath.Join(symlinkPath, "test.txt"),
prefix: nestedDir,
path: "symlink/test.txt",
prefix: "nested",
want: "/test.txt",
},
{
name: "symlink in prefix",
path: filepath.Join(nestedDir, "test.txt"),
prefix: symlinkPath,
path: "nested/test.txt",
prefix: "symlink",
want: "/test.txt",
},
{
name: "non-existent path",
path: filepath.Join(tempDir, "does_not_exist", "test.txt"),
prefix: tempDir,
path: "does_not_exist/test.txt",
prefix: "temp",
wantErr: true,
},
{
name: "path prefix mismatch",
path: filepath.Join(nestedDir, "test.txt"),
path: "nested/test.txt",
prefix: "",
want: filepath.Join(nestedDir, "test.txt"),
want: "nested/test.txt",
},
{
name: "empty paths",
Expand All @@ -78,20 +53,47 @@ func TestCleanPath(t *testing.T) {
},
{
name: "identical path and prefix",
path: nestedDir,
prefix: nestedDir,
path: "nested",
prefix: "nested",
want: "",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := cleanPath(tt.path, tt.prefix)
t.Parallel()

tempDir, err := os.MkdirTemp("", "TestCleanPath")
if err != nil {
t.Fatalf("failed to create temp directory: %v", err)
}
defer os.RemoveAll(tempDir)

nestedDir := filepath.Join(tempDir, "nested")
if err := os.Mkdir(nestedDir, 0o755); err != nil {
t.Fatalf("failed to create nested directory: %v", err)
}

symlinkPath := filepath.Join(tempDir, "symlink")
if err := os.Symlink(nestedDir, symlinkPath); err != nil {
t.Fatalf("failed to create symlink: %v", err)
}

filePath := filepath.Join(nestedDir, "test.txt")
file, err := os.Create(filePath)
if err != nil {
t.Fatalf("failed to create file: %v", err)
}
file.Close()

fullPath := filepath.Join(tempDir, tt.path)
fullPrefix := filepath.Join(tempDir, tt.prefix)

got, err := cleanPath(fullPath, fullPrefix)
if (err != nil) != tt.wantErr {
t.Errorf("cleanPath() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !strings.HasSuffix(got, tt.want) {
if !tt.wantErr && !strings.HasSuffix(got, tt.want) {
t.Errorf("cleanPath() = %v, want suffix %v", got, tt.want)
}
})
Expand Down Expand Up @@ -122,6 +124,7 @@ func TestFormatPath(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := formatPath(tt.path); got != tt.want {
t.Errorf("FormatPath() = %v, want %v", got, tt.want)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/profile/profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
)

func TestProfile(t *testing.T) {
t.Parallel()
stop, err := Profile()
if err != nil {
t.Fatalf("failed to start profiling: %v", err)
Expand Down
1 change: 1 addition & 0 deletions pkg/programkind/programkind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func TestFile(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.in, func(t *testing.T) {
t.Parallel()
got, err := File(filepath.Join("testdata/", tt.in))
if err != nil {
t.Errorf("File(%s) returned error: %v", tt.in, err)
Expand Down
2 changes: 2 additions & 0 deletions pkg/report/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestLongestUnique(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := longestUnique(tt.raw); !reflect.DeepEqual(got, tt.want) {
t.Errorf("longestUnique() = %v, want %v", got, tt.want)
}
Expand Down Expand Up @@ -82,6 +83,7 @@ func TestUpgradeRisk(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := upgradeRisk(context.Background(), tt.currentScore, tt.riskCounts, tt.size); got != tt.want {
t.Errorf("upgradeRisk(%d, %v, %v) = %v, want %v", tt.currentScore, tt.riskCounts, tt.size, got, tt.want)
}
Expand Down