Giter VIP home page Giter VIP logo

snapshot's Introduction

Snapshot

godev build status

Snapshot test for golang.

Store snapshot files under __snapshots__ folder relative to caller file.

  • json snapshot for any go object with type info
  • transform value as schema to compare type only
  • clean data by regexp before compare

Update snapshot

set SNAPSHOT_UPDATE env var to true to update existed snapshot file.

Usage

import (
    "time"

    "github.com/NateScarlet/snapshot/pkg/snapshot"
)

type Object struct {
    A string
    B int
    C bool
    D time.Time
}

func TestSomeThing(t *testing.T) {
    // Match as text
    snapshot.Match(t, "text")
    // snapshot:
    // text

    // Match as json
    snapshot.MatchJSON(t, Object{})
    // snapshot:
    // {
    //   "$Object": {
    //     "A": "",
    //     "B": 0,
    //     "C": false,
    //     "D": {
    //       "$Time": "0001-01-01 00:00:00 +0000 UTC"
    //     }
    //   }
    // }

    // Match schema as json
    snapshot.MatchJSON(t, Object{}, snapshot.OptionTransform(snapshot.TransformSchema))
    // snapshot:
    // {
    //   "$Object": {
    //     "A": "$string",
    //     "B": "$int",
    //     "C": "$bool",
    //     "D": "$Time"
    //   }
    // }

    // Clean dynamic data to make result deterministic
    snapshot.MatchJSON(t, 
        Object{
            A: "a",
            B: 1,
            C: true,
            D: time.Now(),
        }, 
        snapshot.OptionCleanRegex(
            snapshot.CleanAs("*time*"),
            `"D": {\s+"\$Time": "(.+)"\s+}`,
        ),
    )
    // snapshot:
    // {
    //   "$Object": {
    //     "A": "a",
    //     "B": 1,
    //     "C": true,
    //     "D": {
    //       "$Time": "*time*"
    //     }
    //   }
    // }
}

snapshot's People

Contributors

natescarlet avatar renovate-bot avatar renovate[bot] avatar

Watchers

James Cloos avatar  avatar

snapshot's Issues

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/go.yml
  • actions/setup-go v3
  • actions/checkout v1
gomod
go.mod
  • go 1.19
  • github.com/stretchr/testify v1.8.2

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.