cerulean

package module
v0.0.0-...-08e7634 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

README

Cerulean

WIP Go Report Card Man Hours

Cerulean is a mock Azure API, designed for writing infrastructure tests so you can run tests without spending that dosh. This is great for folks who are using the azure-sdk-for-go especially. Here's a nifty example:

package test

import (
    "fmt"
    "testing"

    "github.com/azure/azure-sdk-for-go/services/resources/mgmt/2019-11-01/subscriptions"
    "github.com/goshlanguage/cerulean"
)

func TestSubscription(t *testing.T) {
    server := cerulean.New("c27e7a81-b684-4fce-91d8-fed9e9bb534a")
    client := subscriptions.NewClientWithBaseURI(server.GetBaseClientURI())
    client.Authorizer = autorest.NullAuthorizer{}

    resultPage, err := client.List(context.TODO())
    if err != nil {
	    panic(err)
    }
    // do stuff with your mocked client
}

This project is artisanally crafted, laptop to market software. Please open an issue if you find a bug or have a request. PRs are welcome.

Design

Cerulean works by creating an http server that mimics the Azure API rest endpoints and responses. You can then redirect your Azure SDK clients to use the address of this mock server, and your client will then talk to this mock. This project is inspired by moto.

Cerulean emulates the Azure API. There are two good references for the API to use in development:

  1. azure-rest-api-specs
  2. azure rest api docs

If you decide to explore the API via curl or postman with the docs above, this article may be helpful to you: https://medium.com/@mauridb/calling-azure-rest-api-via-curl-eb10a06127

If you prefer swagger, then you can load in the specs you want to reference by passing it's URL, such as:

Documentation

Overview

Package cerulean provides Go packages for mocking the Azure api. GitHub repo: https://github.com/goshlanguage/cerulean

API reference: https://docs.microsoft.com/en-us/rest/api/azure/ Samples: https://github.com/goshlanguage/cerulean

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cerulean

type Cerulean struct {
	// Addr is the address that Cerulean should listen at, eg: 127.0.0.1:51234
	Addr string
	// BaseSubscriptionID is the base subscriptionID created and the default subscriptionID used for tests
	BaseSubscriptionID string
	Echo               *echo.Echo
	Services           []services.Service
	Store              *lightdb.Store
}

Cerulean holds the handlers and port to instantiate the mock server

func New

func New() Cerulean

New sets up an instance of our mock and returns it

and returns a the mock server

New generates a local address to be passed in when initializing a `BaseClient`

in order to point it at the mock server.

func (*Cerulean) GetBaseClientURI

func (server *Cerulean) GetBaseClientURI() string

GetBaseClientURI returns the address string in the form consumable by say an azure-sdk-for-go BaseClient

func (*Cerulean) ListenAndServe

func (server *Cerulean) ListenAndServe() error

ListenAndServe starts our server.

Directories

Path Synopsis
internal
pkg

Jump to

Keyboard shortcuts

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