gui: TestGitHubTokenRefusedShown refuses a token of its own each run
ghtoken keeps the tokens GitHub answered 401 for as long as the process runs, keyed by the token. The test refused one constant token, so a second run in the same process (-count=2) found it refused before GitHub was asked: red every time. Each run now builds its own token, ending in 4567 so the mask it checks is the same. Run on mote at this head: - go test ./internal/gui -run ^TestGitHubTokenRefusedShown$ -count=2 on the old test: FAIL "refused before GitHub was asked", 2 of 2 tries. - go test ./internal/gui -run ^TestGitHubToken -count=5: ok. - gofmt -l: clean. Test-only; no other file changed.
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/ghtoken"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
@@ -75,7 +77,10 @@ func TestGitHubTokenRefusedShown(t *testing.T) {
|
||||
Handler(nil, nil).ServeHTTP(rec, httptest.NewRequest("GET", "/api/settings", nil))
|
||||
return rec.Body.String()
|
||||
}
|
||||
const tok = "ghp_refusedrefusedrefusedrefused4567"
|
||||
// ghtoken keeps the tokens GitHub refused for as long as the process
|
||||
// runs, so each run refuses a token of its own: with one constant a
|
||||
// second run (-count=2) found it refused before GitHub was asked.
|
||||
tok := fmt.Sprintf("ghp_refused%025d4567", time.Now().UnixNano())
|
||||
s := settings.Load()
|
||||
s.GitHubToken = tok
|
||||
if err := settings.Save(s); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user