MCPcopy Create free account
hub / github.com/flant/shell-operator / Run

Method Run

test/hook/context/generator.go:94–137  ·  view source on GitHub ↗

Run generates binding contexts for hook tests

(initialState string)

Source from the content-addressed store, hash-verified

92
93// Run generates binding contexts for hook tests
94func (b *BindingContextController) Run(initialState string) (GeneratedBindingContexts, error) {
95 b.mu.Lock()
96 defer b.mu.Unlock()
97 if b.started.Load() {
98 return GeneratedBindingContexts{}, fmt.Errorf("attempt to start an already started runner, it cannot be started twice")
99 }
100
101 err := b.Controller.SetInitialState(initialState)
102 if err != nil {
103 return GeneratedBindingContexts{}, err
104 }
105
106 if b.Hook == nil {
107 testHook := hook.NewHook("test", "test", false, false, "", b.logger.Named("hook"))
108 testHook, err = testHook.LoadConfig([]byte(b.HookConfig))
109 if err != nil {
110 return GeneratedBindingContexts{}, fmt.Errorf("couldn't load or validate hook configuration: %v", err)
111 }
112 b.Hook = testHook
113 }
114
115 b.HookCtrl = controller.NewHookController()
116 b.HookCtrl.InitKubernetesBindings(b.Hook.GetConfig().OnKubernetesEvents, b.KubeEventsManager, b.logger.Named("kubernetes-bindings"))
117 b.HookCtrl.InitScheduleBindings(b.Hook.GetConfig().Schedules, b.ScheduleManager)
118 b.HookCtrl.EnableScheduleBindings()
119
120 b.Hook.WithHookController(b.HookCtrl)
121
122 cc := NewContextCombiner()
123 err = b.HookCtrl.HandleEnableKubernetesBindings(context.Background(), func(info controller.BindingExecutionInfo) {
124 if info.KubernetesBinding.ExecuteHookOnSynchronization {
125 cc.AddBindingContext(types.OnKubernetesEvent, info)
126 }
127 })
128 if err != nil {
129 return GeneratedBindingContexts{}, fmt.Errorf("couldn't enable kubernetes bindings: %v", err)
130 }
131
132 b.HookCtrl.UnlockKubernetesEvents()
133 b.started.Store(true)
134
135 time.Sleep(50 * time.Millisecond)
136 return cc.CombinedAndUpdated(b.HookCtrl)
137}
138
139func (b *BindingContextController) ChangeState(newState string) (GeneratedBindingContexts, error) {
140 b.mu.Lock()

Callers 7

Test_RegisterCRDFunction · 0.95
Test_PreferredGVRFunction · 0.95
Test_SynchronizationFunction · 0.95
Test_GroupsFunction · 0.95
Test_RunScheduleFunction · 0.95

Calls 15

LoadConfigMethod · 0.95
AddBindingContextMethod · 0.95
CombinedAndUpdatedMethod · 0.95
NewHookFunction · 0.92
NewHookControllerFunction · 0.92
NewContextCombinerFunction · 0.85
SetInitialStateMethod · 0.80
InitScheduleBindingsMethod · 0.80
WithHookControllerMethod · 0.80

Tested by 7

Test_RegisterCRDFunction · 0.76
Test_PreferredGVRFunction · 0.76
Test_SynchronizationFunction · 0.76
Test_GroupsFunction · 0.76
Test_RunScheduleFunction · 0.76