Debian Codegraph @

debian/go/src/golang.org/x/telemetry/internal/config/config_test.go

raw symbols SCIP
1 // Copyright 2023 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 config
6
7 import (
8 _ "embed"
9 "encoding/json"
10 "os"
11 "path/filepath"
12 "testing"
13
14 "golang.org/x/telemetry/internal/telemetry"
15 )
16
17 func TestConfig(t *testing.T) {
18 f, err := os.Open(filepath.FromSlash("../../config/config.json"))
19 if os.IsNotExist(err) {
20 t.Skip("config file not found")
21 }
22 if err != nil {
23 t.Fatal(err)
24 }
25 defer f.Close()
26 var cfg telemetry.UploadConfig
27 d := json.NewDecoder(f)
28 d.DisallowUnknownFields()
29 if err := d.Decode(&cfg); err != nil {
30 t.Fatal(err)
31 }
32 }
33
34 func TestInternalConfig(t *testing.T) {
35 got, err := ReadConfig("testdata/config.json")
36 if err != nil {
37 t.Fatal(err)
38 }
39 wantGOOS := []string{"linux", "darwin"}
40 wantGOARCH := []string{"amd64", "arm64"}
41 wantGoVersion := []string{"go1.20", "go1.20.1"}
42 wantPrograms := []string{"golang.org/x/tools/gopls", "cmd/go"}
43 wantVersions := [][2]string{
44 {"golang.org/x/tools/gopls", "v0.10.1"},
45 {"golang.org/x/tools/gopls", "v0.11.0"},
46 }
47 wantCounters := [][2]string{
48 {"golang.org/x/tools/gopls", "editor:emacs"},
49 {"golang.org/x/tools/gopls", "editor:vim"},
50 {"golang.org/x/tools/gopls", "editor:vscode"},
51 {"golang.org/x/tools/gopls", "editor:other"},
52 {"cmd/go", "go/buildcache/miss:0"},
53 {"cmd/go", "go/buildcache/miss:1"},
54 {"cmd/go", "go/buildcache/miss:10"},
55 {"cmd/go", "go/buildcache/miss:100"},
56 }
57 wantPrefix := [][2]string{
58 {"golang.org/x/tools/gopls", "editor"},
59 {"cmd/go", "go/buildcache/miss"},
60 }
61
62 for _, w := range wantGOOS {
63 if !got.HasGOOS(w) {
64 t.Errorf("got.HasGOOS(%s) = false: want true", w)
65 }
66 }
67 for _, w := range wantGOARCH {
68 if !got.HasGOARCH(w) {
69 t.Errorf("got.HasGOARCH(%s) = false: want true", w)
70 }
71 }
72 for _, w := range wantGoVersion {
73 if !got.HasGoVersion(w) {
74 t.Errorf("got.HasGoVersion(%s) = false: want true", w)
75 }
76 }
77 for _, w := range wantPrograms {
78 if !got.HasProgram(w) {
79 t.Errorf("got.HasProgram(%s) = false: want true", w)
80 }
81 }
82 for _, w := range wantVersions {
83 if !got.HasVersion(w[0], w[1]) {
84 t.Errorf("got.HasVersion(%s, %s) = false: want true", w[0], w)
85 }
86 }
87 for _, w := range wantCounters {
88 if !got.HasCounter(w[0], w[1]) {
89 t.Errorf("got.HasCounter(%s, %s) = false: want true", w[0], w[1])
90 }
91 }
92 for _, w := range wantPrefix {
93 if !got.HasCounterPrefix(w[0], w[1]) {
94 t.Errorf("got.HasCounterPrefix(%s, %s) = false: want true", w[0], w[1])
95 }
96 }
97 }