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