-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconformance_suite.ex
More file actions
140 lines (118 loc) · 3.42 KB
/
conformance_suite.ex
File metadata and controls
140 lines (118 loc) · 3.42 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# credo:disable-for-this-file
defmodule ConformanceSuite do
@moduledoc """
A module for running the OCI Distribution Specification conformance tests.
"""
require Logger
def clone_repo(repo, branch, opts \\ []) do
path = conformance_dir()
force = Keyword.get(opts, :force, false)
if force || !File.exists?(path) do
File.rm_rf!(path)
Logger.info("🔄 Cloning distribution-spec repo to #{path}")
{output, status} =
System.cmd("git", [
"clone",
"--depth",
"1",
"--branch",
branch,
repo,
path
])
case status do
0 ->
:ok
err ->
Logger.error("🚨 Error cloning distribution-spec repo: #{inspect(err)}")
Logger.error("🚨 Output: #{output}")
{:error, inspect(err)}
end
else
:ok
end
end
def build(opts \\ []) do
force = Keyword.get(opts, :force, false)
path = conformance_bin_path()
if force or !File.exists?(path) do
Logger.info("🚢 Building conformance test binary to #{path}")
dir = Path.dirname(path)
{output, status} = System.cmd("go", ["test", "-c"], cd: dir, stderr_to_stdout: true)
case status do
0 ->
:ok
err ->
Logger.error("🚨 Error building conformance test binary: #{inspect(err)}")
Logger.error("🚨 Output: #{output}")
{:error, inspect(err)}
end
else
:ok
end
end
def generate_report() do
env = [
{"OCI_ROOT_URL", "http://localhost:4002"},
{"OCI_NAMESPACE", "myorg/myrepo"},
{"OCI_CROSSMOUNT_NAMESPACE", "myorg/other"},
{"OCI_USERNAME", "myuser"},
{"OCI_PASSWORD", "mypass"},
{"OCI_TEST_PULL", "1"},
{"OCI_TEST_PUSH", "1"},
{"OCI_TEST_CONTENT_DISCOVERY", "1"},
{"OCI_TEST_CONTENT_MANAGEMENT", "0"},
{"OCI_AUTOMATIC_CROSSMOUNT", "0"},
{"OCI_DELETE_MANIFEST_BEFORE_BLOBS", "0"},
{"OCI_HIDE_SKIPPED_WORKFLOWS", "0"},
{"OCI_DEBUG", "0"},
{"OCI_REPORT_DIR", conformance_report_dir()}
]
Logger.info("🧪 Generating conformance JSON report to #{conformance_json_report_path()}")
Logger.info("🧪 Generating conformance HTML report to #{conformance_html_report_path()}")
System.cmd(
conformance_bin_path(),
[
"--ginkgo.json-report",
conformance_json_report_path()
],
env: env,
stderr_to_stdout: true
)
end
def failures() do
conformance_json_report_path()
|> File.read!()
|> Jason.decode!()
|> List.first()
|> Map.get("SpecReports")
|> Enum.filter(fn test -> test["State"] == "failed" end)
|> Enum.sort_by(fn test ->
file_path = test["Failure"]["Location"]["FileName"]
line_no = test["Failure"]["Location"]["LineNumber"]
{file_path, line_no}
end)
end
def reports() do
conformance_json_report_path()
|> File.read!()
|> Jason.decode!()
|> List.first()
|> Map.get("SpecReports")
end
def conformance_dir() do
".tmp/oci-conformance"
end
def conformance_report_dir() do
"#{conformance_dir()}/reports"
end
def conformance_html_report_path() do
"#{conformance_report_dir()}/report.html"
end
def conformance_json_report_path() do
"#{conformance_report_dir()}/report.json"
end
def conformance_bin_path() do
Path.expand("#{conformance_dir()}/conformance/conformance.test")
end
end