-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[test] Add framework for running Firestore emulator for unit tests
- Loading branch information
Showing
13 changed files
with
429 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
#!/bin/sh | ||
cd functions && gcloud functions deploy challenge --runtime go113 --trigger-http --entry-point ChallengeHandler --allow-unauthenticated | ||
cd functions && gcloud functions deploy challenge --runtime go113 --trigger-http \ | ||
--entry-point ChallengeHTTPHandler --allow-unauthenticated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package functions | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"upload-token.functions/internal/pow" | ||
"upload-token.functions/internal/util" | ||
) | ||
|
||
func TestChallenge(t *testing.T) { | ||
firestore := util.NewTestFirestore(t) | ||
|
||
req, err := http.NewRequestWithContext(context.Background(), "GET", "/challenge", nil) | ||
assert.Nil(t, err) | ||
r := httptest.NewRecorder() | ||
ctx, err := util.NewTestContext(r, req, firestore) | ||
assert.Nil(t, err) | ||
|
||
ChallengeHandler(&ctx) | ||
|
||
// First, unmarshal using pow.Challenge in order to benefit from its | ||
// validation. | ||
var c0 pow.Challenge | ||
err = json.Unmarshal(r.Body.Bytes(), &c0) | ||
assert.Nil(t, err) | ||
|
||
// Second, unmarshal into a map so that we can inspect its contents. | ||
var c1 map[string]interface{} | ||
err = json.Unmarshal(r.Body.Bytes(), &c1) | ||
assert.Nil(t, err) | ||
assert.Equal(t, c1["work_factor"], float64(pow.DefaultWorkFactor)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.