func TestTimeToLiveHTTP(t *testing.T) { be, tmpPath := backend.NewTmpBackend(time.Hour, 10000) defer os.Remove(tmpPath) defer be.Close() le := lease.NewLessor(be, int64(5)) le.Promote(time.Second) l, err := le.Grant(1, int64(5)) if err != nil { t.Fatalf("failed to create lease: %v", err) } ts := httptest.NewServer(NewHandler(le)) defer ts.Close() resp, err := TimeToLiveHTTP(context.TODO(), l.ID, true, ts.URL+LeaseInternalPrefix, http.DefaultTransport) if err != nil { t.Fatal(err) } if resp.LeaseTimeToLiveResponse.ID != 1 { t.Fatalf("lease id expected 1, got %d", resp.LeaseTimeToLiveResponse.ID) } if resp.LeaseTimeToLiveResponse.GrantedTTL != 5 { t.Fatalf("granted TTL expected 5, got %d", resp.LeaseTimeToLiveResponse.GrantedTTL) } }
func TestRenewHTTP(t *testing.T) { be, tmpPath := backend.NewTmpBackend(time.Hour, 10000) defer os.Remove(tmpPath) defer be.Close() le := lease.NewLessor(be, int64(5)) le.Promote(time.Second) l, err := le.Grant(1, int64(5)) if err != nil { t.Fatalf("failed to create lease: %v", err) } ts := httptest.NewServer(NewHandler(le)) defer ts.Close() ttl, err := RenewHTTP(l.ID, ts.URL+LeasePrefix, http.DefaultTransport, time.Second) if err != nil { t.Fatal(err) } if ttl != 5 { t.Fatalf("ttl expected 5, got %d", ttl) } }