You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: integration_test.go
    path of file: ./repos/event-gateway/tests
    
    the code of the file until where you have to start completion: // +build integration

package tests

import (
	"bytes"
	"encoding/base64"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
	"net/http/httptest"
	"os"
	"strconv"
	"sync/atomic"
	"testing"
	"time"

	"go.uber.org/zap"

	"github.com/julienschmidt/httprouter"
	"github.com/serverless/event-gateway/event"
	"github.com/serverless/event-gateway/function"
	"github.com/serverless/event-gateway/httpapi"
	"github.com/serverless/event-gateway/internal/cache"
	"github.com/serverless/event-gateway/internal/embedded"
	intstore "github.com/serverless/event-gateway/internal/store"
	"github.com/serverless/event-gateway/internal/sync"
	eventgateway "github.com/serverless/event-gateway/libkv"
	"github.com/serverless/event-gateway/plugin"
	httpprovider "github.com/serverless/event-gateway/providers/http"
	"github.com/serverless/event-gateway/router"
	"github.com/serverless/event-gateway/subscription"
	"github.com/serverless/libkv"
	"github.com/serverless/libkv/store"
	etcd "github.com/serverless/libkv/store/etcd/v3"
	"github.com/stretchr/testify/assert"
)

func TestMain(t *testing.T) {
	etcd.Register()
}

func TestIntegration_AsyncSubscription(t *testing.T) {
	logCfg := zap.NewDevelopmentConfig()
	logCfg.DisableStacktrace = true
	log, _ := logCfg.Build()
	kv, shutdownGuard := newTestEtcd()

	testAPIServer := newConfig
    
func TestIntegration_AsyncSubscription(t *testing.T) {
	logCfg := zap.NewDevelopmentConfig()
	logCfg.DisableStacktrace = true
	log, _ := logCfg.Build()
	kv, shutdownGuard := newTestEtcd()

	testAPIServer := newConfigAPIServer(kv, log)
	defer testAPIServer.Close()
	instance, testRouterServer := newTestRouterServer(kv, log)
	defer testRouterServer.Close()
	instance.StartWorkers()

	expected := "ðŸ˜¸"
	eventType := "smileys"

	// register event type
	eventTypeName := event.TypeName(eventType)
	postEventType(testAPIServer.URL+"/v1/spaces/default/eventtypes", &event.Type{Name: eventTypeName})
	wait(instance.WaitForEventType("default", eventTypeName), "timed out waiting for event type to be configured!")

	// register subscriber function
	smileyReceived := make(chan struct{})
	testSubscriberServer := httptest.NewServer(http.HandlerFunc(
		func(w http.ResponseWriter, r *http.Request) {
			reqBuf, _ := ioutil.ReadAll(r.Body)

			var event event.Event
			err := json.Unmarshal(reqBuf, &event)
			if err != nil {
				panic(err)
			}
			decoded, _ := base64.StdEncoding.DecodeString(event.Data.(string))

			if string(decoded) == expected {
				close(smileyReceived)
			} else {
				log.Error("received non-smiley!", zap.String("value", fmt.Sprintf("%+v", reqBuf)))
			}
		}))
	defer testSubscriberServer.Close()

	subscriberFnID := function.ID("smileysubscriber")
	postFunction(testAPIServer.URL+"/v1/spaces/default/functions",
		&function.Function{
			ID:           subscriberFnID,
			ProviderType: httpprovider.Type,
			Provider: &httpprovider.HTTP{
				URL: testSubscriberServer.URL,
			},
		})
	wait(instance.WaitForFunction("default", subscriberFnID), "timed out waiting for function to be configured!")

	// set up pub/sub
	postSubscription(testAPIServer.URL+"/v1/spaces/default/subscriptions", &subscription.Subscription{
		FunctionID: subscriberFnID,
		Type:       subscription.TypeAsync,
		EventType:  event.TypeName(eventType),
		Path:       "/",
	})
	wait(instance.WaitForAsyncSubscriber(http.MethodPost, "/", event.TypeName(eventType)), "timed out waiting for subscriber to be configured!")

	// emit event
	emit(testRouterServer.URL, eventType, []byte(expected))
	wait(smileyReceived, "timed out waiting to receive pub/sub event in subscriber!")

	instance.Drain()
	shutdownGuard.ShutdownAndWait()
}