Repository navigation
Expand file tree
/
Copy pathgithub_actions_test.go
More file actions
95 lines (92 loc) · 3.02 KB
/
Copy pathgithub_actions_test.go
File metadata and controls
95 lines (92 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package manifests
import (
"testing"
)
func TestGitHubActionsDockerPURLs(t *testing.T) {
content := []byte(`name: fixture
on: push
jobs:
test:
runs-on: ubuntu-latest
container: ghcr.io/example/job:1
services:
database:
image: postgres:16
steps:
- uses: actions/checkout@v4
- uses: docker://ghcr.io/example/step:2
`)
result, err := Parse(".github/workflows/fixture.yml", content)
if err != nil {
t.Fatal(err)
}
if result.Ecosystem != "github-actions" || result.Kind != Manifest {
t.Fatalf("file identity = %q %q, want github-actions manifest", result.Ecosystem, result.Kind)
}
want := map[string]struct {
version, ecosystem, purl string
}{
"actions/checkout": {"v4", "github-actions", "pkg:githubactions/actions/checkout"},
"docker://ghcr.io/example/step": {"2", "docker", "pkg:docker/ghcr.io/example/step"},
"docker://ghcr.io/example/job": {"1", "docker", "pkg:docker/ghcr.io/example/job"},
"docker://postgres": {"16", "docker", "pkg:docker/postgres"},
}
if len(result.Dependencies) != len(want) {
t.Fatalf("dependencies = %+v, want %d entries", result.Dependencies, len(want))
}
for _, dep := range result.Dependencies {
expected, ok := want[dep.Name]
if !ok {
t.Errorf("unexpected dependency %+v", dep)
continue
}
if dep.Version != expected.version || dep.Ecosystem != expected.ecosystem || dep.PURL != expected.purl ||
dep.Scope != Runtime || !dep.Direct {
t.Errorf("dependency = %+v, want version %q, ecosystem %q, PURL %q, direct runtime",
dep, expected.version, expected.ecosystem, expected.purl)
}
delete(want, dep.Name)
}
if len(want) != 0 {
t.Errorf("missing dependencies: %+v", want)
}
}
func TestGitHubActionsDockerReferences(t *testing.T) {
const digest = "sha256:7b65413af120ec5328077775022c78101f103258a1876ec2f83890bce416e896"
content := []byte(`jobs:
test:
runs-on: ubuntu-latest
container:
image: registry.example:5000/team/image:stable@` + digest + `
services:
duplicate:
image: registry.example:5000/team/image:stable@` + digest + `
untagged:
image: ghcr.io/example/untagged
steps:
- uses: docker://registry.example:5000/team/image:stable@` + digest + `
- uses: docker://registry.example:5000/team/image:2
`)
result, err := Parse(".github/workflows/fixture.yaml", content)
if err != nil {
t.Fatal(err)
}
want := map[string]string{
digest: "pkg:docker/registry.example:5000/team/image",
"2": "pkg:docker/registry.example:5000/team/image",
"latest": "pkg:docker/ghcr.io/example/untagged",
}
if len(result.Dependencies) != len(want) {
t.Fatalf("dependencies = %+v, want %d entries", result.Dependencies, len(want))
}
for _, dep := range result.Dependencies {
expected, ok := want[dep.Version]
if !ok || dep.PURL != expected || dep.Ecosystem != "docker" {
t.Errorf("unexpected dependency %+v, want PURL %q and docker ecosystem", dep, expected)
}
delete(want, dep.Version)
}
if len(want) != 0 {
t.Errorf("missing versions: %+v", want)
}
}