package
1.5.3
Repository: https://github.com/flant/shell-operator.git
Documentation: pkg.go.dev

# README

Binding Context Generator

Binding Context Generator provides the ability to generate binding contexts for hooks testing purposes.

Usage example:

  1. Hook Config
config := `
configVersion: v1
schedule:
- name: every_minute
  crontab: '* * * * *'
  includeSnapshotsFrom:
  - pod
kubernetes:
- apiVersion: v1
  name: pod
  kind: Pod
  watchEvent:
  - Added
  - Modified
  - Deleted
  namespace:
    nameSelector:
      matchNames:
      - default`
  1. Initial objects state
initialState := `
---
apiVersion: v1
kind: Pod
metadata:
  name: pod-0
---
apiVersion: v1
kind: Pod
metadata:
  name: pod-1
`
  1. New state
newState := `
---
apiVersion: v1
kind: Pod
metadata:
  name: pod-0
`
  1. Create new binding context controller
c := context.NewBindingContextController(config, initialState)
  1. Register CRDs (if it is necessary) in format [Group, Version, Kind, isNamespaced]:
c.RegisterCRD("example.com", "v1", "Example", true)
c.RegisterCRD("example.com", "v1", "ClusterExample", false)
  1. Run controller to get initial binding context
contexts, err := c.Run()
if err != nil {
  return err
}
testContexts(contexts)
  1. Change state to get new binding contexts
contexts, err = c.ChangeState(newState)
if err != nil {
  return err
}
testNewContexts(contexts)
  1. Run schedule to get binding contexts for a cron task
contexts, err = c.RunSchedule("* * * * *")
if err != nil {
  return err
}
testScheduleContexts(contexts)

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
NewStateController creates controller to apply state changes.

# Constants

TestQueueName is a name of the queue created by ContextCombiner.
TestTaskType is a type for tasks created by ContextCombiner.

# Structs

No description provided by the author
ContextCombiner is used to bring logic behind the combineBindingContextForHook method into tests.
No description provided by the author
StateController holds objects state for FakeCluster.