MCPcopy
hub / github.com/ory/keto / createFile

Function createFile

internal/driver/registry_factory.go:40–59  ·  view source on GitHub ↗

createFile writes the content to a temporary file, returning the path. Good for testing config files.

(t testing.TB, content string)

Source from the content-addressed store, hash-verified

38// createFile writes the content to a temporary file, returning the path.
39// Good for testing config files.
40func createFile(t testing.TB, content string) (path string) {
41 t.Helper()
42
43 f, err := os.CreateTemp(t.TempDir(), "config-*.yaml")
44 if err != nil {
45 t.Fatal(err)
46 }
47
48 t.Cleanup(func() { _ = os.Remove(f.Name()) })
49
50 n, err := f.WriteString(content)
51 if err != nil {
52 t.Fatal(err)
53 }
54 if n != len(content) {
55 t.Fatal("failed to write the complete content")
56 }
57
58 return f.Name()
59}
60
61func NewDefaultRegistry(ctx context.Context, flags *pflag.FlagSet, withoutNetwork bool, opts []ketoctx.Option) (Registry, error) {
62 reg, ok := ctx.Value(RegistryContextKey).(Registry)

Callers 2

WithOPLFunction · 0.70
TestCreateCmdFunction · 0.50

Calls 1

NameMethod · 0.45

Tested by 1

TestCreateCmdFunction · 0.40