Skip to content

Commit

Permalink
✅ Add gcs bucket for test
Browse files Browse the repository at this point in the history
  • Loading branch information
nkmr-jp committed May 9, 2022
1 parent e775655 commit b3b8d14
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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) && \
Expand All @@ -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) \
Expand Down
4 changes: 2 additions & 2 deletions fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package fetch_test

import (
"context"
"os"
"testing"

"cloud.google.com/go/pubsub"
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit b3b8d14

Please sign in to comment.