MCPcopy
hub / github.com/kubernetes/client-go / TestCachedTokenSource

Function TestCachedTokenSource

plugin/pkg/client/auth/gcp/gcp_test.go:403–435  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

401}
402
403func TestCachedTokenSource(t *testing.T) {
404 tok := &oauth2.Token{AccessToken: "fakeaccesstoken"}
405 persister := &fakePersister{}
406 source := &fakeTokenSource{
407 token: tok,
408 err: nil,
409 }
410 cache := map[string]string{
411 "foo": "bar",
412 "baz": "bazinga",
413 }
414 ts, err := newCachedTokenSource("fakeaccesstoken", "", persister, source, cache)
415 if err != nil {
416 t.Fatal(err)
417 }
418 var wg sync.WaitGroup
419 wg.Add(10)
420 for i := 0; i < 10; i++ {
421 go func() {
422 _, err := ts.Token()
423 if err != nil {
424 t.Errorf("unexpected error: %s", err)
425 }
426 wg.Done()
427 }()
428 }
429 wg.Wait()
430 cache["access-token"] = "fakeaccesstoken"
431 cache["expiry"] = tok.Expiry.Format(time.RFC3339Nano)
432 if got := persister.read(); !reflect.DeepEqual(got, cache) {
433 t.Errorf("got cache %v, want %v", got, cache)
434 }
435}
436
437type MockTransport struct {
438 res *http.Response

Callers

nothing calls this directly

Calls 6

readMethod · 0.95
newCachedTokenSourceFunction · 0.85
AddMethod · 0.65
TokenMethod · 0.65
ErrorfMethod · 0.65
DoneMethod · 0.65

Tested by

no test coverage detected