mockconsul

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: MPL-2.0 Imports: 4 Imported by: 0

README

consul-mock-api

Consul Mock HTTP API helpers

Usage

package somepkg

import (
   "testing"

   "github.com/hashicorp/consul/api"
   mockconsul "github.com/mkeeler/consul-mock-api"
)

func TestTokenList(t *testing.T) {
   m := mockconsul.NewConsul(t)

   // http.Get will add both of the headers but we don't want to care about them.
   m.SetFilteredHeaders([]string{
      "Accept-Encoding",
      "User-Agent",
   })

   // set up an expectation for a GET /v1/acl/tokens
   m.ACLTokenList(200, []*api.ACLTokenListEntry{
      CreateIndex: 1,
      ModifyIndex: 2,
      AccessorID:  "cd45b25a-07cf-4a60-ae71-2a227eaace8e",
      Description: "fake token",
      NodeIdentities: []*api.ACLNodeIdentity{
         {
             NodeName: "foo",
             Datacenter: "dc1",
         },
      },
   }).Once() // expect this call to be made exactly once
   
   cfg := api.DefaultConfig()
   cfg.Address = m.URL()
   
   client, err := api.NewClient(cfg)
   if err != nil {
      t.Fatalf("error when creating a new HTTP client: %v", err)
   }
   
   tokens, _, err := client.ACL().TokenList(nil)
   if err != nil {
      t.Fatalf("error when retrieving token list: %v", err)
   }
   
   if len(tokens) != 1 {
      t.Fatalf("wrong number of token returned - expected: 1, got: %d", len(tokens))
   }
   
   // no need to do anything if using Go 1.14 as the expectations will be checked 
   // and the test HTTP server will be closed automatically. If not using Go 1.14 then
   // you should defer m.Close() after its creation
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Consul

type Consul struct {
	*mockapi.MockAPI
}

func NewConsul

func NewConsul(t mockapi.TestingT) *Consul

func (*Consul) ACLAuthMethodCreate

func (m *Consul) ACLAuthMethodCreate(body *api.ACLAuthMethod, status int, reply *api.ACLAuthMethod) *mockapi.MockAPICall

func (*Consul) ACLAuthMethodDelete

func (m *Consul) ACLAuthMethodDelete(authMethodName string, status int, reply interface{}) *mockapi.MockAPICall

func (*Consul) ACLAuthMethodGet

func (m *Consul) ACLAuthMethodGet(authMethodName string, status int, reply *api.ACLAuthMethod) *mockapi.MockAPICall

func (*Consul) ACLAuthMethodList

func (m *Consul) ACLAuthMethodList(status int, reply []*api.ACLAuthMethodListEntry) *mockapi.MockAPICall

func (*Consul) ACLAuthMethodUpdate

func (m *Consul) ACLAuthMethodUpdate(authMethodName string, body *api.ACLAuthMethod, status int, reply *api.ACLAuthMethod) *mockapi.MockAPICall

func (*Consul) ACLBindingRuleCreate

func (m *Consul) ACLBindingRuleCreate(body *api.ACLBindingRule, status int, reply *api.ACLBindingRule) *mockapi.MockAPICall

func (*Consul) ACLBindingRuleDelete

func (m *Consul) ACLBindingRuleDelete(bindingRuleID string, status int, reply interface{}) *mockapi.MockAPICall

func (*Consul) ACLBindingRuleGet

func (m *Consul) ACLBindingRuleGet(bindingRuleID string, status int, reply *api.ACLBindingRule) *mockapi.MockAPICall

func (*Consul) ACLBindingRuleList

func (m *Consul) ACLBindingRuleList(status int, reply []*api.ACLBindingRule) *mockapi.MockAPICall

func (*Consul) ACLBindingRuleUpdate

func (m *Consul) ACLBindingRuleUpdate(bindingRuleID string, body *api.ACLBindingRule, status int, reply *api.ACLBindingRule) *mockapi.MockAPICall

func (*Consul) ACLBootstrap

func (m *Consul) ACLBootstrap(status int, reply *api.ACLToken) *mockapi.MockAPICall

func (*Consul) ACLLogin

func (m *Consul) ACLLogin(body *api.ACLLoginParams, status int, reply *api.ACLToken) *mockapi.MockAPICall

func (*Consul) ACLLogout

func (m *Consul) ACLLogout(status int, reply interface{}) *mockapi.MockAPICall

func (*Consul) ACLPolicyCreate

func (m *Consul) ACLPolicyCreate(body *api.ACLPolicy, status int, reply *api.ACLPolicy) *mockapi.MockAPICall

func (*Consul) ACLPolicyDelete

func (m *Consul) ACLPolicyDelete(policyID string, status int, reply interface{}) *mockapi.MockAPICall

func (*Consul) ACLPolicyGet

func (m *Consul) ACLPolicyGet(policyID string, status int, reply *api.ACLPolicy) *mockapi.MockAPICall

func (*Consul) ACLPolicyGetByName

func (m *Consul) ACLPolicyGetByName(policyName string, status int, reply *api.ACLPolicy) *mockapi.MockAPICall

func (*Consul) ACLPolicyList

func (m *Consul) ACLPolicyList(status int, reply []*api.ACLPolicyListEntry) *mockapi.MockAPICall

func (*Consul) ACLPolicyUpdate

func (m *Consul) ACLPolicyUpdate(policyID string, body *api.ACLPolicy, status int, reply *api.ACLPolicy) *mockapi.MockAPICall

func (*Consul) ACLReplication

func (m *Consul) ACLReplication(status int, reply *api.ACLReplicationStatus) *mockapi.MockAPICall

func (*Consul) ACLRoleCreate

func (m *Consul) ACLRoleCreate(body *api.ACLPolicy, status int, reply []*api.ACLRole) *mockapi.MockAPICall

func (*Consul) ACLRoleDelete

func (m *Consul) ACLRoleDelete(roleID string, status int, reply interface{}) *mockapi.MockAPICall

func (*Consul) ACLRoleGet

func (m *Consul) ACLRoleGet(roleID string, status int, reply *api.ACLRole) *mockapi.MockAPICall

func (*Consul) ACLRoleGetByName

func (m *Consul) ACLRoleGetByName(roleName string, status int, reply *api.ACLRole) *mockapi.MockAPICall

func (*Consul) ACLRoleList

func (m *Consul) ACLRoleList(status int, reply []*api.ACLRole) *mockapi.MockAPICall

func (*Consul) ACLRoleUpdate

func (m *Consul) ACLRoleUpdate(roleID string, body *api.ACLRole, status int, reply *api.ACLRole) *mockapi.MockAPICall

func (*Consul) ACLRulesTranslate

func (m *Consul) ACLRulesTranslate(status int) *mockapi.MockAPICall

func (*Consul) ACLRulesTranslateFromToken

func (m *Consul) ACLRulesTranslateFromToken(tokenID string, status int, reply string) *mockapi.MockAPICall

func (*Consul) ACLTokenCreate

func (m *Consul) ACLTokenCreate(body *api.ACLToken, status int, reply []*api.ACLToken) *mockapi.MockAPICall

func (*Consul) ACLTokenDelete

func (m *Consul) ACLTokenDelete(tokenID string, status int, reply interface{}) *mockapi.MockAPICall

func (*Consul) ACLTokenGet

func (m *Consul) ACLTokenGet(tokenID string, status int, reply []*api.ACLToken) *mockapi.MockAPICall

func (*Consul) ACLTokenList

func (m *Consul) ACLTokenList(status int, reply []*api.ACLTokenListEntry) *mockapi.MockAPICall

func (*Consul) ACLTokenSelf

func (m *Consul) ACLTokenSelf(headers map[string]string, queryParams map[string]string, status int, reply *api.ACLToken) *mockapi.MockAPICall

func (*Consul) ACLTokenUpdate

func (m *Consul) ACLTokenUpdate(tokenID string, body *api.ACLToken, status int, reply *api.ACLToken) *mockapi.MockAPICall

func (*Consul) AgentCheckDeregister

func (m *Consul) AgentCheckDeregister(checkID string, status int) *mockapi.MockAPICall

func (*Consul) AgentCheckRegister

func (m *Consul) AgentCheckRegister(body *api.AgentCheckRegistration, status int) *mockapi.MockAPICall

func (*Consul) AgentCheckUpdateTLL

func (m *Consul) AgentCheckUpdateTLL(checkID string, body map[string]interface{}, status int) *mockapi.MockAPICall

func (*Consul) AgentChecks

func (m *Consul) AgentChecks(status int, reply map[string]*api.AgentCheck) *mockapi.MockAPICall

func (*Consul) AgentConnectAuthorize

func (m *Consul) AgentConnectAuthorize(body *api.AgentAuthorizeParams, status int) *mockapi.MockAPICall

func (*Consul) AgentConnectCALeaf

func (m *Consul) AgentConnectCALeaf(serviceID string, status int, reply *api.LeafCert) *mockapi.MockAPICall

func (*Consul) AgentConnectCARoots

func (m *Consul) AgentConnectCARoots(status int, reply *api.CARootList) *mockapi.MockAPICall

func (*Consul) AgentForceLeave

func (m *Consul) AgentForceLeave(node string, status int) *mockapi.MockAPICall

func (*Consul) AgentHealthServiceByID

func (m *Consul) AgentHealthServiceByID(serviceID string, status int, reply *api.AgentServiceChecksInfo) *mockapi.MockAPICall

func (*Consul) AgentHealthServiceByName

func (m *Consul) AgentHealthServiceByName(serviceName string, status int, reply []api.AgentServiceChecksInfo) *mockapi.MockAPICall

func (*Consul) AgentHost

func (m *Consul) AgentHost(status int, reply map[string]interface{}) *mockapi.MockAPICall

func (*Consul) AgentJoin

func (m *Consul) AgentJoin(address string, status int) *mockapi.MockAPICall

func (*Consul) AgentLeave

func (m *Consul) AgentLeave(status int) *mockapi.MockAPICall

func (*Consul) AgentMaintenance

func (m *Consul) AgentMaintenance(status int) *mockapi.MockAPICall

func (*Consul) AgentMembers

func (m *Consul) AgentMembers(status int, reply []*api.AgentMember) *mockapi.MockAPICall

func (*Consul) AgentMetrics

func (m *Consul) AgentMetrics(status int, reply *api.MetricsInfo) *mockapi.MockAPICall

func (*Consul) AgentMonitor

func (m *Consul) AgentMonitor(status int, reply io.Reader) *mockapi.MockAPICall

func (*Consul) AgentReload

func (m *Consul) AgentReload(status int) *mockapi.MockAPICall

func (*Consul) AgentSelf

func (m *Consul) AgentSelf(status int, reply map[string]map[string]interface{}) *mockapi.MockAPICall

func (*Consul) AgentService

func (m *Consul) AgentService(serviceID string, status int, reply *api.AgentService) *mockapi.MockAPICall

func (*Consul) AgentServiceDeregister

func (m *Consul) AgentServiceDeregister(status int) *mockapi.MockAPICall

func (*Consul) AgentServiceMaintenance

func (m *Consul) AgentServiceMaintenance(serviceID string, status int) *mockapi.MockAPICall

func (*Consul) AgentServiceRegister

func (m *Consul) AgentServiceRegister(body *api.AgentServiceRegistration, status int) *mockapi.MockAPICall

func (*Consul) AgentServices

func (m *Consul) AgentServices(status int, reply map[string]*api.AgentService) *mockapi.MockAPICall

func (*Consul) AgentTokenSet

func (m *Consul) AgentTokenSet(tokenType string, body []byte, status int) *mockapi.MockAPICall

func (*Consul) CatalogConnect

func (m *Consul) CatalogConnect(service string, queryParams map[string]string, status int, reply []*api.CatalogService) *mockapi.MockAPICall

func (*Consul) CatalogDatacenters

func (m *Consul) CatalogDatacenters(status int, reply []string) *mockapi.MockAPICall

func (*Consul) CatalogDeregister

func (m *Consul) CatalogDeregister(body *api.CatalogRegistration, status int, reply interface{}) *mockapi.MockAPICall

func (*Consul) CatalogGatewayServices

func (m *Consul) CatalogGatewayServices(gateway string, queryParams map[string]string, status int, reply []*api.GatewayService) *mockapi.MockAPICall

func (*Consul) CatalogNode

func (m *Consul) CatalogNode(node string, queryParams map[string]string, status int, reply *api.CatalogNode) *mockapi.MockAPICall

func (*Consul) CatalogNodeServiceList

func (m *Consul) CatalogNodeServiceList(node string, queryParams map[string]string, status int, reply *api.CatalogNodeServiceList) *mockapi.MockAPICall

func (*Consul) CatalogNodes

func (m *Consul) CatalogNodes(status int, reply []*api.Node) *mockapi.MockAPICall

func (*Consul) CatalogRegister

func (m *Consul) CatalogRegister(body *api.CatalogRegistration, status int, reply interface{}) *mockapi.MockAPICall

func (*Consul) CatalogService

func (m *Consul) CatalogService(service string, queryParams map[string]string, status int, reply []*api.CatalogService) *mockapi.MockAPICall

func (*Consul) CatalogServices

func (m *Consul) CatalogServices(status int, reply map[string][]string) *mockapi.MockAPICall

func (*Consul) HealthChecks

func (m *Consul) HealthChecks(service string, queryParams map[string]string, status int, reply api.HealthChecks) *mockapi.MockAPICall

func (*Consul) HealthConnect

func (m *Consul) HealthConnect(service string, queryParams map[string]string, status int, reply []*api.ServiceEntry) *mockapi.MockAPICall

func (*Consul) HealthIngress

func (m *Consul) HealthIngress(service string, queryParams map[string]string, status int, reply []*api.ServiceEntry) *mockapi.MockAPICall

func (*Consul) HealthNode

func (m *Consul) HealthNode(node string, queryParams map[string]string, status int, reply api.HealthChecks) *mockapi.MockAPICall

func (*Consul) HealthService

func (m *Consul) HealthService(service string, queryParams map[string]string, status int, reply []*api.ServiceEntry) *mockapi.MockAPICall

func (*Consul) KVAcquire

func (m *Consul) KVAcquire(key string, queryParams map[string]string, body *api.KVPair, status int, reply bool) *mockapi.MockAPICall

func (*Consul) KVDelete

func (m *Consul) KVDelete(key string, queryParams map[string]string, body *api.KVPair, status int) *mockapi.MockAPICall

func (*Consul) KVDeleteCAS

func (m *Consul) KVDeleteCAS(key string, queryParams map[string]string, body *api.KVPair, status int, reply bool) *mockapi.MockAPICall

func (*Consul) KVGet

func (m *Consul) KVGet(key string, queryParams map[string]string, status int, reply *api.KVPairs) *mockapi.MockAPICall

func (*Consul) KVKeys

func (m *Consul) KVKeys(prefix string, queryParams map[string]string, status int, reply []string) *mockapi.MockAPICall

func (*Consul) KVList

func (m *Consul) KVList(prefix string, queryParams map[string]string, status int, reply *api.KVPairs) *mockapi.MockAPICall

func (*Consul) KVPut

func (m *Consul) KVPut(key string, queryParams map[string]string, body []byte, status int) *mockapi.MockAPICall

func (*Consul) KVPutCAS

func (m *Consul) KVPutCAS(key string, queryParams map[string]string, body *api.KVPair, status int, reply bool) *mockapi.MockAPICall

func (*Consul) KVRelease

func (m *Consul) KVRelease(key string, queryParams map[string]string, body *api.KVPair, status int, reply bool) *mockapi.MockAPICall

func (*Consul) StatusLeader

func (m *Consul) StatusLeader(status int, reply string) *mockapi.MockAPICall

func (*Consul) StatusPeers

func (m *Consul) StatusPeers(status int, reply []string) *mockapi.MockAPICall

Jump to

Keyboard shortcuts

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