Debian Codegraph @

gopls/internal/debug/info_test.go

raw symbols SCIP
1 // Copyright 2022 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // Package debug exports debug information for gopls.
6 package debug
7
8 import (
9 "bytes"
10 "encoding/json"
11 "runtime"
12 "testing"
13
14 "golang.org/x/tools/gopls/internal/version"
15 )
16
17 func TestPrintVersionInfoJSON(t *testing.T) {
18 buf := new(bytes.Buffer)
19 WriteVersionInfo(buf, true, JSON)
20 res := buf.Bytes()
21
22 var got ServerVersion
23 if err := json.Unmarshal(res, &got); err != nil {
24 t.Fatalf("unexpected output: %v\n%s", err, res)
25 }
26 if g, w := got.GoVersion, runtime.Version(); g != w {
27 t.Errorf("go version = %v, want %v", g, w)
28 }
29 if g, w := got.Version, version.Version(); g != w {
30 t.Errorf("gopls version = %v, want %v", g, w)
31 }
32 // Other fields of BuildInfo may not be available during test.
33 }
34
35 func TestPrintVersionInfoPlainText(t *testing.T) {
36 buf := new(bytes.Buffer)
37 WriteVersionInfo(buf, true, PlainText)
38 res := buf.Bytes()
39
40 // Other fields of BuildInfo may not be available during test.
41 wantGoplsVersion, wantGoVersion := version.Version(), runtime.Version()
42 if !bytes.Contains(res, []byte(wantGoplsVersion)) || !bytes.Contains(res, []byte(wantGoVersion)) {
43 t.Errorf("plaintext output = %q,\nwant (version: %v, go: %v)", res, wantGoplsVersion, wantGoVersion)
44 }
45 }