Skip to content

Commit

Permalink
try using emulator
Browse files Browse the repository at this point in the history
  • Loading branch information
chiaryan committed Nov 4, 2024
1 parent 0a9a483 commit 44e2c54
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 5 deletions.
52 changes: 51 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,58 @@ jobs:
test-firebase:
runs-on: ubuntu-latest
steps:
- name: Deploy to Firebase
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up .env
env:
QUESTION_FIREBASE_CREDENTIAL_PATH: ${{ vars.QUESTION_SERVICE_FIREBASE_CREDENTIAL_PATH }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
run: |
cd ./apps/question-service
echo "FIREBASE_CREDENTIAL_PATH=$QUESTION_FIREBASE_CREDENTIAL_PATH" >> .env
echo "JWT_SECRET=$JWT_SECRET" >> .env
- name: Set up credentials
env:
QUESTION_FIREBASE_JSON: ${{ secrets.QUESTION_SERVICE_FIREBASE_CREDENTIAL }}
QUESTION_FIREBASE_CREDENTIAL_PATH: ${{ vars.QUESTION_SERVICE_FIREBASE_CREDENTIAL_PATH }}
run: |
cd ./apps/question-service
echo "$QUESTION_FIREBASE_JSON" > "./$QUESTION_FIREBASE_CREDENTIAL_PATH"
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.23.x'

- name: Install dependencies
run: |
cd ./apps/question-service
go mod tidy
- name: Run tests with emulator
uses: w9jds/firebase-action@master
with:
args: emulators:exec --only firestore --project demo-test-project 'cd ./apps/question-service; go test ./...'
env:
GCP_SA_KEY: dummy

frontend-unit-tests:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Setup .env
run: |
cd ./apps/frontend
cp .env.example .env
- name: Set up Node.js
uses: actions/setup-node@v2
with:
args: emulators:start --only firestore --project demo-test-project
env:
Expand Down
8 changes: 4 additions & 4 deletions apps/question-service/tests/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var client *firestore.Client
func TestMain(m *testing.M) {
// fmt.Printf("test")
// Set FIRESTORE_EMULATOR_HOST environment variable.
err := os.Setenv("FIRESTORE_EMULATOR_HOST", "localhost:8390")
err := os.Setenv("FIRESTORE_EMULATOR_HOST", "localhost:8080")
if err != nil {
// TODO: Handle error.
log.Fatalf("could not set env %v", err)
Expand Down Expand Up @@ -87,16 +87,16 @@ func setup(t *testing.T) string {
return docRef.ID
}
func Test_Read(t *testing.T) {
id = setup(t)
id := setup(t)

res := httptest.NewRecorder()

// adds chi context
// https://stackoverflow.com/questions/54580582/testing-chi-routes-w-path-variables
rctx := chi.NewRouteContext()
rctx.URLParams.Add("docRefID", "6SdbW4Awcfm5x0UQtWmg")
rctx.URLParams.Add("docRefID", id)

req := httptest.NewRequest(http.MethodGet, "http://localhost:8080/questions/6SdbW4Awcfm5x0UQtWmg", strings.NewReader(""))
req := httptest.NewRequest(http.MethodGet, "http://localhost:8080/questions/"+id, strings.NewReader(""))
req = req.WithContext(context.WithValue(req.Context(), chi.RouteCtxKey, rctx))

service.ReadQuestion(res, req)
Expand Down

0 comments on commit 44e2c54

Please sign in to comment.