Skip to content

Commit 335447c

Browse files
committed
test(pki): centralize test fixtures
1 parent b9d2276 commit 335447c

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

pkg/pki/ca_test.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,22 @@ import (
1414
"time"
1515
)
1616

17+
const (
18+
testCAName = "test-ca"
19+
testCADefault = "test-ca-default"
20+
21+
testDeviceCN = "test-device"
22+
testDeviceOrg = "test-org"
23+
testDeviceURI = "spiffe://example.com/device/123"
24+
testDeviceDNS = "device.example.com"
25+
testDeviceTTLH = time.Hour
26+
)
27+
1728
func TestLoadOrCreateCA(t *testing.T) {
1829
tmpDir := t.TempDir()
1930
certPath := filepath.Join(tmpDir, "ca.pem")
2031
keyPath := filepath.Join(tmpDir, "ca-key.pem")
2132

22-
const (
23-
testCAName = "test-ca"
24-
testCADefault = "test-ca-default"
25-
)
26-
2733
t.Run("creates new CA when files don't exist", func(t *testing.T) {
2834
ca, err := LoadOrCreateCA(certPath, keyPath, testCAName, time.Hour*24*365)
2935
if err != nil {
@@ -158,14 +164,6 @@ func TestCertificateAuthority_IssueCertificate(t *testing.T) {
158164
certPath := filepath.Join(tmpDir, "ca.pem")
159165
keyPath := filepath.Join(tmpDir, "ca-key.pem")
160166

161-
const (
162-
testDeviceCN = "test-device"
163-
testDeviceOrg = "test-org"
164-
testDeviceURI = "spiffe://example.com/device/123"
165-
testDeviceDNS = "device.example.com"
166-
testDeviceTTLH = time.Hour
167-
)
168-
169167
ca, err := LoadOrCreateCA(certPath, keyPath, testCAName, 24*time.Hour)
170168
if err != nil {
171169
t.Fatalf("Failed to create CA: %v", err)

0 commit comments

Comments
 (0)