Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/findkim/consul-mock-api

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/findkim/consul-mock-api

  • v0.0.0-20200911151247-c380cdbcb976
  • Source
  • Go
  • Socket score

Version published
Created
Source

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
}

FAQs

Package last updated on 11 Sep 2020

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc