golang.org/x/tools/gopls@v0.15.3/internal/test/integration/env_test.go (about) 1 // Copyright 2020 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 integration 6 7 import ( 8 "context" 9 "encoding/json" 10 "testing" 11 12 "golang.org/x/tools/gopls/internal/protocol" 13 ) 14 15 func TestProgressUpdating(t *testing.T) { 16 a := &Awaiter{ 17 state: State{ 18 work: make(map[protocol.ProgressToken]*workProgress), 19 }, 20 } 21 ctx := context.Background() 22 if err := a.onWorkDoneProgressCreate(ctx, &protocol.WorkDoneProgressCreateParams{ 23 Token: "foo", 24 }); err != nil { 25 t.Fatal(err) 26 } 27 if err := a.onWorkDoneProgressCreate(ctx, &protocol.WorkDoneProgressCreateParams{ 28 Token: "bar", 29 }); err != nil { 30 t.Fatal(err) 31 } 32 updates := []struct { 33 token string 34 value interface{} 35 }{ 36 {"foo", protocol.WorkDoneProgressBegin{Kind: "begin", Title: "foo work"}}, 37 {"bar", protocol.WorkDoneProgressBegin{Kind: "begin", Title: "bar work"}}, 38 {"foo", protocol.WorkDoneProgressEnd{Kind: "end"}}, 39 {"bar", protocol.WorkDoneProgressReport{Kind: "report", Percentage: 42}}, 40 } 41 for _, update := range updates { 42 params := &protocol.ProgressParams{ 43 Token: update.token, 44 Value: update.value, 45 } 46 data, err := json.Marshal(params) 47 if err != nil { 48 t.Fatal(err) 49 } 50 var unmarshaled protocol.ProgressParams 51 if err := json.Unmarshal(data, &unmarshaled); err != nil { 52 t.Fatal(err) 53 } 54 if err := a.onProgress(ctx, &unmarshaled); err != nil { 55 t.Fatal(err) 56 } 57 } 58 if !a.state.work["foo"].complete { 59 t.Error("work entry \"foo\" is incomplete, want complete") 60 } 61 got := *a.state.work["bar"] 62 want := workProgress{title: "bar work", percent: 42} 63 if got != want { 64 t.Errorf("work progress for \"bar\": %v, want %v", got, want) 65 } 66 }