feat: writer test full coverage
This commit is contained in:
@@ -2,6 +2,7 @@ package io
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"gitlab.com/urkob/go-cert-gen/pkg/io"
|
||||
@@ -17,18 +18,19 @@ func (w writer) WriteFile(filename string, data []byte) (string, error) {
|
||||
if filename == "" {
|
||||
return "", fmt.Errorf("filename cannot be empty")
|
||||
}
|
||||
|
||||
if w.dirPath == "" {
|
||||
return "", fmt.Errorf("export directory cannot be empty")
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(w.dirPath, 0o755); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
log.Println("to write file")
|
||||
outputPath := w.dirPath + "/" + filename
|
||||
if err := os.WriteFile(outputPath, data, 0o600); err != nil {
|
||||
return "", err
|
||||
}
|
||||
log.Println("file written")
|
||||
return outputPath, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user