Skip to content

Instantly share code, notes, and snippets.

View start.sh
export FIRESTORE_EMULATOR_HOST=localhost:8090 && go run .
View main.go
package main
import (
"context"
"log"
"os"
"cloud.google.com/go/firestore"
)
View go.mod
module main
go 1.16
require cloud.google.com/go/firestore v1.5.0
View test.sh
go test -v . | sed ''/PASS/s//$(printf "\033[32mPASS\033[0m")/'' | sed ''/FAIL/s//$(printf "\033[31mFAIL\033[0m")/''
View main_test.go
package main
import (
"bytes"
"encoding/json"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
View main_test.go
//.....
const sumMethodName = "Sum"
const multiplyMethodName = "Multiply"
type AppHandlerFake struct {
// method name -> call -> params
Calls map[string][][]interface{}
}
View app_handler.go
package main
type Result struct {
Value int `json:"value"`
}
type AppHandler interface {
Sum(x, y int) Result
Multiply(x, y int) Result
}
View main.go
package main
import (
"log"
"strconv"
"github.com/gofiber/fiber/v2"
)
// Request body payload of the 'POST /multiply' endpoint
View math_test.go
package main
import (
"testing"
)
func TestMultiply(t *testing.T) {
// Create the test table
tables := []struct {
View math.go
package main
func Multiply(x, y int) int {
return x * y
}