BeiBaiNian opened a new pull request, #197:
URL: https://github.com/apache/casbin-gateway/pull/197

   # Why
   
   The tests under `object/` hardcode data of the original developer's account 
(`owner = "admin"`, e.g. sites `caswaf_my` / `test-site` and certs `casbin.com` 
/ `admin/cert`). This data does not exist on any fresh database, so `go test 
./object/...` always fails with a nil pointer panic. The tests are also 
excluded from CI (the `!skipCi` build tag plus the commented-out test step in 
`build.yml`), so the failure is invisible there, but every local run still 
breaks.
   
   # What changed
   
   - Added `object/main_test.go` with `TestMain` and fixtures: sites/certs are 
created under a dedicated owner `caswaf-test` and are automatically deleted 
when a test finishes (whether it passes, fails or panics). Existing data with 
the same id is never touched (the test skips instead).
   - Reworked `TestGetCertExpireTime` into a real test: it generates a 
self-signed certificate at runtime (no hardcoded PEM), asserts the parsed 
expire time and cleans up the fixture cert.
   - Renamed `TestCheckNode` to `TestUpdateSiteStatus` and `TestCheckCerts` to 
`TestCheckCertsNoOpForEmptyNodes`, with comments explaining what they actually 
cover (the no-node early-return path; the node health-check and cert renewal 
logic that has external side effects is intentionally not exercised).
   - Removed `TestApplyAllCerts` (it wrote certificates to a machine-specific 
`F:/` nginx directory).
   - Converted the remaining manual operations (`TestRenewCert`, 
`TestRenewAllCerts`, `TestUpdateDomainExpireTime`), which renew real 
certificates via external providers or perform real WHOIS lookups, to explicit 
`t.Skip` entries that can still be run manually.
   - Replaced all `panic()` calls in the tests with `t.Fatalf()`.
   
   # Verification
   
   Local run on Windows (Go 1.20.14, MySQL):
   
   `go test ./object/... -count=1 -v`
   
   ```
   --- PASS: TestGetCertExpireTime (0.01s)
   --- SKIP: TestRenewCert (0.00s)
   --- SKIP: TestRenewAllCerts (0.00s)
   --- PASS: TestCheckCertsNoOpForEmptyNodes (0.07s)
   --- SKIP: TestUpdateDomainExpireTime (0.00s)
   --- PASS: TestUpdateSiteStatus (0.09s)
   PASS
   ok   github.com/apache/casbin-gateway/object 2.328s
   ```
   
   After the run, no fixture data remains in the database:
   
   ```sql
   SELECT COUNT(*) FROM site WHERE owner='caswaf-test';  -- 0
   SELECT COUNT(*) FROM cert WHERE owner='caswaf-test';  -- 0
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to