MCPcopy
hub / github.com/github/gh-ost / TestCompositeHooks_WithShellExecutor

Function TestCompositeHooks_WithShellExecutor

go/logic/hooks_test.go:109–135  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

107)
108
109func 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
137func TestNewMigrator_HooksFromContext(t *testing.T) {
138 t.Run("default-is-script-executor", func(t *testing.T) {

Callers

nothing calls this directly

Calls 3

OnStartupMethod · 0.95
NewMigrationContextFunction · 0.92
NewHooksExecutorFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…