Socket
Socket
Sign inDemoInstall

github.com/stvp/go-udp-testing

Package Overview
Dependencies
0
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    github.com/stvp/go-udp-testing

Package udp implements UDP test helpers. It lets you assert that certain strings must or must not be sent to a given local UDP listener.


Version published

Readme

Source

go-udp-testing

Build Status

Provides UDP socket test helpers for Go.

Documentation

Examples

package main

import (
  "github.com/stvp/go-udp-testing"
  "testing"
)

func TestStatsdReporting(t *testing.T) {
  udp.SetAddr(":8125")

  udp.ShouldReceiveOnly(t, "mystat:2|g", func() {
    statsd.Gauge("mystat", 2)
  })

  udp.ShouldNotReceiveOnly(t, "mystat:1|c", func() {
    statsd.Gauge("bukkit", 2)
  })

  udp.ShouldReceive(t, "bar:2|g", func() {
    statsd.Gauge("foo", 2)
    statsd.Gauge("bar", 2)
    statsd.Gauge("baz", 2)
  })

  udp.ShouldNotReceive(t, "bar:2|g", func() {
    statsd.Gauge("foo", 2)
    statsd.Gauge("baz", 2)
  })

  expected := []string{
    "bar:2|g",
    "baz:5|g",
  }
  udp.ShouldReceiveAll(t, expected, func() {
    statsd.Gauge("bar", 2)
    statsd.Gauge("baz", 2)
  })

  unexpected := []string{
    "bar",
    "baz",
  }
  udp.ShouldNotReceiveAny(t, unexpected, func() {
    statsd.Gauge("foo", 1)
  })

  expected := []string{ "" }
    "bar:2|g",
    "baz:5|g",
  }
  unexpected := []string{
    "foo",
  }
  udp.ShouldReceiveAllAndNotReceiveAny(t, expected, unexpected, func() {
    statsd.Gauge("bar", 2)
    statsd.Gauge("baz", 5)
  })
}

FAQs

Last updated on 19 Oct 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc