Skip to content

Commit c92b450

Browse files
committed
refactor: rename test fixtures
1 parent f31b8a7 commit c92b450

File tree

111 files changed

+29
-24
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+29
-24
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ generate-schema: ## Generate schema
2020

2121
.PHONY: write-fixtures
2222
write-fixtures: ## Write new test fixtures
23-
@rm -f ./fixtures/*.out.yaml ./fixtures/*.valid.out
23+
@rm -f ./fixtures/*.out.yaml ./fixtures/*.validator.out
2424
@WRITE_FIXTURES=1 go test -count=1 .
2525

2626
.PHONY: pkg-go-dev-update

README.md

+3-3

fixtures/accounts.valid.out

Whitespace-only changes.

fixtures/cacerts.valid.out

Whitespace-only changes.

fixtures/containers.valid.out

Whitespace-only changes.

fixtures/dnf.valid.out

Whitespace-only changes.

fixtures/fips.valid.out

Whitespace-only changes.

fixtures/firewall.valid.out

Whitespace-only changes.

fixtures/fsnodes.valid.out

Whitespace-only changes.

fixtures/hostname.valid.out

Whitespace-only changes.

fixtures/ignition.valid.out

Whitespace-only changes.

fixtures/installer.valid.out

Whitespace-only changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

fixtures/installer-invalid.valid.out fixtures/invalid-installer.validator.out

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ validation failed: jsonschema validation failed with 'blueprint-schema.json'
22
- at '/installer': oneOf failed, none matched
33
- at '/installer/anaconda': oneOf failed, none matched
44
- at '/installer/anaconda': validation failed
5-
- at '/installer/anaconda/sudo_nopasswd/0': 'invalid username' does not match pattern '^[%a-zA-Z0-9_.][a-zA-Z0-9_.$-]*$'
65
- at '/installer/anaconda/enabled_modules/0': value must be one of 'org.fedoraproject.Anaconda.Modules.Localization', 'org.fedoraproject.Anaconda.Modules.Network', 'org.fedoraproject.Anaconda.Modules.Payloads', 'org.fedoraproject.Anaconda.Modules.Runtime', 'org.fedoraproject.Anaconda.Modules.Security', 'org.fedoraproject.Anaconda.Modules.Services', 'org.fedoraproject.Anaconda.Modules.Storage', 'org.fedoraproject.Anaconda.Modules.Subscription', 'org.fedoraproject.Anaconda.Modules.Timezone', 'org.fedoraproject.Anaconda.Modules.Users'
6+
- at '/installer/anaconda/sudo_nopasswd/0': 'invalid username' does not match pattern '^[%a-zA-Z0-9_.][a-zA-Z0-9_.$-]*$'
77
- at '/installer/anaconda': oneOf failed, subschemas 0, 1 matched
88
- at '/installer/anaconda': got object, want null
99
- at '/installer': got object, want null
File renamed without changes.
File renamed without changes.
File renamed without changes.

fixtures/kernel.valid.out

Whitespace-only changes.

fixtures/locale.valid.out

Whitespace-only changes.

fixtures/minimal-j.valid.out

Whitespace-only changes.

fixtures/minimal.valid.out

Whitespace-only changes.

fixtures/openscap-json-tailoring.valid.out

Whitespace-only changes.

fixtures/openscap-selected.valid.out

Whitespace-only changes.

fixtures/openscap-selection-both.valid.out

Whitespace-only changes.

fixtures/openscap-unselected.valid.out

Whitespace-only changes.

fixtures/registration-fdo-certs.valid.out

Whitespace-only changes.

fixtures/registration-fdo-hash.valid.out

Whitespace-only changes.

fixtures/registration.valid.out

Whitespace-only changes.

fixtures/storage.valid.out

Whitespace-only changes.

fixtures/systemd.valid.out

Whitespace-only changes.

fixtures/timedate.valid.out

Whitespace-only changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

validate_test.go

+24-19
Original file line numberDiff line numberDiff line change
@@ -124,28 +124,33 @@ func TestFix(t *testing.T) {
124124
t.Fatal(err)
125125
}
126126
if writeFixtures {
127-
outputFile, err := os.OpenFile(output, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
128-
if err != nil {
129-
t.Fatal(err)
130-
}
131-
defer outputFile.Close()
127+
schemaErr := schema.ValidateMap(data)
128+
if schemaErr != nil && schemaErr.Error() != "" {
129+
outFile, err := os.OpenFile(output, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
130+
if err != nil {
131+
t.Fatal(err)
132+
}
133+
defer outFile.Close()
132134

133-
err = schema.ValidateMap(data)
134-
if err != nil {
135-
outputFile.WriteString(err.Error())
135+
outFile.WriteString(schemaErr.Error())
136+
t.Logf("Written %s", output)
136137
}
137-
t.Logf("Written %s", output)
138138
} else {
139-
outputFile, err := os.Open(output)
140-
if err != nil {
141-
t.Fatal(err)
142-
}
143-
defer outputFile.Close()
144-
wantBuf, err := io.ReadAll(outputFile)
145-
if err != nil {
146-
t.Fatal(err)
139+
var want string
140+
141+
// if file output exists
142+
if _, err := os.Stat(output); err == nil {
143+
inFile, err := os.Open(output)
144+
if err != nil {
145+
t.Fatal(err)
146+
}
147+
defer inFile.Close()
148+
wantBuf, err := io.ReadAll(inFile)
149+
if err != nil {
150+
t.Fatal(err)
151+
}
152+
want = string(wantBuf)
147153
}
148-
want := string(wantBuf)
149154

150155
var got string
151156
err = schema.ValidateMap(data)
@@ -174,7 +179,7 @@ func TestFix(t *testing.T) {
174179
direction := filepath.Ext(fileWithoutFormat)
175180
baseFile := file[0 : len(fileWithoutFormat)-len(direction)]
176181
outFile := baseFile + ".out.yaml"
177-
validFile := baseFile + ".valid.out"
182+
validFile := baseFile + ".validator.out"
178183

179184
marshalTest(t, file, outFile)
180185
validationTest(t, file, validFile)

0 commit comments

Comments
 (0)