A solution for webhook delivery for multiple services, primarily for testing. Still in development.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Erik Hollensbe 6967844951 Fixed whitespace in readme example 1 week ago
LICENSE Licensed 1 week ago
README.md Fixed whitespace in readme example 1 week ago
digester_test.go More docs 1 week ago
errors.go Some documentation as comments. 1 week ago
gitea_test.go Initial commit 1 week ago
go.mod Initial commit 1 week ago
messages.go Some documentation as comments. 1 week ago
payloads.go Some documentation as comments. 1 week ago
pidgeon.go Some documentation as comments. 1 week ago
static_messages.go Initial commit 1 week ago

README.md

pidgeon: a small library for testing webhooks

I needed a reliable way to test webhooks in a tight loop with varying parameters. This is what I came up with. Beats integration testing.

Support

It only supports gitea right now, I will change that as other projects progress.

Usage & Example

Please see the godoc for more information on usage.

The best example here is probably an annotated version of our tests. Here we do some basic operations with static payloads and templates:

package pidgeon

import "testing"

func TestGiteaSample(t *testing.T) {
  // this would be your test service, we provide one internally for testing the system
  // itself. the url is the important bit, and the hook secret which is
  // "secret". This is a gitea hook acceptor.
  url := newHTTPD(t, "gitea", "secret")

  // test: for each event type, push a sample payload with the
  // appropriate secret. Fail on any error.
  for _, event := range []string{"push", "pull_request"} {
    m := NewGiteaMessage(GiteaSamplePayload, "secret", event)
    TestDeliver(t, m, url)
  }

  // negative test: invalid secret
  for _, event := range []string{"push", "pull_request"} {
    m := NewGiteaMessage(GiteaSamplePayload, "invalid secret", event)
    if err := Deliver(m, url); err == nil {
      t.Fatal("passed with invalid secret")
    }
  }

  // negative test: invalid event
  for _, event := range []string{"monkeys", "fling", "poo", ""} {
    m := NewGiteaMessage(GiteaSamplePayload, "secret", event)
    if err := Deliver(m, url); err == nil {
      t.Fatal("passed with invalid event")
    }
  }
}

func TestTemplatePayload(t *testing.T) {
  url := newHTTPD(t, "gitea", "secret")
  // Templates use a pre-defined text/template with a struct just like the
  // template library does, just makes it easier to deliver easily to a webhook.
  payload, err := NewTemplatePayload(GiteaSampleTemplateSource, &GiteaSampleData{})
  if err != nil {
    t.Fatal(err)
  }

  m := NewGiteaMessage(payload, "secret", "push")
  TestDeliver(t, m, url)
}

Author

Erik Hollensbe erik+github@hollensbe.org

LICENSE: MIT