(t *testing.T)
| 107 | ) |
| 108 | |
| 109 | func TestCompositeHooks_WithShellExecutor(t *testing.T) { |
| 110 | ctx := base.NewMigrationContext() |
| 111 | ctx.DatabaseName = "test" |
| 112 | ctx.OriginalTableName = "tablename" |
| 113 | |
| 114 | hooksDir, err := os.MkdirTemp("", "TestCompositeHooks_WithShellExecutor") |
| 115 | require.NoError(t, err) |
| 116 | defer os.RemoveAll(hooksDir) |
| 117 | ctx.HooksPath = hooksDir |
| 118 | |
| 119 | sideEffect := filepath.Join(hooksDir, "ran.marker") |
| 120 | script := fmt.Sprintf("#!/bin/sh\ntouch %q\n", sideEffect) |
| 121 | require.NoError(t, os.WriteFile(filepath.Join(hooksDir, "gh-ost-on-startup"), []byte(script), 0o777)) |
| 122 | |
| 123 | shellExec := NewHooksExecutor(ctx) |
| 124 | shellExec.writer = new(bytes.Buffer) // suppress stderr noise |
| 125 | |
| 126 | var calls []string |
| 127 | goFake := &recordingHooks{name: "go", calls: &calls} |
| 128 | |
| 129 | composite := CompositeHooks{shellExec, goFake} |
| 130 | require.NoError(t, composite.OnStartup()) |
| 131 | |
| 132 | _, err = os.Stat(sideEffect) |
| 133 | require.NoError(t, err, "shell hook should have created marker file") |
| 134 | require.Equal(t, []string{"go:OnStartup"}, calls, "Go fake should have been invoked once") |
| 135 | } |
| 136 | |
| 137 | func TestNewMigrator_HooksFromContext(t *testing.T) { |
| 138 | t.Run("default-is-script-executor", func(t *testing.T) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…