createFile writes the content to a temporary file, returning the path. Good for testing config files.
(t testing.TB, content string)
| 38 | // createFile writes the content to a temporary file, returning the path. |
| 39 | // Good for testing config files. |
| 40 | func 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 | |
| 61 | func NewDefaultRegistry(ctx context.Context, flags *pflag.FlagSet, withoutNetwork bool, opts []ketoctx.Option) (Registry, error) { |
| 62 | reg, ok := ctx.Value(RegistryContextKey).(Registry) |