fake

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2024 License: Apache-2.0 Imports: 4 Imported by: 1

README

fake - generate random data for testing and/or performance evaluation

Go Reference CI Go Report Card

Fake is a Go library and CLI to generate random data such as names, adjectives, IP addresses and so on.

This repository contains three Go modules:

  • github.com/khulnasoft/fake: a library to generate generic random data which can be useful to any project (e.g. fake.Adjective(), fake.IP(), ...).
  • github.com/khulnasoft/fake/flow: a library to generate random Hubble network flows and flow related data. This library is only relevant to projects directly related to Cilium and/or Hubble.
  • github.com/khulnasoft/fake/cmd: a CLI to generate random data.

As opposed to most fake data generator Go libraries, a design philosophy of this library is to allow fine-grained control over generated data.

Let's illustrate this with an example. Instead of having separate functions to generate IPv4 and IPv6 addresses (e.g. fake.IPv4() and fake.IPv6()), there is a single fake.IP() function. However, this generator function, like most others, can take optional arguments. By default, i.e. when no option is specified (fake.IP()), it generates a random IP address which can be either v4 or v6. However, when passing the option to generate IPv4 addresses only (fake.IP(fake.WithIPv4()) option, only v4 addresses are generated. It is also possible to pass an option to specify a CIDR that randomly generated IP addresses must belong to (e.g. fake.IP(fake.WithIPCIDR("10.0.0.0/8"))).

Compared to other fake data generator Go libraries such as github.com/icrowley/fake or github.com/bxcodec/faker, this library does not (yet) support as many generators (contributions welcome!).

Installing the CLI

Go needs to be installed. Then, from either the root directory or the cmd subdirectory, the fake binary can be compiled and installed via the install make target. E.g.

make install

By default, it installs the binary to /usr/local/bin/fake. The destination directory can be specified using the BINDIR environment variable, e.g.:

BINDIR=~/.local/bin make install

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Adjective

func Adjective() string

Adjective generates a random adjective.

func AlphaNum

func AlphaNum(length int) string

AlphaNum generates a random alphanumeric string of the given length.

func App

func App() string

App generates a random software application name.

func DeploymentTier

func DeploymentTier() string

DeploymentTier generates a random software deployment tier such as prod, staging, etc.

func IP

func IP(options ...IPOption) string

IP generates a random IP address. Options may be provided to specify a network for the address or if it should be IPv4 or IPv6.

func K8sLabels

func K8sLabels() []string

K8sLabels generates a random set of Kubernetes labels.

func K8sNamespace

func K8sNamespace() string

K8sNamespace generates a random Kubernetes namespace name.

func K8sNodeName

func K8sNodeName() string

K8sNodeName generates a random Kubernetes node name.

func K8sPodName

func K8sPodName() string

K8sPodName generates a random Kubernetes pod name.

func MAC

func MAC() string

MAC generates a random MAC address.

func Name

func Name() string

Name generates a random name.

func Names

func Names(max int) []string

Names generates a random set of names. It panics if max < 0.

func Noun

func Noun() string

Noun generates a random noun.

func Port

func Port(options ...PortOption) uint32

Port generates a random port number between 1 and 65535 or in the range specified by the given option.

Types

type IPOption

type IPOption interface {
	// contains filtered or unexported methods
}

IPOption is an option to use with IP.

func WithIPCIDR

func WithIPCIDR(cidr string) IPOption

WithIPCIDR defines a network for generated IPs. This option is incompatible with WithIPv4 and WithIPv6. It panics if the given cidr is invalid.

func WithIPv4

func WithIPv4() IPOption

WithIPv4 specifies that the generated IP address must be IPv4. This option is incompatible with WithIPv6 and WithIPCIDR.

func WithIPv6

func WithIPv6() IPOption

WithIPv6 specifies that the generated IP address must be IPv6. This option is incompatible with WithIPv4 and WithIPCIDR.

type PortOption

type PortOption interface {
	// contains filtered or unexported methods
}

PortOption is an option to use with Port.

func WithPortDynamic

func WithPortDynamic() PortOption

WithPortDynamic specifies that the generated port must be in the dynamic range, i.e. [49152,65535]. This option is incompatible with WithPortSystem and WithPortUser.

func WithPortSystem

func WithPortSystem(zero bool) PortOption

WithPortSystem specifies that the generated port must in the system range. If zero is true, the port range is [0,1023], otherwise it's [1,1023]. This option is incompatible with WithPortUser and WithPortDynamic.

func WithPortUser

func WithPortUser() PortOption

WithPortUser specifies that the generated port must be in the user range, i.e. [1024, 49151]. This option is incompatible with WithPortSystem and WithPortDynamic.

Directories

Path Synopsis
cmd module
flow module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL