| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 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 |
|
| 33 |
} |
| 34 |
|
| 35 |
func TestPrintVersionInfoPlainText(t *testing.T) { |
| 36 |
buf := new(bytes.Buffer) |
| 37 |
WriteVersionInfo(buf, true, PlainText) |
| 38 |
res := buf.Bytes() |
| 39 |
|
| 40 |
|
| 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 |
} |