1
0
mirror of https://github.com/golang/go synced 2024-11-18 19:24:39 -07:00
go/internal/lsp/debug/serve_test.go
Rob Findley e02f5847d1 internal/lsp/debug: move all debug state onto the Instance
For testability, and to support the exchange of debug information across
Forwarder and server, it is helpful to encapsulate all debug information
on the instance object.

This CL moves all state in the debug package into a new 'State' type,
that is added as a field on the debug.Instance. While doing so, common
functionality for object collections is factored out into the objset
helper type.

Also add two new debug object types: Client and Server. These aren't yet
used, but will be in a later CL (and frankly it was easier to leave them
in this CL than to more carefully rewrite history...).

Updates golang/go#34111

Change-Id: Ib809cd14cb957b41a9bcbd94a991f804531a76ea
Reviewed-on: https://go-review.googlesource.com/c/tools/+/220078
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-02-24 22:50:47 +00:00

55 lines
1.2 KiB
Go

// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package debug
import "testing"
type fakeCache struct {
Cache
id string
}
func (c fakeCache) ID() string {
return c.id
}
func TestState(t *testing.T) {
c1 := fakeCache{id: "1"}
c2 := fakeCache{id: "2"}
c3 := fakeCache{id: "3"}
var s State
s.AddCache(c1)
s.AddCache(c2)
s.AddCache(c3)
compareCaches := func(desc string, want []fakeCache) {
t.Run(desc, func(t *testing.T) {
caches := s.Caches()
if gotLen, wantLen := len(caches), len(want); gotLen != wantLen {
t.Fatalf("len(Caches) = %d, want %d", gotLen, wantLen)
}
for i, got := range caches {
if got != want[i] {
t.Errorf("Caches[%d] = %v, want %v", i, got, want[i])
}
}
})
}
compareCaches("initial load", []fakeCache{c1, c2, c3})
s.DropCache(c2)
compareCaches("dropped cache 2", []fakeCache{c1, c3})
s.DropCache(c2)
compareCaches("duplicate drop", []fakeCache{c1, c3})
s.AddCache(c2)
compareCaches("re-add cache 2", []fakeCache{c1, c3, c2})
s.DropCache(c1)
s.DropCache(c2)
s.DropCache(c3)
compareCaches("drop all", []fakeCache{})
}