This commit is contained in:
Urko 2023-03-05 00:07:48 +01:00
parent 0bf7b63286
commit b049c6a779
2 changed files with 23 additions and 8 deletions

View File

@ -44,8 +44,14 @@ func TestNewWriter(t *testing.T) {
} }
func Test_writer_WriteFile(t *testing.T) { func Test_writer_WriteFile(t *testing.T) {
deleteAllDirs() err := deleteAllDirs()
defer deleteAllDirs() require.NoError(t, err)
defer func(t *testing.T) {
err := deleteAllDirs()
require.NoError(t, err)
}(t)
w := newWriter(testWriterPath) w := newWriter(testWriterPath)
wgot, err := w.WriteFile(testFileName, []byte(testFileContent)) wgot, err := w.WriteFile(testFileName, []byte(testFileContent))
require.NoError(t, err) require.NoError(t, err)
@ -57,18 +63,25 @@ func Test_writer_WriteFile(t *testing.T) {
} }
func Test_writer_WriteFileError(t *testing.T) { func Test_writer_WriteFileError(t *testing.T) {
deleteAllDirs() err := deleteAllDirs()
defer deleteAllDirs() require.NoError(t, err)
defer func(t *testing.T) {
err := deleteAllDirs()
require.NoError(t, err)
}(t)
w := newWriter("") w := newWriter("")
_, err := w.WriteFile(testFileName, []byte(testFileContent)) _, err = w.WriteFile(testFileName, []byte(testFileContent))
assert.Error(t, err) assert.Error(t, err)
w = newWriter(testWriterPath) w = newWriter(testWriterPath)
_, err = w.WriteFile("", []byte(testFileContent)) _, err = w.WriteFile("", []byte(testFileContent))
require.Error(t, err) require.Error(t, err)
go func() { go func(t *testing.T) {
deleteAllDirs() err := deleteAllDirs()
require.NoError(t, err)
for { for {
f, err := os.Stat(testWriterPath) f, err := os.Stat(testWriterPath)
if err != nil { if err != nil {
@ -83,7 +96,7 @@ func Test_writer_WriteFileError(t *testing.T) {
require.NoError(t, err, "should not throw error because dir exists") require.NoError(t, err, "should not throw error because dir exists")
return return
} }
}() }(t)
_, err = w.WriteFile(testFileName, nil) _, err = w.WriteFile(testFileName, nil)
assert.Error(t, err) assert.Error(t, err)

View File

@ -29,8 +29,10 @@ type Subject struct {
PostalCode string PostalCode string
} }
/*
var ( var (
subjectKeyId = []byte{1, 2, 3, 4, 6} subjectKeyId = []byte{1, 2, 3, 4, 6}
extKeyUsage = []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth, x509.ExtKeyUsageServerAuth} extKeyUsage = []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth, x509.ExtKeyUsageServerAuth}
keyUsage = x509.KeyUsageDigitalSignature keyUsage = x509.KeyUsageDigitalSignature
) )
*/