Skip to content

Commit

Permalink
welcome to github
Browse files Browse the repository at this point in the history
  • Loading branch information
arhea committed Dec 2, 2023
0 parents commit 0f3b1e7
Show file tree
Hide file tree
Showing 18 changed files with 1,036 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
; https://editorconfig.org/

root = true

[*]
insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true
indent_style = space
indent_size = 2

[{Makefile,go.mod,go.sum,*.go,.gitmodules}]
indent_style = tab
indent_size = 4

[*.md]
indent_size = 4
trim_trailing_whitespace = false

eclint_indent_style = unset

[Dockerfile]
indent_size = 4
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @arhea
13 changes: 13 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# These are supported funding model platforms

github: [arhea]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: "gomod"
target-branch: "main"
directory: "/"
schedule:
interval: "weekly"
25 changes: 25 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Quality

on: push

jobs:
check:
name: Quality / Check
runs-on: ubuntu-latest

permissions:
contents: "read"
id-token: "write"

steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v4
with:
check-latest: true
go-version: stable

- uses: golangci/golangci-lint-action@v3

- run: make ci
shell: bash
31 changes: 31 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
.DS_Store

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work

# Log files
*.log

# Temporary files
/tmp

# Configuration files
*.env
32 changes: 32 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Refer to golangci-lint's example config file for more options and information:
# https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml

run:
timeout: 5m
modules-download-mode: readonly

linters:
disable-all: true
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- unused
- bodyclose
- revive
- gosec
- exportloopref
- misspell

linters-settings:
revive:
rules:
- name: unused-parameter
disabled: true

issues:
exclude-use-default: false
max-issues-per-linter: 0
max-same-issues: 0
80 changes: 80 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"editor.formatOnSave": false,
"editor.formatOnPaste": false,
"editor.formatOnType": false,
"editor.codeActionsOnSave": [ ],
"editor.rulers": [ 120 ],

// markdown formatting options
"[markdown]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
// json formatting options
"[json]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "vscode.json-language-features"
},
"[jsonc]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "vscode.json-language-features"
},
// yaml formatting options
"[yaml]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "redhat.vscode-yaml"
},
// we want to support make files as well
"[makefile]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "ms-vscode.makefile-tools"
},
// go specific settings
"[go]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "golang.go",
"editor.codeActionsOnSave": {
"source.organizeImports": true,
"source.fixAll": true
}
},
// make sure the go language server is enabled
"go.useLanguageServer": true,
// configure gopls, the go language server
"gopls": {
"ui.semanticTokens": true,
"ui.completion.usePlaceholders": true
},
// configure the go formatting tool to be goimports
"go.formatTool": "goimports",
"go.formatFlags": [ "-local", "github.com/arhea/" ],

// change the linting tool to be golangci
"go.lintTool": "golangci-lint",
"go.lintOnSave": "workspace",
"go.lintFlags": [ "--fast" ],
// configure the tags we want to add by default
"go.addTags": {
"tags": "json,validate",
"options": "json=omitempty,validate=omitempty",
"promptForTags": false,
"transform": "snakecase",
"template": ""
},
// dont run code coverage on save
"go.coverOnSave": false,
"go.coverOnSingleTest": true,
"go.coverOnTestPackage": true,
"go.coverShowCounts": false,
"go.coverageDecorator": {
"type": "gutter",
"coveredHighlightColor": "rgba(64,128,128,0.5)",
"uncoveredHighlightColor": "rgba(128,64,64,0.25)",
"coveredGutterStyle": "blockgreen",
"uncoveredGutterStyle": "blockred"
},
// configure some helpful test environment variables
"go.testEnvVars": {
"WORKSPACE_DIR": "${workspaceFolder}"
}
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Alex Rhea

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# process run during github actions
ci: install test

# install dependencies
install:
go get .

# install and upgrade dependencies
deps: install
go mod tidy
go get -u ./...

# run lint using golangci-linters
lint:
golangci-lint run

# run tests
test:
go test -cover ./...
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Mock Google Cloud Spanner

Provides a mock of [Google Cloud Spanner](https://cloud.google.com/spanner?hl=en) using the official [Google Cloud Spanner Emulator](https://github.com/GoogleCloudPlatform/cloud-spanner-emulator).

These mocks will automatically create a new emulator, wait for it to be available, then create a mock database. You will need to run your database migrations prior to performing your tests.

I recommend reusing the instance across multiple tests to reduce test run times.

This library is built on top of [testcontainers](https://testcontainers.com/).

## Usage

Creating a mock instance for creating a customer connection.

```golang
func TestXXX(t *testing.T) {
ctx := context.Background()

mock, err := mockspanner.NewInstance(ctx, t)

if err != nil {
t.Fatalf("creating the instance: %v", err)
return
}

// close the mock
defer mock.Close(ctx)

// ... my test code
}
```

Creating a mock Spanner client for interacting with Spanner via the Go client.

```golang
func TestXXX(t *testing.T) {
ctx := context.Background()

mock, err := mockspanner.NewClient(ctx, t)

if err != nil {
t.Fatalf("creating the client: %v", err)
return
}

// close the mock
defer mock.Close(ctx)

spannerClient := mock.Client()

t.Run("MyTest1", func(t *testing.T) {
// ... my test code
})

t.Run("MyTest2", func(t *testing.T) {
// ... my test code
})
}
```
Loading

0 comments on commit 0f3b1e7

Please sign in to comment.