Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/supervisor/pkg/config/gitpod-config_analytics_test.go
2500 views
1
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package config
6
7
import (
8
"testing"
9
"time"
10
11
"github.com/google/go-cmp/cmp"
12
13
"github.com/gitpod-io/gitpod/common-go/log"
14
gitpod "github.com/gitpod-io/gitpod/gitpod-protocol"
15
)
16
17
func TestAnalyzeGitpodConfig(t *testing.T) {
18
tests := []struct {
19
Desc string
20
Prev *gitpod.GitpodConfig
21
Current *gitpod.GitpodConfig
22
Fields []string
23
}{
24
{
25
Desc: "change",
26
Prev: &gitpod.GitpodConfig{
27
CheckoutLocation: "foo",
28
},
29
Current: &gitpod.GitpodConfig{
30
CheckoutLocation: "bar",
31
},
32
Fields: []string{"CheckoutLocation"},
33
},
34
{
35
Desc: "add",
36
Prev: &gitpod.GitpodConfig{},
37
Current: &gitpod.GitpodConfig{
38
CheckoutLocation: "bar",
39
},
40
Fields: []string{"CheckoutLocation"},
41
},
42
{
43
Desc: "remove",
44
Prev: &gitpod.GitpodConfig{
45
CheckoutLocation: "bar",
46
},
47
Current: &gitpod.GitpodConfig{},
48
Fields: []string{"CheckoutLocation"},
49
},
50
{
51
Desc: "none",
52
Prev: &gitpod.GitpodConfig{
53
CheckoutLocation: "bar",
54
},
55
Current: &gitpod.GitpodConfig{
56
CheckoutLocation: "bar",
57
},
58
Fields: nil,
59
},
60
{
61
Desc: "fie created",
62
Current: &gitpod.GitpodConfig{},
63
Fields: nil,
64
},
65
}
66
for _, test := range tests {
67
t.Run(test.Desc, func(t *testing.T) {
68
var fields []string
69
analyzer := NewConfigAnalyzer(log.Log, 100*time.Millisecond, func(field string) {
70
fields = append(fields, field)
71
}, test.Prev)
72
<-analyzer.Analyse(test.Current)
73
if diff := cmp.Diff(test.Fields, fields); diff != "" {
74
t.Errorf("unexpected output (-want +got):\n%s", diff)
75
}
76
})
77
}
78
}
79
80