cloudemu

package module
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 4 Imported by: 0

README

cloudemu

Zero-Cost In-Memory Cloud Emulation for Go

Go Reference Go Report Card MIT License Tests Go Version Providers Zero Cost Documentation


cloudemu is a Go library that emulates cloud services entirely in memory. No real cloud accounts, no Docker, no network calls. Import the package, create a provider, and test your cloud code instantly.

aws := cloudemu.NewAWS()
azure := cloudemu.NewAzure()
gcp := cloudemu.NewGCP()

Installation

go get github.com/stackshy/cloudemu

Requires Go 1.25.0+.

The Problem

Testing cloud-dependent code is painful. You either pay for real accounts, wrestle with heavy emulators that need Docker, or write incomplete mocks from scratch.

Approach Cost Speed Offline
Real cloud (AWS/Azure/GCP) $$$ Slow (seconds) No
LocalStack / Emulators $ Medium (100ms+) Yes
cloudemu Free Fast (~10ms) Yes

How It Works

cloudemu provides mock implementations of cloud services that behave like the real thing. Each provider (AWS, Azure, GCP) gives you typed access to all supported services. You call the same operations you'd call in production — create resources, read data, manage lifecycle — and cloudemu handles it in memory with realistic behavior.

Example: EC2 Compute

package main

import (
    "context"
    "fmt"

    "github.com/stackshy/cloudemu"
    "github.com/stackshy/cloudemu/compute/driver"
)

func main() {
    ctx := context.Background()
    aws := cloudemu.NewAWS()

    // Launch 2 instances — they start in "pending" and transition to "running"
    instances, _ := aws.EC2.RunInstances(ctx, driver.InstanceConfig{
        ImageID:      "ami-0abcdef1234567890",
        InstanceType: "t2.micro",
        Tags:         map[string]string{"env": "test"},
    }, 2)

    fmt.Println(instances[0].State) // "running"
    fmt.Println(instances[0].ID)    // "i-00000001"

    // Stop an instance — state machine enforces valid transitions
    _ = aws.EC2.StopInstances(ctx, []string{instances[0].ID})

    // Describe to check state
    desc, _ := aws.EC2.DescribeInstances(ctx, []string{instances[0].ID}, nil)
    fmt.Println(desc[0].State) // "stopped"

    // Terminate
    _ = aws.EC2.TerminateInstances(ctx, []string{instances[0].ID})

    // Trying to stop a terminated instance returns an error — just like real EC2
    err := aws.EC2.StopInstances(ctx, []string{instances[0].ID})
    fmt.Println(err) // "cannot stop instance: invalid transition"
}

This same pattern works across all services and all three providers. Replace aws.EC2 with azure.VirtualMachines or gcp.GCE and the code behaves identically.

What Makes It Realistic

cloudemu goes beyond basic CRUD mocks. It reproduces real cloud behaviors so your tests catch real issues:

  • State Machines — VMs enforce valid lifecycle transitions (pending → running → stopped → terminated). Illegal transitions return errors.
  • Auto-Metrics — Launching a VM automatically pushes CPU, Network, and Disk metrics to the monitoring service. Stop/start/terminate emit corresponding metric values.
  • Alarm Evaluation — Push metric data and alarms automatically transition between OK and ALARM based on threshold comparison.
  • IAM Policy Evaluation — Parses JSON policy documents with wildcard matching. Explicit Deny overrides Allow.
  • FIFO Deduplication — FIFO queues enforce 5-minute deduplication windows.
  • Dead-Letter Queues — Messages exceeding max receive count move to the DLQ automatically.
  • TTL Expiry — Cached items and database records expire after their TTL. Lazy cleanup on read.
  • Stream/Change Feed — Database mutations produce stream records (INSERT/MODIFY/REMOVE).
  • Numeric-Aware Comparisons — Database filters compare "10" > "9" correctly using numeric ordering.

Cross-Cutting Features

Every service can be wrapped with a portable API layer that adds test-oriented features:

bucket := storage.NewBucket(aws.S3,
    storage.WithRecorder(rec),              // record every API call
    storage.WithMetrics(mc),                // track call counts and durations
    storage.WithErrorInjection(inj),        // simulate cloud failures
    storage.WithRateLimiter(limiter),       // simulate API throttling
    storage.WithLatency(5*time.Millisecond),// simulate network delay
)
Feature What It Does
Call Recording Capture every API call with inputs, outputs, errors, and timing
Error Injection Simulate failures: always, every Nth call, probabilistic, or first N calls
Rate Limiting Token bucket limiter that returns Throttled errors when exhausted
Metrics Collection Track calls_total, call_duration, errors_total per operation
Fake Clock Control time for deterministic testing of TTL, dedup, alarms
Latency Simulation Add delays to test timeout handling

Configuration

aws := cloudemu.NewAWS(
    config.WithRegion("eu-west-1"),
    config.WithAccountID("999888777666"),
    config.WithClock(config.NewFakeClock(time.Now())),
)

Error Handling

All operations return errors with canonical codes. Use helper functions to check types:

import cerrors "github.com/stackshy/cloudemu/errors"

_, err := aws.S3.GetObject(ctx, "bucket", "missing-key")
if cerrors.IsNotFound(err) {
    // handle missing resource
}

// Codes: NotFound, AlreadyExists, InvalidArgument,
//        FailedPrecondition, PermissionDenied, Throttled

Architecture

Three-layer design inspired by Go CDK:

Portable API     →  recording, metrics, rate limiting, error injection
Driver Interface →  minimal Go interfaces per service
Provider Mocks   →  in-memory backends (AWS/Azure/GCP) using generic memstore

All mocks are backed by a generic, thread-safe memstore.Store[V]. Services emit cloud-native metrics to the monitoring service, so you can query metrics via GetMetricData the same way you would with real CloudWatch, Azure Monitor, or Cloud Monitoring.

Running Tests

go build ./...   # compile
go vet ./...     # static analysis
go test -v ./... # run all tests

License

MIT

Documentation

Overview

Package cloudemu provides zero-cost, in-memory cloud emulation of AWS, Azure, and GCP cloud services for Go.

cloudemu follows a three-layer architecture:

  • Portable API: High-level types (storage.Bucket, compute.Compute, etc.) that wrap drivers with cross-cutting concerns like recording, metrics, rate limiting, and error injection.

  • Driver Interfaces: Minimal contracts (storage/driver, compute/driver, etc.) that each provider must implement.

  • Provider Implementations: In-memory backends (providers/aws/s3, providers/azure/blobstorage, providers/gcp/gcs, etc.) powered by a generic memstore.

10 cloud services are covered across all three providers: Storage, Compute, Database, Serverless, Networking, Monitoring, IAM, DNS, Load Balancer, and Message Queue.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAWS

func NewAWS(opts ...config.Option) *aws.Provider

NewAWS creates a new AWS mock provider.

func NewAzure

func NewAzure(opts ...config.Option) *azure.Provider

NewAzure creates a new Azure mock provider.

func NewGCP

func NewGCP(opts ...config.Option) *gcp.Provider

NewGCP creates a new GCP mock provider.

Types

This section is empty.

Directories

Path Synopsis
Package cache provides a portable cache API with cross-cutting concerns.
Package cache provides a portable cache API with cross-cutting concerns.
driver
Package driver defines the interface for cache service implementations.
Package driver defines the interface for cache service implementations.
Package compute provides a portable compute API with cross-cutting concerns.
Package compute provides a portable compute API with cross-cutting concerns.
driver
Package driver defines the interface for compute service implementations.
Package driver defines the interface for compute service implementations.
Package config provides configuration options for cloudemu services.
Package config provides configuration options for cloudemu services.
Package containerregistry provides a portable container registry API with cross-cutting concerns.
Package containerregistry provides a portable container registry API with cross-cutting concerns.
driver
Package driver defines the interface for container registry service implementations.
Package driver defines the interface for container registry service implementations.
Package cost provides simulated cost tracking for cloud operations.
Package cost provides simulated cost tracking for cloud operations.
Package database provides a portable database API with cross-cutting concerns.
Package database provides a portable database API with cross-cutting concerns.
driver
Package driver defines the interface for database service implementations.
Package driver defines the interface for database service implementations.
dns
Package dns provides a portable DNS API with cross-cutting concerns.
Package dns provides a portable DNS API with cross-cutting concerns.
driver
Package driver defines the interface for DNS service implementations.
Package driver defines the interface for DNS service implementations.
Package errors provides canonical error codes for cloudemu services.
Package errors provides canonical error codes for cloudemu services.
Package eventbus provides a portable event bus API with cross-cutting concerns.
Package eventbus provides a portable event bus API with cross-cutting concerns.
driver
Package driver defines the interface for event bus service implementations.
Package driver defines the interface for event bus service implementations.
iam
Package iam provides a portable IAM API with cross-cutting concerns.
Package iam provides a portable IAM API with cross-cutting concerns.
driver
Package driver defines the interface for IAM service implementations.
Package driver defines the interface for IAM service implementations.
Package inject provides error injection for testing cloudemu services.
Package inject provides error injection for testing cloudemu services.
internal
idgen
Package idgen provides ID generators for various cloud resource types.
Package idgen provides ID generators for various cloud resource types.
memstore
Package memstore provides a generic thread-safe in-memory key-value store.
Package memstore provides a generic thread-safe in-memory key-value store.
Package loadbalancer provides a portable load balancer API with cross-cutting concerns.
Package loadbalancer provides a portable load balancer API with cross-cutting concerns.
driver
Package driver defines the interface for load balancer service implementations.
Package driver defines the interface for load balancer service implementations.
Package logging provides a portable logging API with cross-cutting concerns.
Package logging provides a portable logging API with cross-cutting concerns.
driver
Package driver defines the interface for logging service implementations.
Package driver defines the interface for logging service implementations.
Package messagequeue provides a portable message queue API with cross-cutting concerns.
Package messagequeue provides a portable message queue API with cross-cutting concerns.
driver
Package driver defines the interface for message queue service implementations.
Package driver defines the interface for message queue service implementations.
Package metrics provides in-memory metrics collection for cloudemu services.
Package metrics provides in-memory metrics collection for cloudemu services.
Package monitoring provides a portable monitoring API with cross-cutting concerns.
Package monitoring provides a portable monitoring API with cross-cutting concerns.
driver
Package driver defines the interface for monitoring service implementations.
Package driver defines the interface for monitoring service implementations.
Package networking provides a portable networking API with cross-cutting concerns.
Package networking provides a portable networking API with cross-cutting concerns.
driver
Package driver defines the interface for networking service implementations.
Package driver defines the interface for networking service implementations.
Package notification provides a portable notification API with cross-cutting concerns.
Package notification provides a portable notification API with cross-cutting concerns.
driver
Package driver defines the interface for notification service implementations.
Package driver defines the interface for notification service implementations.
Package pagination provides generic pagination utilities for cloudemu services.
Package pagination provides generic pagination utilities for cloudemu services.
providers
aws
Package aws provides AWS mock provider factories.
Package aws provides AWS mock provider factories.
aws/awsiam
Package awsiam provides an in-memory mock implementation of AWS IAM.
Package awsiam provides an in-memory mock implementation of AWS IAM.
aws/cloudwatch
Package cloudwatch provides an in-memory mock implementation of AWS CloudWatch.
Package cloudwatch provides an in-memory mock implementation of AWS CloudWatch.
aws/cloudwatchlogs
Package cloudwatchlogs provides an in-memory mock implementation of AWS CloudWatch Logs.
Package cloudwatchlogs provides an in-memory mock implementation of AWS CloudWatch Logs.
aws/ecr
Package ecr provides an in-memory mock implementation of AWS Elastic Container Registry.
Package ecr provides an in-memory mock implementation of AWS Elastic Container Registry.
aws/elasticache
Package elasticache provides an in-memory mock implementation of AWS ElastiCache.
Package elasticache provides an in-memory mock implementation of AWS ElastiCache.
aws/elb
Package elb provides an in-memory mock implementation of AWS Elastic Load Balancing.
Package elb provides an in-memory mock implementation of AWS Elastic Load Balancing.
aws/eventbridge
Package eventbridge provides an in-memory mock implementation of AWS EventBridge.
Package eventbridge provides an in-memory mock implementation of AWS EventBridge.
aws/route53
Package route53 provides an in-memory mock implementation of AWS Route 53.
Package route53 provides an in-memory mock implementation of AWS Route 53.
aws/secretsmanager
Package secretsmanager provides an in-memory mock implementation of AWS Secrets Manager.
Package secretsmanager provides an in-memory mock implementation of AWS Secrets Manager.
aws/sns
Package sns provides an in-memory mock implementation of AWS Simple Notification Service.
Package sns provides an in-memory mock implementation of AWS Simple Notification Service.
aws/sqs
Package sqs provides an in-memory mock implementation of AWS Simple Queue Service.
Package sqs provides an in-memory mock implementation of AWS Simple Queue Service.
aws/vpc
Package vpc provides an in-memory mock implementation of AWS VPC networking.
Package vpc provides an in-memory mock implementation of AWS VPC networking.
azure
Package azure provides Azure mock provider factories.
Package azure provides Azure mock provider factories.
azure/acr
Package acr provides an in-memory mock implementation of Azure Container Registry.
Package acr provides an in-memory mock implementation of Azure Container Registry.
azure/azurecache
Package azurecache provides an in-memory mock implementation of Azure Cache for Redis.
Package azurecache provides an in-memory mock implementation of Azure Cache for Redis.
azure/azuredns
Package azuredns provides an in-memory mock implementation of Azure DNS.
Package azuredns provides an in-memory mock implementation of Azure DNS.
azure/azureiam
Package azureiam provides an in-memory mock implementation of Azure Active Directory / IAM.
Package azureiam provides an in-memory mock implementation of Azure Active Directory / IAM.
azure/azurelb
Package azurelb provides an in-memory mock implementation of Azure Load Balancer.
Package azurelb provides an in-memory mock implementation of Azure Load Balancer.
azure/azuremonitor
Package azuremonitor provides an in-memory mock implementation of Azure Monitor.
Package azuremonitor provides an in-memory mock implementation of Azure Monitor.
azure/blobstorage
Package blobstorage provides an in-memory mock implementation of Azure Blob Storage.
Package blobstorage provides an in-memory mock implementation of Azure Blob Storage.
azure/cosmosdb
Package cosmosdb provides an in-memory mock implementation of Azure Cosmos DB.
Package cosmosdb provides an in-memory mock implementation of Azure Cosmos DB.
azure/eventgrid
Package eventgrid provides an in-memory mock implementation of Azure Event Grid.
Package eventgrid provides an in-memory mock implementation of Azure Event Grid.
azure/functions
Package functions provides an in-memory mock implementation of Azure Functions.
Package functions provides an in-memory mock implementation of Azure Functions.
azure/keyvault
Package keyvault provides an in-memory mock implementation of Azure Key Vault.
Package keyvault provides an in-memory mock implementation of Azure Key Vault.
azure/loganalytics
Package loganalytics provides an in-memory mock implementation of Azure Log Analytics.
Package loganalytics provides an in-memory mock implementation of Azure Log Analytics.
azure/notificationhubs
Package notificationhubs provides an in-memory mock implementation of Azure Notification Hubs.
Package notificationhubs provides an in-memory mock implementation of Azure Notification Hubs.
azure/servicebus
Package servicebus provides an in-memory mock implementation of Azure Service Bus.
Package servicebus provides an in-memory mock implementation of Azure Service Bus.
azure/virtualmachines
Package virtualmachines provides an in-memory mock implementation of Azure Virtual Machines.
Package virtualmachines provides an in-memory mock implementation of Azure Virtual Machines.
azure/vnet
Package vnet provides an in-memory mock implementation of Azure Virtual Network.
Package vnet provides an in-memory mock implementation of Azure Virtual Network.
gcp
Package gcp provides GCP mock provider factories.
Package gcp provides GCP mock provider factories.
gcp/artifactregistry
Package artifactregistry provides an in-memory mock implementation of GCP Artifact Registry.
Package artifactregistry provides an in-memory mock implementation of GCP Artifact Registry.
gcp/clouddns
Package clouddns provides an in-memory mock implementation of GCP Cloud DNS.
Package clouddns provides an in-memory mock implementation of GCP Cloud DNS.
gcp/cloudfunctions
Package cloudfunctions provides an in-memory mock implementation of Google Cloud Functions.
Package cloudfunctions provides an in-memory mock implementation of Google Cloud Functions.
gcp/cloudlogging
Package cloudlogging provides an in-memory mock implementation of GCP Cloud Logging.
Package cloudlogging provides an in-memory mock implementation of GCP Cloud Logging.
gcp/cloudmonitoring
Package cloudmonitoring provides an in-memory mock implementation of GCP Cloud Monitoring.
Package cloudmonitoring provides an in-memory mock implementation of GCP Cloud Monitoring.
gcp/eventarc
Package eventarc provides an in-memory mock implementation of GCP Eventarc.
Package eventarc provides an in-memory mock implementation of GCP Eventarc.
gcp/fcm
Package fcm provides an in-memory mock implementation of GCP Firebase Cloud Messaging.
Package fcm provides an in-memory mock implementation of GCP Firebase Cloud Messaging.
gcp/firestore
Package firestore provides an in-memory mock implementation of Google Cloud Firestore.
Package firestore provides an in-memory mock implementation of Google Cloud Firestore.
gcp/gce
Package gce provides an in-memory mock implementation of Google Compute Engine.
Package gce provides an in-memory mock implementation of Google Compute Engine.
gcp/gcpiam
Package gcpiam provides an in-memory mock implementation of GCP IAM.
Package gcpiam provides an in-memory mock implementation of GCP IAM.
gcp/gcplb
Package gcplb provides an in-memory mock implementation of GCP Cloud Load Balancing.
Package gcplb provides an in-memory mock implementation of GCP Cloud Load Balancing.
gcp/gcpvpc
Package gcpvpc provides an in-memory mock implementation of Google Cloud VPC networking.
Package gcpvpc provides an in-memory mock implementation of Google Cloud VPC networking.
gcp/gcs
Package gcs provides an in-memory mock implementation of Google Cloud Storage.
Package gcs provides an in-memory mock implementation of Google Cloud Storage.
gcp/memorystore
Package memorystore provides an in-memory mock implementation of GCP Memorystore.
Package memorystore provides an in-memory mock implementation of GCP Memorystore.
gcp/pubsub
Package pubsub provides an in-memory mock implementation of GCP Pub/Sub.
Package pubsub provides an in-memory mock implementation of GCP Pub/Sub.
gcp/secretmanager
Package secretmanager provides an in-memory mock implementation of GCP Secret Manager.
Package secretmanager provides an in-memory mock implementation of GCP Secret Manager.
Package ratelimit provides token bucket rate limiting for cloudemu services.
Package ratelimit provides token bucket rate limiting for cloudemu services.
Package recorder provides call recording (VCR pattern) for cloudemu services.
Package recorder provides call recording (VCR pattern) for cloudemu services.
Package secrets provides a portable secret management API with cross-cutting concerns.
Package secrets provides a portable secret management API with cross-cutting concerns.
driver
Package driver defines the interface for secret management service implementations.
Package driver defines the interface for secret management service implementations.
Package serverless provides a portable serverless functions API with cross-cutting concerns.
Package serverless provides a portable serverless functions API with cross-cutting concerns.
driver
Package driver defines the interface for serverless function service implementations.
Package driver defines the interface for serverless function service implementations.
Package statemachine provides a generic finite state machine with callbacks.
Package statemachine provides a generic finite state machine with callbacks.
Package storage provides a portable storage bucket API with cross-cutting concerns.
Package storage provides a portable storage bucket API with cross-cutting concerns.
driver
Package driver defines the interface for storage service implementations.
Package driver defines the interface for storage service implementations.
Package testhelper provides test suite helpers for cloudemu.
Package testhelper provides test suite helpers for cloudemu.

Jump to

Keyboard shortcuts

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