diff --git a/Makefile b/Makefile index d4f867c..4fa2383 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,7 @@ FUNC_NAME=fetch ENTRY_POINT=Fetch TOPIC_NAME=$(FUNC_NAME)-topic BUCKET_NAME=$(PROJECT_ID)-fetch +TEST_BUCKET_NAME=$(PROJECT_ID)-fetch-test start: export FUNCTION_TARGET=$(ENTRY_POINT) && \ @@ -19,6 +20,10 @@ init: --role=roles/iam.serviceAccountTokenCreator gcloud pubsub topics create $(TOPIC_NAME) gsutil mb -c regional -l $(REGION) gs://$(BUCKET_NAME) + gsutil mb -c regional -l $(REGION) gs://$(TEST_BUCKET_NAME) + +test: + export BUCKET_NAME=$(TEST_BUCKET_NAME) && go test -v deploy: gcloud beta functions deploy $(FUNC_NAME) \ diff --git a/fetch.go b/fetch.go index 4ea3d64..9bb75af 100644 --- a/fetch.go +++ b/fetch.go @@ -34,7 +34,6 @@ func init() { func Run(ctx context.Context, event event.Event) error { defer zl.Sync() // Flush log file buffer. for debug in mac local. - // objectName := "test" bucket := getEnv() url := parseEvent(event) gcsPath := parseURL(url) @@ -47,6 +46,7 @@ func Run(ctx context.Context, event event.Event) error { zl.Info("RUN_GCF_FETCH", zap.String("url", url), zap.String("bucket", bucket), + zap.String("object", gcsPath), ) return nil } @@ -83,7 +83,7 @@ func parseURL(s string) string { if err != nil { zl.Error("URL_PARSE_ERROR", err) } - return url.Host + "/" + url.Path + return url.Host + url.Path } func parseEvent(event event.Event) (url string) { diff --git a/fetch_test.go b/fetch_test.go index d14697e..05e735d 100644 --- a/fetch_test.go +++ b/fetch_test.go @@ -2,7 +2,6 @@ package fetch_test import ( "context" - "os" "testing" "cloud.google.com/go/pubsub" @@ -31,7 +30,6 @@ func NewTestFetch() *TestFetch { } func (f *TestFetch) setup(t *testing.T) { - os.Setenv("BUCKET_NAME", "gcf-fetch-test") msg := fetch.MessagePublishedData{ Message: pubsub.Message{ Attributes: map[string]string{