-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Test] Add test for get content size endpoint (#71)
* chore: add return to getSizeHandler * test: add func for mocking json post requests * test: add test setup * chore(test): change package name to main_test * refactor: move tests to ui dir * chore: remove baseUrl to config * test: api/cdn/size endpoint * fix: set LoadEnvVariables to prod mode
- Loading branch information
1 parent
e48c796
commit 685da91
Showing
8 changed files
with
78 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package main_test | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/kevinanielsen/go-fast-cdn/database" | ||
ini "github.com/kevinanielsen/go-fast-cdn/initializers" | ||
"github.com/kevinanielsen/go-fast-cdn/util" | ||
) | ||
|
||
func setup() { | ||
util.LoadExPath() | ||
gin.SetMode(gin.TestMode) | ||
ini.LoadEnvVariables(true) | ||
ini.CreateFolders() | ||
database.ConnectToDB() | ||
} | ||
|
||
func TestMain(m *testing.M) { | ||
setup() | ||
code := m.Run() | ||
os.Exit(code) | ||
} |
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,24 @@ | ||
package testutils | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"io" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func MockJsonPost(c *gin.Context, content interface{}) { | ||
c.Request.Method = "POST" // or PUT | ||
c.Request.Header.Set("Content-Type", "application/json") | ||
|
||
jsonbytes, err := json.Marshal(content) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// the request body must be an io.ReadCloser | ||
// the bytes buffer though doesn't implement io.Closer, | ||
// so you wrap it in a no-op closer | ||
c.Request.Body = io.NopCloser(bytes.NewBuffer(jsonbytes)) | ||
} |
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,20 @@ | ||
import { test, expect } from "@playwright/test"; | ||
|
||
/** | ||
* Tests that the /api/cdn/size endpoint returns a 200 OK status. | ||
* Verifies the status code is 200 and the response is ok. | ||
*/ | ||
test("should return OK", async ({ request }) => { | ||
const response = await request.get("/api/cdn/size"); | ||
expect(response.status()).toBe(200); | ||
expect(response.ok()).toBe(true); | ||
}); | ||
|
||
/** | ||
* Test that ensures the /api/cdn/size endpoint returns a response with cdn_size_bytes > 0. | ||
* This validates that the CDN size API is returning a valid non-zero byte count. | ||
*/ | ||
test("should be > 0 bytes", async ({ request }) => { | ||
const response = await request.get("/api/cdn/size"); | ||
expect((await response.json()).cdn_size_bytes).toBeGreaterThan(0); | ||
}); |
This file was deleted.
Oops, something went wrong.
3 changes: 1 addition & 2 deletions
3
ui/tests/content-size.spec.ts → ui/tests/ui/content-size.spec.ts
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