billing_emitter_test.go 2.4 KB

1234567891011121314151617181920212223242526272829
  1. package multitenant
  2. import "testing"
  3. func Test_intervalFromCommand(t *testing.T) {
  4. tests := []struct {
  5. name string
  6. cmd string
  7. want string
  8. }{
  9. {cmd: "/home/weave/scope --mode=probe --probe-only --probe.kubernetes=true --probe.spy.interval=3s --probe.publish.interval=5s --probe.processes=false --probe.conntrack=false --probe.ebpf.connections=false --probe.docker.bridge=docker0 --probe.docker=true https://redacted@cloud.weave.works.", want: "5s", name: "seconds"},
  10. {cmd: "/home/weave/scope --mode=probe --probe-only --probe.kubernetes=true --probe.spy.interval=3s --probe.publish.interval 5s --probe.processes=false --probe.conntrack=false --probe.ebpf.connections=false --probe.docker.bridge=docker0 --probe.docker=true https://redacted@cloud.weave.works.", want: "5s", name: "space"},
  11. {cmd: "/home/weave/scope --mode=probe --no-app --probe.docker=true --probe.kubernetes.role=host --weave=false --probe.publish.interval=4500ms --probe.spy.interval=2s --probe.http.listen=:4041 --probe.conntrack.buffersize=4194304 https://redacted@cloud.weave.works scope.weave.svc.cluster.local:80", want: "4500ms", name: "miliseconds"},
  12. {cmd: "/home/weave/scope --mode=probe --no-app --probe.docker=true --probe.kubernetes.role=host --weave=false --probe.spy.interval=2s --probe.http.listen=:4041 --probe.conntrack.buffersize=4194304 https://redacted@cloud.weave.works scope.weave.svc.cluster.local:80", want: "", name: "notset"},
  13. {cmd: "/home/weave/scope --mode=probe --probe-only --probe.kubernetes.role=host --probe.publish.interval=4500ms --probe.spy.interval=10s --probe.docker.bridge=docker0 --probe.docker=true --probe.ebpf.connections=false --probe.conntrack=false https://redacted@cloud.weave.works.", want: "10s", name: "higher-spy-interval"},
  14. {cmd: "/bin/prometheus --config.file=/etc/prometheus/prometheus.yml --web.listen-address=:8080 --storage.tsdb.retention.time=2h --web.enable-lifecycle", want: "", name: "notscope"},
  15. {cmd: "", want: "", name: "blank"},
  16. {cmd: "/home/weave/scope --probe.publish.interval=3s", want: "3s", name: "at-end"},
  17. {cmd: "/home/weave/scope --probe.publish.interval=", want: "", name: "equals-blank"},
  18. {cmd: "/home/weave/scope --probe.publish.interval", want: "", name: "no-value"},
  19. }
  20. for _, tt := range tests {
  21. t.Run(tt.name, func(t *testing.T) {
  22. if got := intervalFromCommand(tt.cmd); got != tt.want {
  23. t.Errorf("intervalFromCommand() = %v, want %v", got, tt.want)
  24. }
  25. })
  26. }
  27. }