MCPcopy Create free account
hub / github.com/conforma/cli / ReadFile

Function ReadFile

internal/validate/helpers.go:74–87  ·  view source on GitHub ↗

Read file from the workspace and return its contents.

(ctx context.Context, fileName string)

Source from the content-addressed store, hash-verified

72
73// Read file from the workspace and return its contents.
74func ReadFile(ctx context.Context, fileName string) (string, error) {
75 fs := utils.FS(ctx)
76 fileBytes, err := afero.ReadFile(fs, fileName)
77 if err != nil {
78 return "", err
79 }
80 // Check for empty file as that would cause a false "success"
81 if len(fileBytes) == 0 {
82 err := fmt.Errorf("file %s is empty", fileName)
83 return "", err
84 }
85 log.Debugf("Loaded %s", fileName)
86 return string(fileBytes), nil
87}

Callers 2

GetPolicyConfigFunction · 0.85
TestReadFileFunction · 0.85

Calls 2

FSFunction · 0.92
ErrorfMethod · 0.65

Tested by 1

TestReadFileFunction · 0.68