diff --git a/cmd/heartbeat/heartbeat_test.go b/cmd/heartbeat/heartbeat_test.go index 9e34a203..d6d09e63 100644 --- a/cmd/heartbeat/heartbeat_test.go +++ b/cmd/heartbeat/heartbeat_test.go @@ -10,11 +10,13 @@ import ( "path/filepath" "runtime" "strings" + "sync" "testing" "time" "github.com/wakatime/wakatime-cli/cmd" cmdheartbeat "github.com/wakatime/wakatime-cli/cmd/heartbeat" + cmdparams "github.com/wakatime/wakatime-cli/cmd/params" "github.com/wakatime/wakatime-cli/pkg/api" "github.com/wakatime/wakatime-cli/pkg/heartbeat" "github.com/wakatime/wakatime-cli/pkg/ini" @@ -290,6 +292,8 @@ func TestSendHeartbeats_ExtraHeartbeats(t *testing.T) { os.Stdin = r + cmdparams.Once = sync.Once{} + data, err := os.ReadFile("testdata/extra_heartbeats.json") require.NoError(t, err) @@ -372,6 +376,8 @@ func TestSendHeartbeats_ExtraHeartbeats_Sanitize(t *testing.T) { os.Stdin = r + cmdparams.Once = sync.Once{} + data, err := os.ReadFile("testdata/extra_heartbeats.json") require.NoError(t, err) @@ -580,6 +586,8 @@ func TestSendHeartbeats_IsUnsavedEntity(t *testing.T) { os.Stdin = inr + cmdparams.Once = sync.Once{} + data, err := os.ReadFile("testdata/extra_heartbeats_is_unsaved_entity.json") require.NoError(t, err) @@ -710,6 +718,8 @@ func TestSendHeartbeats_NonExistingExtraHeartbeatsEntity(t *testing.T) { os.Stdin = inr + cmdparams.Once = sync.Once{} + data, err := os.ReadFile("testdata/extra_heartbeats_nonexisting_entity.json") require.NoError(t, err) diff --git a/cmd/params/params.go b/cmd/params/params.go index 21147c4c..72a63ae2 100644 --- a/cmd/params/params.go +++ b/cmd/params/params.go @@ -751,10 +751,12 @@ func readAPIKeyFromCommand(cmdStr string) (string, error) { } var extraHeartbeatsCache *[]heartbeat.Heartbeat // nolint:gochecknoglobals -var once sync.Once // nolint:gochecknoglobals + +// Once prevents reading from stdin twice. +var Once sync.Once // nolint:gochecknoglobals func readExtraHeartbeats() []heartbeat.Heartbeat { - once.Do(func() { + Once.Do(func() { in := bufio.NewReader(os.Stdin) input, err := in.ReadString('\n') diff --git a/cmd/params/params_test.go b/cmd/params/params_test.go index cda37cee..4738f53f 100644 --- a/cmd/params/params_test.go +++ b/cmd/params/params_test.go @@ -9,10 +9,11 @@ import ( "regexp" "runtime" "strings" + "sync" "testing" "time" - paramscmd "github.com/wakatime/wakatime-cli/cmd/params" + cmdparams "github.com/wakatime/wakatime-cli/cmd/params" "github.com/wakatime/wakatime-cli/pkg/api" "github.com/wakatime/wakatime-cli/pkg/apikey" "github.com/wakatime/wakatime-cli/pkg/heartbeat" @@ -33,7 +34,7 @@ func TestLoadHeartbeatParams_AlternateProject(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("alternate-project", "web") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.Equal(t, "web", params.Project.Alternate) @@ -43,7 +44,7 @@ func TestLoadHeartbeatParams_AlternateProject_Unset(t *testing.T) { v := viper.New() v.Set("entity", "/path/to/file") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.Empty(t, params.Project.Alternate) @@ -77,7 +78,7 @@ func TestLoadHeartbeatParams_Category(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("category", name) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.Equal(t, category, params.Category) @@ -89,7 +90,7 @@ func TestLoadHeartbeatParams_Category_Default(t *testing.T) { v := viper.New() v.Set("entity", "/path/to/file") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.Equal(t, heartbeat.CodingCategory, params.Category) @@ -100,7 +101,7 @@ func TestLoadHeartbeatParams_Category_Invalid(t *testing.T) { v.SetDefault("sync-offline-activity", 1000) v.Set("category", "invalid") - _, err := paramscmd.LoadHeartbeatParams(v) + _, err := cmdparams.LoadHeartbeatParams(v) require.Error(t, err) assert.Equal(t, "failed to parse category: invalid category \"invalid\"", err.Error()) @@ -111,7 +112,7 @@ func TestLoadHeartbeatParams_CursorPosition(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("cursorpos", 42) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.Equal(t, 42, *params.CursorPosition) @@ -122,7 +123,7 @@ func TestLoadHeartbeatParams_CursorPosition_Zero(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("cursorpos", 0) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.Zero(t, *params.CursorPosition) @@ -133,7 +134,7 @@ func TestLoadHeartbeatParams_CursorPosition_Unset(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("key", "00000000-0000-4000-8000-000000000000") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.Nil(t, params.CursorPosition) @@ -144,7 +145,7 @@ func TestLoadHeartbeatParams_Entity_EntityFlagTakesPrecedence(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("file", "ignored") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.Equal(t, "/path/to/file", params.Entity) @@ -157,7 +158,7 @@ func TestLoadHeartbeatParams_Entity_FileFlag(t *testing.T) { home, err := os.UserHomeDir() require.NoError(t, err) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.Equal(t, filepath.Join(home, "/path/to/file"), params.Entity) @@ -166,7 +167,7 @@ func TestLoadHeartbeatParams_Entity_FileFlag(t *testing.T) { func TestLoadHeartbeatParams_Entity_Unset(t *testing.T) { v := viper.New() - _, err := paramscmd.LoadHeartbeatParams(v) + _, err := cmdparams.LoadHeartbeatParams(v) require.Error(t, err) assert.Equal(t, "failed to retrieve entity", err.Error()) @@ -185,7 +186,7 @@ func TestLoadHeartbeatParams_EntityType(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("entity-type", name) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.Equal(t, entityType, params.EntityType) @@ -197,7 +198,7 @@ func TestLoadHeartbeatParams_EntityType_Default(t *testing.T) { v := viper.New() v.Set("entity", "/path/to/file") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.Equal(t, heartbeat.FileType, params.EntityType) @@ -208,7 +209,7 @@ func TestLoadHeartbeatParams_EntityType_Invalid(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("entity-type", "invalid") - _, err := paramscmd.LoadHeartbeatParams(v) + _, err := cmdparams.LoadHeartbeatParams(v) require.Error(t, err) assert.Equal( @@ -232,6 +233,8 @@ func TestLoadHeartbeatParams_ExtraHeartbeats(t *testing.T) { os.Stdin = r + cmdparams.Once = sync.Once{} + data, err := os.ReadFile("testdata/extra_heartbeats.json") require.NoError(t, err) @@ -246,7 +249,7 @@ func TestLoadHeartbeatParams_ExtraHeartbeats(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("extra-heartbeats", true) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.Len(t, params.ExtraHeartbeats, 2) @@ -304,6 +307,8 @@ func TestLoadHeartbeatParams_ExtraHeartbeats_WithStringValues(t *testing.T) { os.Stdin = r + cmdparams.Once = sync.Once{} + data, err := os.ReadFile("testdata/extra_heartbeats_with_string_values.json") require.NoError(t, err) @@ -318,7 +323,7 @@ func TestLoadHeartbeatParams_ExtraHeartbeats_WithStringValues(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("extra-heartbeats", true) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.Len(t, params.ExtraHeartbeats, 2) @@ -371,6 +376,8 @@ func TestLoadHeartbeatParams_ExtraHeartbeats_WithEOF(t *testing.T) { os.Stdin = r + cmdparams.Once = sync.Once{} + data, err := os.ReadFile("testdata/extra_heartbeats.json") require.NoError(t, err) @@ -386,7 +393,7 @@ func TestLoadHeartbeatParams_ExtraHeartbeats_WithEOF(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("extra-heartbeats", true) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.Len(t, params.ExtraHeartbeats, 2) @@ -449,6 +456,8 @@ func TestLoadHeartbeatParams_ExtraHeartbeats_NoData(t *testing.T) { os.Stdin = r + cmdparams.Once = sync.Once{} + go func() { _, err := w.Write([]byte{}) require.NoError(t, err) @@ -460,7 +469,7 @@ func TestLoadHeartbeatParams_ExtraHeartbeats_NoData(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("extra-heartbeats", true) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.Empty(t, params.ExtraHeartbeats) @@ -475,7 +484,7 @@ func TestLoadHeartbeat_GuessLanguage_FlagTakesPrecedence(t *testing.T) { v.Set("guess-language", true) v.Set("settings.guess_language", false) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.True(t, params.GuessLanguage) @@ -486,7 +495,7 @@ func TestLoadHeartbeat_GuessLanguage_FromConfig(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("settings.guess_language", true) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.True(t, params.GuessLanguage) @@ -496,7 +505,7 @@ func TestLoadHeartbeat_GuessLanguage_Default(t *testing.T) { v := viper.New() v.Set("entity", "/path/to/file") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.False(t, params.GuessLanguage) @@ -507,7 +516,7 @@ func TestLoadHeartbeatParams_IsUnsavedEntity(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("is-unsaved-entity", true) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.True(t, params.IsUnsavedEntity) @@ -525,7 +534,7 @@ func TestLoadHeartbeatParams_IsWrite(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("write", isWrite) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.Equal(t, isWrite, *params.IsWrite) @@ -537,7 +546,7 @@ func TestLoadHeartbeatParams_IsWrite_Unset(t *testing.T) { v := viper.New() v.Set("entity", "/path/to/file") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.Nil(t, params.IsWrite) @@ -548,7 +557,7 @@ func TestLoadHeartbeatParams_Language(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("language", "Go") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.Equal(t, heartbeat.LanguageGo.String(), *params.Language) @@ -559,7 +568,7 @@ func TestLoadHeartbeatParams_LanguageAlternate(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("alternate-language", "Go") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.Equal(t, heartbeat.LanguageGo.String(), params.LanguageAlternate) @@ -571,7 +580,7 @@ func TestLoadHeartbeatParams_LineNumber(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("lineno", 42) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.Equal(t, 42, *params.LineNumber) @@ -582,7 +591,7 @@ func TestLoadHeartbeatParams_LineNumber_Zero(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("lineno", 0) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.Zero(t, *params.LineNumber) @@ -592,7 +601,7 @@ func TestLoadHeartbeatParams_LineNumber_Unset(t *testing.T) { v := viper.New() v.Set("entity", "/path/to/file") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.Nil(t, params.LineNumber) @@ -603,7 +612,7 @@ func TestLoadHeartbeatParams_LocalFile(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("local-file", "/path/to/file") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.Equal(t, "/path/to/file", params.LocalFile) @@ -614,7 +623,7 @@ func TestLoadHeartbeatParams_Project(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("project", "billing") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.Equal(t, "billing", params.Project.Override) @@ -624,7 +633,7 @@ func TestLoadHeartbeatParams_Project_Unset(t *testing.T) { v := viper.New() v.Set("entity", "/path/to/file") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.Empty(t, params.Project.Override) @@ -667,7 +676,7 @@ func TestLoadHeartbeatParams_ProjectMap(t *testing.T) { v.Set("entity", test.Entity) v.Set(fmt.Sprintf("projectmap.%s", test.Regex.String()), test.Project) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.Equal(t, test.Expected, params.Project.MapPatterns) @@ -725,7 +734,7 @@ func TestLoadAPIParams_ProjectApiKey(t *testing.T) { v.Set("key", "00000000-0000-4000-8000-000000000000") v.Set(fmt.Sprintf("project_api_key.%s", test.Regex.String()), test.APIKey) - params, err := paramscmd.LoadAPIParams(v) + params, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) assert.Equal(t, test.Expected, params.KeyPatterns) @@ -744,7 +753,7 @@ func TestLoadAPIParams_ProjectApiKey_ParseConfig(t *testing.T) { err = inipkg.ReadInConfig(v, configFile) require.NoError(t, err) - params, err := paramscmd.LoadAPIParams(v) + params, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) expected := []apikey.MapPattern{ @@ -761,7 +770,7 @@ func TestLoadAPIParams_APIKeyPrefixSupported(t *testing.T) { v := viper.New() v.Set("key", "waka_00000000-0000-4000-8000-000000000000") - _, err := paramscmd.LoadAPIParams(v) + _, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) } @@ -770,7 +779,7 @@ func TestLoadHeartbeatParams_Time(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("time", 1590609206.1) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.Equal(t, 1590609206.1, params.Time) @@ -780,7 +789,7 @@ func TestLoadHeartbeatParams_Time_Default(t *testing.T) { v := viper.New() v.Set("entity", "/path/to/file") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) now := float64(time.Now().UnixNano()) / 1000000000 @@ -795,7 +804,7 @@ func TestLoadHeartbeatParams_Filter_Exclude(t *testing.T) { v.Set("settings.exclude", []string{".+", "wakatime.+"}) v.Set("settings.ignore", []string{".?", "wakatime.?"}) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) require.Len(t, params.Filter.Exclude, 6) @@ -812,7 +821,7 @@ func TestLoadHeartbeatParams_Filter_Exclude_Multiline(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("settings.ignore", "\t.?\n\twakatime.? \t\n") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) require.Len(t, params.Filter.Exclude, 2) @@ -825,7 +834,7 @@ func TestLoadHeartbeatParams_Filter_Exclude_IgnoresInvalidRegex(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("exclude", []string{".*", "["}) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) require.Len(t, params.Filter.Exclude, 1) @@ -844,7 +853,7 @@ func TestLoadHeartbeatParams_Filter_Exclude_PerlRegexPatterns(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("exclude", []string{pattern}) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) require.Len(t, params.Filter.Exclude, 1) @@ -858,7 +867,7 @@ func TestLoadHeartbeatParams_Filter_ExcludeUnknownProject(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("exclude-unknown-project", true) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.True(t, params.Filter.ExcludeUnknownProject) @@ -870,7 +879,7 @@ func TestLoadHeartbeatParams_Filter_ExcludeUnknownProject_FromConfig(t *testing. v.Set("exclude-unknown-project", false) v.Set("settings.exclude_unknown_project", true) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.True(t, params.Filter.ExcludeUnknownProject) @@ -882,7 +891,7 @@ func TestLoadHeartbeatParams_Filter_Include(t *testing.T) { v.Set("include", []string{".*", "wakatime.*"}) v.Set("settings.include", []string{".+", "wakatime.+"}) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) require.Len(t, params.Filter.Include, 4) @@ -897,7 +906,7 @@ func TestLoadHeartbeatParams_Filter_Include_IgnoresInvalidRegex(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("include", []string{".*", "["}) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) require.Len(t, params.Filter.Include, 1) @@ -916,7 +925,7 @@ func TestLoadHeartbeatParams_Filter_Include_PerlRegexPatterns(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("include", []string{pattern}) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) require.Len(t, params.Filter.Include, 1) @@ -930,7 +939,7 @@ func TestLoadHeartbeatParams_Filter_IncludeOnlyWithProjectFile(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("include-only-with-project-file", true) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.True(t, params.Filter.IncludeOnlyWithProjectFile) @@ -942,7 +951,7 @@ func TestLoadHeartbeatParams_Filter_IncludeOnlyWithProjectFile_FromConfig(t *tes v.Set("include-only-with-project-file", false) v.Set("settings.include_only_with_project_file", true) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.True(t, params.Filter.IncludeOnlyWithProjectFile) @@ -961,10 +970,10 @@ func TestLoadHeartbeatParams_SanitizeParams_HideBranchNames_True(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("hide-branch-names", viperValue) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) - assert.Equal(t, paramscmd.SanitizeParams{ + assert.Equal(t, cmdparams.SanitizeParams{ HideBranchNames: []regex.Regex{regex.MustCompile(".*")}, }, params.Sanitize) }) @@ -984,10 +993,10 @@ func TestLoadHeartbeatParams_SanitizeParams_HideBranchNames_False(t *testing.T) v.Set("entity", "/path/to/file") v.Set("hide-branch-names", viperValue) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) - assert.Equal(t, paramscmd.SanitizeParams{ + assert.Equal(t, cmdparams.SanitizeParams{ HideBranchNames: []regex.Regex{regex.MustCompile("a^")}, }, params.Sanitize) }) @@ -1020,10 +1029,10 @@ func TestLoadHeartbeatParams_SanitizeParams_HideBranchNames_List(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("hide-branch-names", test.ViperValue) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) - assert.Equal(t, paramscmd.SanitizeParams{ + assert.Equal(t, cmdparams.SanitizeParams{ HideBranchNames: test.Expected, }, params.Sanitize) }) @@ -1038,10 +1047,10 @@ func TestLoadHeartbeatParams_SanitizeParams_HideBranchNames_FlagTakesPrecedence( v.Set("settings.hide_branchnames", "ignored") v.Set("settings.hidebranchnames", "ignored") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) - assert.Equal(t, paramscmd.SanitizeParams{ + assert.Equal(t, cmdparams.SanitizeParams{ HideBranchNames: []regex.Regex{regexp.MustCompile(".*")}, }, params.Sanitize) } @@ -1053,10 +1062,10 @@ func TestLoadHeartbeatParams_SanitizeParams_HideBranchNames_ConfigTakesPrecedenc v.Set("settings.hide_branchnames", "ignored") v.Set("settings.hidebranchnames", "ignored") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) - assert.Equal(t, paramscmd.SanitizeParams{ + assert.Equal(t, cmdparams.SanitizeParams{ HideBranchNames: []regex.Regex{regexp.MustCompile(".*")}, }, params.Sanitize) } @@ -1067,10 +1076,10 @@ func TestLoadHeartbeatParams_SanitizeParams_HideBranchNames_ConfigDeprecatedOneT v.Set("settings.hide_branchnames", "true") v.Set("settings.hidebranchnames", "ignored") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) - assert.Equal(t, paramscmd.SanitizeParams{ + assert.Equal(t, cmdparams.SanitizeParams{ HideBranchNames: []regex.Regex{regexp.MustCompile(".*")}, }, params.Sanitize) } @@ -1080,10 +1089,10 @@ func TestLoadHeartbeatParams_SanitizeParams_HideBranchNames_ConfigDeprecatedTwo( v.Set("entity", "/path/to/file") v.Set("settings.hidebranchnames", "true") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) - assert.Equal(t, paramscmd.SanitizeParams{ + assert.Equal(t, cmdparams.SanitizeParams{ HideBranchNames: []regex.Regex{regexp.MustCompile(".*")}, }, params.Sanitize) } @@ -1093,7 +1102,7 @@ func TestLoadHeartbeatParams_SanitizeParams_HideBranchNames_InvalidRegex(t *test v.Set("entity", "/path/to/file") v.Set("hide-branch-names", ".*secret.*\n[0-9+") - _, err := paramscmd.LoadHeartbeatParams(v) + _, err := cmdparams.LoadHeartbeatParams(v) require.Error(t, err) assert.True(t, strings.HasPrefix( @@ -1117,10 +1126,10 @@ func TestLoadHeartbeatParams_SanitizeParams_HideProjectNames_True(t *testing.T) v.Set("entity", "/path/to/file") v.Set("hide-project-names", viperValue) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) - assert.Equal(t, paramscmd.SanitizeParams{ + assert.Equal(t, cmdparams.SanitizeParams{ HideProjectNames: []regex.Regex{regexp.MustCompile(".*")}, }, params.Sanitize) }) @@ -1140,10 +1149,10 @@ func TestLoadHeartbeatParams_SanitizeParams_HideProjectNames_False(t *testing.T) v.Set("entity", "/path/to/file") v.Set("hide-project-names", viperValue) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) - assert.Equal(t, paramscmd.SanitizeParams{ + assert.Equal(t, cmdparams.SanitizeParams{ HideProjectNames: []regex.Regex{regexp.MustCompile("a^")}, }, params.Sanitize) }) @@ -1176,10 +1185,10 @@ func TestLoadHeartbeatParams_SanitizeParams_HideProjecthNames_List(t *testing.T) v.Set("entity", "/path/to/file") v.Set("hide-project-names", test.ViperValue) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) - assert.Equal(t, paramscmd.SanitizeParams{ + assert.Equal(t, cmdparams.SanitizeParams{ HideProjectNames: test.Expected, }, params.Sanitize) }) @@ -1194,10 +1203,10 @@ func TestLoadHeartbeatParams_SanitizeParams_HideProjectNames_FlagTakesPrecedence v.Set("settings.hide_projectnames", "ignored") v.Set("settings.hideprojectnames", "ignored") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) - assert.Equal(t, paramscmd.SanitizeParams{ + assert.Equal(t, cmdparams.SanitizeParams{ HideProjectNames: []regex.Regex{regexp.MustCompile(".*")}, }, params.Sanitize) } @@ -1209,10 +1218,10 @@ func TestLoadHeartbeatParams_SanitizeParams_HideProjectNames_ConfigTakesPreceden v.Set("settings.hide_projectnames", "ignored") v.Set("settings.hideprojectnames", "ignored") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) - assert.Equal(t, paramscmd.SanitizeParams{ + assert.Equal(t, cmdparams.SanitizeParams{ HideProjectNames: []regex.Regex{regexp.MustCompile(".*")}, }, params.Sanitize) } @@ -1223,10 +1232,10 @@ func TestLoadHeartbeatParams_SanitizeParams_HideProjectNames_ConfigDeprecatedOne v.Set("settings.hide_projectnames", "true") v.Set("settings.hideprojectnames", "ignored") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) - assert.Equal(t, paramscmd.SanitizeParams{ + assert.Equal(t, cmdparams.SanitizeParams{ HideProjectNames: []regex.Regex{regexp.MustCompile(".*")}, }, params.Sanitize) } @@ -1236,10 +1245,10 @@ func TestLoadHeartbeatParams_SanitizeParams_HideProjectNames_ConfigDeprecatedTwo v.Set("entity", "/path/to/file") v.Set("settings.hideprojectnames", "true") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) - assert.Equal(t, paramscmd.SanitizeParams{ + assert.Equal(t, cmdparams.SanitizeParams{ HideProjectNames: []regex.Regex{regexp.MustCompile(".*")}, }, params.Sanitize) } @@ -1249,7 +1258,7 @@ func TestLoadHeartbeatParams_SanitizeParams_HideProjectNames_InvalidRegex(t *tes v.Set("entity", "/path/to/file") v.Set("hide-project-names", ".*secret.*\n[0-9+") - _, err := paramscmd.LoadHeartbeatParams(v) + _, err := cmdparams.LoadHeartbeatParams(v) require.Error(t, err) assert.True(t, strings.HasPrefix( @@ -1273,10 +1282,10 @@ func TestLoadHeartbeatParams_SanitizeParams_HideFileNames_True(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("hide-file-names", viperValue) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) - assert.Equal(t, paramscmd.SanitizeParams{ + assert.Equal(t, cmdparams.SanitizeParams{ HideFileNames: []regex.Regex{regexp.MustCompile(".*")}, }, params.Sanitize) }) @@ -1296,10 +1305,10 @@ func TestLoadHeartbeatParams_SanitizeParams_HideFileNames_False(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("hide-file-names", viperValue) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) - assert.Equal(t, paramscmd.SanitizeParams{ + assert.Equal(t, cmdparams.SanitizeParams{ HideFileNames: []regex.Regex{regexp.MustCompile("a^")}, }, params.Sanitize) }) @@ -1332,10 +1341,10 @@ func TestLoadHeartbeatParams_SanitizeParams_HideFileNames_List(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("hide-file-names", test.ViperValue) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) - assert.Equal(t, paramscmd.SanitizeParams{ + assert.Equal(t, cmdparams.SanitizeParams{ HideFileNames: test.Expected, }, params.Sanitize) }) @@ -1352,10 +1361,10 @@ func TestLoadheartbeatParams_SanitizeParams_HideFileNames_FlagTakesPrecedence(t v.Set("settings.hide_filenames", "ignored") v.Set("settings.hidefilenames", "ignored") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) - assert.Equal(t, paramscmd.SanitizeParams{ + assert.Equal(t, cmdparams.SanitizeParams{ HideFileNames: []regex.Regex{regexp.MustCompile(".*")}, }, params.Sanitize) } @@ -1369,10 +1378,10 @@ func TestLoadHeartbeatParams_SanitizeParams_HideFileNames_FlagDeprecatedOneTakes v.Set("settings.hide_filenames", "ignored") v.Set("settings.hidefilenames", "ignored") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) - assert.Equal(t, paramscmd.SanitizeParams{ + assert.Equal(t, cmdparams.SanitizeParams{ HideFileNames: []regex.Regex{regexp.MustCompile(".*")}, }, params.Sanitize) } @@ -1385,10 +1394,10 @@ func TestLoadHeartbeatParams_SanitizeParams_HideFileNames_FlagDeprecatedTwoTakes v.Set("settings.hide_filenames", "ignored") v.Set("settings.hidefilenames", "ignored") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) - assert.Equal(t, paramscmd.SanitizeParams{ + assert.Equal(t, cmdparams.SanitizeParams{ HideFileNames: []regex.Regex{regexp.MustCompile(".*")}, }, params.Sanitize) } @@ -1400,10 +1409,10 @@ func TestLoadHeartbeatParams_SanitizeParams_HideFileNames_ConfigTakesPrecedence( v.Set("settings.hide_filenames", "ignored") v.Set("settings.hidefilenames", "ignored") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) - assert.Equal(t, paramscmd.SanitizeParams{ + assert.Equal(t, cmdparams.SanitizeParams{ HideFileNames: []regex.Regex{regexp.MustCompile(".*")}, }, params.Sanitize) } @@ -1414,10 +1423,10 @@ func TestLoadHeartbeatParams_SanitizeParams_HideFileNames_ConfigDeprecatedOneTak v.Set("settings.hide_filenames", "true") v.Set("settings.hidefilenames", "ignored") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) - assert.Equal(t, paramscmd.SanitizeParams{ + assert.Equal(t, cmdparams.SanitizeParams{ HideFileNames: []regex.Regex{regexp.MustCompile(".*")}, }, params.Sanitize) } @@ -1427,10 +1436,10 @@ func TestLoadHeartbeatParams_SanitizeParams_HideFileNames_ConfigDeprecatedTwo(t v.Set("entity", "/path/to/file") v.Set("settings.hidefilenames", "true") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) - assert.Equal(t, paramscmd.SanitizeParams{ + assert.Equal(t, cmdparams.SanitizeParams{ HideFileNames: []regex.Regex{regexp.MustCompile(".*")}, }, params.Sanitize) } @@ -1440,7 +1449,7 @@ func TestLoadHeartbeatParams_SanitizeParams_HideFileNames_InvalidRegex(t *testin v.Set("entity", "/path/to/file") v.Set("hide-file-names", ".*secret.*\n[0-9+") - _, err := paramscmd.LoadHeartbeatParams(v) + _, err := cmdparams.LoadHeartbeatParams(v) require.Error(t, err) assert.True(t, strings.HasPrefix( @@ -1456,10 +1465,10 @@ func TestLoadHeartbeatParams_SanitizeParams_HideProjectFolder(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("hide-project-folder", true) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) - assert.Equal(t, paramscmd.SanitizeParams{ + assert.Equal(t, cmdparams.SanitizeParams{ HideProjectFolder: true, }, params.Sanitize) } @@ -1469,10 +1478,10 @@ func TestLoadHeartbeatParams_SanitizeParams_HideProjectFolder_ConfigTakesPrecede v.Set("entity", "/path/to/file") v.Set("settings.hide_project_folder", true) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) - assert.Equal(t, paramscmd.SanitizeParams{ + assert.Equal(t, cmdparams.SanitizeParams{ HideProjectFolder: true, }, params.Sanitize) } @@ -1482,10 +1491,10 @@ func TestLoadHeartbeatParams_SanitizeParams_OverrideProjectPath(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("project-folder", "/custom-path") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) - assert.Equal(t, paramscmd.SanitizeParams{ + assert.Equal(t, cmdparams.SanitizeParams{ ProjectPathOverride: "/custom-path", }, params.Sanitize) } @@ -1503,7 +1512,7 @@ func TestLoadHeartbeatParams_SubmodulesDisabled_True(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("git.submodules_disabled", viperValue) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.Equal(t, []regex.Regex{regexp.MustCompile(".*")}, params.Project.SubmodulesDisabled) @@ -1524,7 +1533,7 @@ func TestLoadHeartbeatParams_SubmodulesDisabled_False(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("git.submodules_disabled", viperValue) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.Equal(t, params.Project.SubmodulesDisabled, []regex.Regex{regexp.MustCompile("a^")}) @@ -1559,7 +1568,7 @@ func TestLoadHeartbeatsParams_SubmodulesDisabled_List(t *testing.T) { v.Set("entity", "/path/to/file") v.Set("git.submodules_disabled", test.ViperValue) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.Equal(t, test.Expected, params.Project.SubmodulesDisabled) @@ -1604,7 +1613,7 @@ func TestLoadHeartbeatsParams_SubmoduleProjectMap(t *testing.T) { v.Set("entity", test.Entity) v.Set(fmt.Sprintf("git_submodule_projectmap.%s", test.Regex.String()), test.Project) - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.Equal(t, test.Expected, params.Project.SubmoduleMapPatterns) @@ -1617,7 +1626,7 @@ func TestLoadAPIParams_Plugin(t *testing.T) { v.Set("key", "00000000-0000-4000-8000-000000000000") v.Set("plugin", "plugin/10.0.0") - params, err := paramscmd.LoadAPIParams(v) + params, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) assert.Equal(t, "plugin/10.0.0", params.Plugin) @@ -1627,7 +1636,7 @@ func TestLoadAPIParams_Plugin_Unset(t *testing.T) { v := viper.New() v.Set("key", "00000000-0000-4000-8000-000000000000") - params, err := paramscmd.LoadAPIParams(v) + params, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) assert.Empty(t, params.Plugin) @@ -1639,7 +1648,7 @@ func TestLoadAPIParams_Timeout_FlagTakesPrecedence(t *testing.T) { v.Set("timeout", 5) v.Set("settings.timeout", 10) - params, err := paramscmd.LoadAPIParams(v) + params, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) assert.Equal(t, 5*time.Second, params.Timeout) @@ -1650,7 +1659,7 @@ func TestLoadAPIParams_Timeout_FromConfig(t *testing.T) { v.Set("key", "00000000-0000-4000-8000-000000000000") v.Set("settings.timeout", 10) - params, err := paramscmd.LoadAPIParams(v) + params, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) assert.Equal(t, 10*time.Second, params.Timeout) @@ -1662,7 +1671,7 @@ func TestLoadOfflineParams_Disabled_ConfigTakesPrecedence(t *testing.T) { v.Set("disableoffline", false) v.Set("settings.offline", false) - params := paramscmd.LoadOfflineParams(v) + params := cmdparams.LoadOfflineParams(v) assert.True(t, params.Disabled) } @@ -1672,7 +1681,7 @@ func TestLoadOfflineParams_Disabled_FlagDeprecatedTakesPrecedence(t *testing.T) v.Set("disable-offline", false) v.Set("disableoffline", true) - params := paramscmd.LoadOfflineParams(v) + params := cmdparams.LoadOfflineParams(v) assert.True(t, params.Disabled) } @@ -1681,7 +1690,7 @@ func TestLoadOfflineParams_Disabled_FromFlag(t *testing.T) { v := viper.New() v.Set("disable-offline", true) - params := paramscmd.LoadOfflineParams(v) + params := cmdparams.LoadOfflineParams(v) assert.True(t, params.Disabled) } @@ -1691,7 +1700,7 @@ func TestLoadOfflineParams_RateLimit_FlagTakesPrecedence(t *testing.T) { v.Set("heartbeat-rate-limit-seconds", 5) v.Set("settings.heartbeat_rate_limit_seconds", 10) - params := paramscmd.LoadOfflineParams(v) + params := cmdparams.LoadOfflineParams(v) assert.Equal(t, time.Duration(5)*time.Second, params.RateLimit) } @@ -1700,7 +1709,7 @@ func TestLoadOfflineParams_RateLimit_FromConfig(t *testing.T) { v := viper.New() v.Set("settings.heartbeat_rate_limit_seconds", 10) - params := paramscmd.LoadOfflineParams(v) + params := cmdparams.LoadOfflineParams(v) assert.Equal(t, time.Duration(10)*time.Second, params.RateLimit) } @@ -1709,7 +1718,7 @@ func TestLoadOfflineParams_RateLimit_Zero(t *testing.T) { v := viper.New() v.Set("heartbeat-rate-limit-seconds", "0") - params := paramscmd.LoadOfflineParams(v) + params := cmdparams.LoadOfflineParams(v) assert.Zero(t, params.RateLimit) } @@ -1718,7 +1727,7 @@ func TestLoadOfflineParams_RateLimit_Default(t *testing.T) { v := viper.New() v.SetDefault("heartbeat-rate-limit-seconds", 20) - params := paramscmd.LoadOfflineParams(v) + params := cmdparams.LoadOfflineParams(v) assert.Equal(t, time.Duration(20)*time.Second, params.RateLimit) } @@ -1727,7 +1736,7 @@ func TestLoadOfflineParams_RateLimit_NegativeNumber(t *testing.T) { v := viper.New() v.Set("heartbeat-rate-limit-seconds", -1) - params := paramscmd.LoadOfflineParams(v) + params := cmdparams.LoadOfflineParams(v) assert.Zero(t, params.RateLimit) } @@ -1736,7 +1745,7 @@ func TestLoadOfflineParams_RateLimit_NonIntegerValue(t *testing.T) { v := viper.New() v.Set("heartbeat-rate-limit-seconds", "invalid") - params := paramscmd.LoadOfflineParams(v) + params := cmdparams.LoadOfflineParams(v) assert.Zero(t, params.RateLimit) } @@ -1745,7 +1754,7 @@ func TestLoadOfflineParams_LastSentAt(t *testing.T) { v := viper.New() v.Set("internal.heartbeats_last_sent_at", "2021-08-30T18:50:42-03:00") - params := paramscmd.LoadOfflineParams(v) + params := cmdparams.LoadOfflineParams(v) lastSentAt, err := time.Parse(inipkg.DateFormat, "2021-08-30T18:50:42-03:00") require.NoError(t, err) @@ -1757,7 +1766,7 @@ func TestLoadOfflineParams_LastSentAt_Err(t *testing.T) { v := viper.New() v.Set("internal.heartbeats_last_sent_at", "2021-08-30") - params := paramscmd.LoadOfflineParams(v) + params := cmdparams.LoadOfflineParams(v) assert.Zero(t, params.LastSentAt) } @@ -1766,7 +1775,7 @@ func TestLoadOfflineParams_QueueFile(t *testing.T) { v := viper.New() v.Set("offline-queue-file", "/path/to/file") - params := paramscmd.LoadOfflineParams(v) + params := cmdparams.LoadOfflineParams(v) assert.Equal(t, "/path/to/file", params.QueueFile) } @@ -1775,7 +1784,7 @@ func TestLoadOfflineParams_QueueFileLegacy(t *testing.T) { v := viper.New() v.Set("offline-queue-file-legacy", "/path/to/file") - params := paramscmd.LoadOfflineParams(v) + params := cmdparams.LoadOfflineParams(v) assert.Equal(t, "/path/to/file", params.QueueFileLegacy) } @@ -1784,7 +1793,7 @@ func TestLoadOfflineParams_SyncMax(t *testing.T) { v := viper.New() v.Set("sync-offline-activity", 42) - params := paramscmd.LoadOfflineParams(v) + params := cmdparams.LoadOfflineParams(v) assert.Equal(t, 42, params.SyncMax) } @@ -1793,7 +1802,7 @@ func TestLoadOfflineParams_SyncMax_Zero(t *testing.T) { v := viper.New() v.Set("sync-offline-activity", "0") - params := paramscmd.LoadOfflineParams(v) + params := cmdparams.LoadOfflineParams(v) assert.Zero(t, params.SyncMax) } @@ -1802,7 +1811,7 @@ func TestLoadOfflineParams_SyncMax_Default(t *testing.T) { v := viper.New() v.SetDefault("sync-offline-activity", 1000) - params := paramscmd.LoadOfflineParams(v) + params := cmdparams.LoadOfflineParams(v) assert.Equal(t, 1000, params.SyncMax) } @@ -1811,7 +1820,7 @@ func TestLoadOfflineParams_SyncMax_NegativeNumber(t *testing.T) { v := viper.New() v.Set("sync-offline-activity", -1) - params := paramscmd.LoadOfflineParams(v) + params := cmdparams.LoadOfflineParams(v) assert.Zero(t, params.SyncMax) } @@ -1820,7 +1829,7 @@ func TestLoadOfflineParams_SyncMax_NonIntegerValue(t *testing.T) { v := viper.New() v.Set("sync-offline-activity", "invalid") - params := paramscmd.LoadOfflineParams(v) + params := cmdparams.LoadOfflineParams(v) assert.Zero(t, params.SyncMax) } @@ -1830,13 +1839,13 @@ func TestLoadAPIParams_APIKey(t *testing.T) { ViperAPIKey string ViperAPIKeyConfig string ViperAPIKeyConfigOld string - Expected paramscmd.API + Expected cmdparams.API }{ "api key flag takes precedence": { ViperAPIKey: "00000000-0000-4000-8000-000000000000", ViperAPIKeyConfig: "10000000-0000-4000-8000-000000000000", ViperAPIKeyConfigOld: "20000000-0000-4000-8000-000000000000", - Expected: paramscmd.API{ + Expected: cmdparams.API{ Key: "00000000-0000-4000-8000-000000000000", URL: "https://api.wakatime.com/api/v1", Hostname: "my-computer", @@ -1845,7 +1854,7 @@ func TestLoadAPIParams_APIKey(t *testing.T) { "api from config takes precedence": { ViperAPIKeyConfig: "00000000-0000-4000-8000-000000000000", ViperAPIKeyConfigOld: "10000000-0000-4000-8000-000000000000", - Expected: paramscmd.API{ + Expected: cmdparams.API{ Key: "00000000-0000-4000-8000-000000000000", URL: "https://api.wakatime.com/api/v1", Hostname: "my-computer", @@ -1853,7 +1862,7 @@ func TestLoadAPIParams_APIKey(t *testing.T) { }, "api key from config deprecated": { ViperAPIKeyConfigOld: "00000000-0000-4000-8000-000000000000", - Expected: paramscmd.API{ + Expected: cmdparams.API{ Key: "00000000-0000-4000-8000-000000000000", URL: "https://api.wakatime.com/api/v1", Hostname: "my-computer", @@ -1869,7 +1878,7 @@ func TestLoadAPIParams_APIKey(t *testing.T) { v.Set("settings.api_key", test.ViperAPIKeyConfig) v.Set("settings.apikey", test.ViperAPIKeyConfigOld) - params, err := paramscmd.LoadAPIParams(v) + params, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) assert.Equal(t, test.Expected, params) @@ -1881,7 +1890,7 @@ func TestLoadAPIParams_APIKeyUnset(t *testing.T) { v := viper.New() v.Set("key", "") - _, err := paramscmd.LoadAPIParams(v) + _, err := cmdparams.LoadAPIParams(v) require.Error(t, err) var errauth api.ErrAuth @@ -1903,7 +1912,7 @@ func TestLoadAPIParams_APIKeyInvalid(t *testing.T) { v := viper.New() v.Set("key", value) - _, err := paramscmd.LoadAPIParams(v) + _, err := cmdparams.LoadAPIParams(v) require.Error(t, err) var errauth api.ErrAuth @@ -1925,7 +1934,7 @@ func TestLoadAPIParams_ApiKey_SettingTakePrecedence(t *testing.T) { err = inipkg.ReadInConfig(v, configFile) require.NoError(t, err) - params, err := paramscmd.LoadAPIParams(v) + params, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) assert.Equal(t, "00000000-0000-4000-8000-000000000000", params.Key) @@ -1942,7 +1951,7 @@ func TestLoadAPIParams_ApiKey_FromVault(t *testing.T) { err = inipkg.ReadInConfig(v, configFile) require.NoError(t, err) - params, err := paramscmd.LoadAPIParams(v) + params, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) assert.Equal(t, "00000000-0000-4000-8000-000000000000", params.Key) @@ -1963,7 +1972,7 @@ func TestLoadParams_ApiKey_FromVault_Err_Darwin(t *testing.T) { err = inipkg.ReadInConfig(v, configFile) require.NoError(t, err) - _, err = paramscmd.LoadAPIParams(v) + _, err = cmdparams.LoadAPIParams(v) assert.EqualError(t, err, "failed to read api key from vault: exit status 1") } @@ -1976,7 +1985,7 @@ func TestLoadAPIParams_APIKeyFromEnv(t *testing.T) { defer os.Unsetenv("WAKATIME_API_KEY") - params, err := paramscmd.LoadAPIParams(v) + params, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) assert.Equal(t, "00000000-0000-4000-8000-000000000000", params.Key) @@ -1990,7 +1999,7 @@ func TestLoadAPIParams_APIKeyFromEnvInvalid(t *testing.T) { defer os.Unsetenv("WAKATIME_API_KEY") - _, err = paramscmd.LoadAPIParams(v) + _, err = cmdparams.LoadAPIParams(v) require.Error(t, err) var errauth api.ErrAuth @@ -2009,7 +2018,7 @@ func TestLoadAPIParams_APIKeyFromEnv_ConfigTakesPrecedence(t *testing.T) { defer os.Unsetenv("WAKATIME_API_KEY") - params, err := paramscmd.LoadAPIParams(v) + params, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) assert.Equal(t, "00000000-0000-4000-8000-000000000000", params.Key) @@ -2020,13 +2029,13 @@ func TestLoadAPIParams_APIUrl(t *testing.T) { ViperAPIUrl string ViperAPIUrlConfig string ViperAPIUrlOld string - Expected paramscmd.API + Expected cmdparams.API }{ "api url flag takes precedence": { ViperAPIUrl: "http://localhost:8080", ViperAPIUrlConfig: "http://localhost:8081", ViperAPIUrlOld: "http://localhost:8082", - Expected: paramscmd.API{ + Expected: cmdparams.API{ Key: "00000000-0000-4000-8000-000000000000", URL: "http://localhost:8080", Hostname: "my-computer", @@ -2035,7 +2044,7 @@ func TestLoadAPIParams_APIUrl(t *testing.T) { "api url deprecated flag takes precedence": { ViperAPIUrlConfig: "http://localhost:8081", ViperAPIUrlOld: "http://localhost:8082", - Expected: paramscmd.API{ + Expected: cmdparams.API{ Key: "00000000-0000-4000-8000-000000000000", URL: "http://localhost:8082", Hostname: "my-computer", @@ -2043,7 +2052,7 @@ func TestLoadAPIParams_APIUrl(t *testing.T) { }, "api url from config": { ViperAPIUrlConfig: "http://localhost:8081", - Expected: paramscmd.API{ + Expected: cmdparams.API{ Key: "00000000-0000-4000-8000-000000000000", URL: "http://localhost:8081", Hostname: "my-computer", @@ -2051,7 +2060,7 @@ func TestLoadAPIParams_APIUrl(t *testing.T) { }, "api url with legacy heartbeats endpoint": { ViperAPIUrl: "http://localhost:8080/api/v1/heartbeats.bulk", - Expected: paramscmd.API{ + Expected: cmdparams.API{ Key: "00000000-0000-4000-8000-000000000000", URL: "http://localhost:8080/api/v1", Hostname: "my-computer", @@ -2059,7 +2068,7 @@ func TestLoadAPIParams_APIUrl(t *testing.T) { }, "api url with trailing slash": { ViperAPIUrl: "http://localhost:8080/api/", - Expected: paramscmd.API{ + Expected: cmdparams.API{ Key: "00000000-0000-4000-8000-000000000000", URL: "http://localhost:8080/api", Hostname: "my-computer", @@ -2067,7 +2076,7 @@ func TestLoadAPIParams_APIUrl(t *testing.T) { }, "api url with wakapi style endpoint": { ViperAPIUrl: "http://localhost:8080/api/heartbeat", - Expected: paramscmd.API{ + Expected: cmdparams.API{ Key: "00000000-0000-4000-8000-000000000000", URL: "http://localhost:8080/api", Hostname: "my-computer", @@ -2084,7 +2093,7 @@ func TestLoadAPIParams_APIUrl(t *testing.T) { v.Set("apiurl", test.ViperAPIUrlOld) v.Set("settings.api_url", test.ViperAPIUrlConfig) - params, err := paramscmd.LoadAPIParams(v) + params, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) assert.Equal(t, test.Expected, params) @@ -2096,7 +2105,7 @@ func TestLoadAPIParams_Url_Default(t *testing.T) { v := viper.New() v.Set("key", "00000000-0000-4000-8000-000000000000") - params, err := paramscmd.LoadAPIParams(v) + params, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) assert.Equal(t, api.BaseURL, params.URL) @@ -2107,7 +2116,7 @@ func TestLoadAPIParams_Url_InvalidFormat(t *testing.T) { v.Set("key", "00000000-0000-4000-8000-000000000000") v.Set("api-url", "http://in valid") - _, err := paramscmd.LoadAPIParams(v) + _, err := cmdparams.LoadAPIParams(v) var errauth api.ErrAuth @@ -2123,13 +2132,13 @@ func TestLoadAPIParams_BackoffAt(t *testing.T) { v.Set("internal.backoff_at", "2021-08-30T18:50:42-03:00") v.Set("internal.backoff_retries", "3") - params, err := paramscmd.LoadAPIParams(v) + params, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) backoffAt, err := time.Parse(inipkg.DateFormat, "2021-08-30T18:50:42-03:00") require.NoError(t, err) - assert.Equal(t, paramscmd.API{ + assert.Equal(t, cmdparams.API{ BackoffAt: backoffAt, BackoffRetries: 3, Key: "00000000-0000-4000-8000-000000000000", @@ -2145,10 +2154,10 @@ func TestLoadAPIParams_BackoffAtErr(t *testing.T) { v.Set("internal.backoff_at", "2021-08-30") v.Set("internal.backoff_retries", "2") - params, err := paramscmd.LoadAPIParams(v) + params, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) - assert.Equal(t, paramscmd.API{ + assert.Equal(t, cmdparams.API{ BackoffAt: time.Time{}, BackoffRetries: 2, Key: "00000000-0000-4000-8000-000000000000", @@ -2163,7 +2172,7 @@ func TestLoadAPIParams_DisableSSLVerify_FlagTakesPrecedence(t *testing.T) { v.Set("no-ssl-verify", true) v.Set("settings.no_ssl_verify", false) - params, err := paramscmd.LoadAPIParams(v) + params, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) assert.True(t, params.DisableSSLVerify) @@ -2174,7 +2183,7 @@ func TestLoadAPIParams_DisableSSLVerify_FromConfig(t *testing.T) { v.Set("key", "00000000-0000-4000-8000-000000000000") v.Set("settings.no_ssl_verify", true) - params, err := paramscmd.LoadAPIParams(v) + params, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) assert.True(t, params.DisableSSLVerify) @@ -2184,7 +2193,7 @@ func TestLoadAPIParams_DisableSSLVerify_Default(t *testing.T) { v := viper.New() v.Set("key", "00000000-0000-4000-8000-000000000000") - params, err := paramscmd.LoadAPIParams(v) + params, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) assert.False(t, params.DisableSSLVerify) @@ -2205,7 +2214,7 @@ func TestLoadAPIParams_ProxyURL(t *testing.T) { v.Set("key", "00000000-0000-4000-8000-000000000000") v.Set("proxy", proxyURL) - params, err := paramscmd.LoadAPIParams(v) + params, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) assert.Equal(t, proxyURL, params.ProxyURL) @@ -2219,7 +2228,7 @@ func TestLoadAPIParams_ProxyURL_FlagTakesPrecedence(t *testing.T) { v.Set("proxy", "https://john:secret@example.org:8888") v.Set("settings.proxy", "ignored") - params, err := paramscmd.LoadAPIParams(v) + params, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) assert.Equal(t, "https://john:secret@example.org:8888", params.ProxyURL) @@ -2235,7 +2244,7 @@ func TestLoadAPIParams_ProxyURL_UserDefinedTakesPrecedenceOverEnvironment(t *tes defer os.Unsetenv("HTTPS_PROXY") - params, err := paramscmd.LoadAPIParams(v) + params, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) assert.Equal(t, "https://john:secret@example.org:8888", params.ProxyURL) @@ -2246,7 +2255,7 @@ func TestLoadAPIParams_ProxyURL_FromConfig(t *testing.T) { v.Set("key", "00000000-0000-4000-8000-000000000000") v.Set("settings.proxy", "https://john:secret@example.org:8888") - params, err := paramscmd.LoadAPIParams(v) + params, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) assert.Equal(t, "https://john:secret@example.org:8888", params.ProxyURL) @@ -2261,7 +2270,7 @@ func TestLoadAPIParams_ProxyURL_FromEnvironment(t *testing.T) { defer os.Unsetenv("HTTPS_PROXY") - params, err := paramscmd.LoadAPIParams(v) + params, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) assert.Equal(t, "https://john:secret@example.org:8888", params.ProxyURL) @@ -2276,7 +2285,7 @@ func TestLoadAPIParams_ProxyURL_NoProxyFromEnvironment(t *testing.T) { defer os.Unsetenv("NO_PROXY") - params, err := paramscmd.LoadAPIParams(v) + params, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) assert.Empty(t, params.ProxyURL) @@ -2287,7 +2296,7 @@ func TestLoadAPIParams_ProxyURL_InvalidFormat(t *testing.T) { v.Set("key", "00000000-0000-4000-8000-000000000000") v.Set("proxy", "ftp://john:secret@example.org:8888") - _, err := paramscmd.LoadAPIParams(v) + _, err := cmdparams.LoadAPIParams(v) var errauth api.ErrAuth @@ -2308,7 +2317,7 @@ func TestLoadAPIParams_SSLCertFilepath_FlagTakesPrecedence(t *testing.T) { home, err := os.UserHomeDir() require.NoError(t, err) - params, err := paramscmd.LoadAPIParams(v) + params, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) assert.Equal(t, filepath.Join(home, "/path/to/cert.pem"), params.SSLCertFilepath) @@ -2319,7 +2328,7 @@ func TestLoadAPIParams_SSLCertFilepath_FromConfig(t *testing.T) { v.Set("key", "00000000-0000-4000-8000-000000000000") v.Set("settings.ssl_certs_file", "/path/to/cert.pem") - params, err := paramscmd.LoadAPIParams(v) + params, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) assert.Equal(t, "/path/to/cert.pem", params.SSLCertFilepath) @@ -2336,7 +2345,7 @@ func TestLoadAPIParams_Hostname_FlagTakesPrecedence(t *testing.T) { defer os.Unsetenv("GITPOD_WORKSPACE_ID") - params, err := paramscmd.LoadAPIParams(v) + params, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) assert.Equal(t, "my-machine", params.Hostname) @@ -2347,7 +2356,7 @@ func TestLoadAPIParams_Hostname_FromConfig(t *testing.T) { v.Set("key", "00000000-0000-4000-8000-000000000000") v.Set("settings.hostname", "my-machine") - params, err := paramscmd.LoadAPIParams(v) + params, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) assert.Equal(t, "my-machine", params.Hostname) @@ -2363,7 +2372,7 @@ func TestLoadAPIParams_Hostname_ConfigTakesPrecedence(t *testing.T) { defer os.Unsetenv("GITPOD_WORKSPACE_ID") - params, err := paramscmd.LoadAPIParams(v) + params, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) assert.Equal(t, "my-machine", params.Hostname) @@ -2378,7 +2387,7 @@ func TestLoadAPIParams_Hostname_FromGitpodEnv(t *testing.T) { defer os.Unsetenv("GITPOD_WORKSPACE_ID") - params, err := paramscmd.LoadAPIParams(v) + params, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) assert.Equal(t, "Gitpod", params.Hostname) @@ -2388,7 +2397,7 @@ func TestLoadAPIParams_Hostname_DefaultFromSystem(t *testing.T) { v := viper.New() v.Set("key", "00000000-0000-4000-8000-000000000000") - params, err := paramscmd.LoadAPIParams(v) + params, err := cmdparams.LoadAPIParams(v) require.NoError(t, err) expected, err := os.Hostname() @@ -2402,7 +2411,7 @@ func TestLoadStatusBarParams_HideCategories_FlagTakesPrecedence(t *testing.T) { v.Set("today-hide-categories", true) v.Set("settings.status_bar_hide_categories", "ignored") - params, err := paramscmd.LoadStatusBarParams(v) + params, err := cmdparams.LoadStatusBarParams(v) require.NoError(t, err) assert.True(t, params.HideCategories) @@ -2412,7 +2421,7 @@ func TestLoadStatusBarParams_HideCategories_ConfigTakesPrecedence(t *testing.T) v := viper.New() v.Set("settings.status_bar_hide_categories", true) - params, err := paramscmd.LoadStatusBarParams(v) + params, err := cmdparams.LoadStatusBarParams(v) require.NoError(t, err) assert.True(t, params.HideCategories) @@ -2429,7 +2438,7 @@ func TestLoadStatusBarParams_Output(t *testing.T) { v := viper.New() v.Set("output", name) - params, err := paramscmd.LoadStatusBarParams(v) + params, err := cmdparams.LoadStatusBarParams(v) require.NoError(t, err) assert.Equal(t, out, params.Output) @@ -2440,7 +2449,7 @@ func TestLoadStatusBarParams_Output(t *testing.T) { func TestLoadStatusBarParams_Output_Default(t *testing.T) { v := viper.New() - params, err := paramscmd.LoadStatusBarParams(v) + params, err := cmdparams.LoadStatusBarParams(v) require.NoError(t, err) assert.Equal(t, output.TextOutput, params.Output) @@ -2450,7 +2459,7 @@ func TestLoadStatusBarParams_Output_Invalid(t *testing.T) { v := viper.New() v.Set("output", "invalid") - _, err := paramscmd.LoadStatusBarParams(v) + _, err := cmdparams.LoadStatusBarParams(v) require.Error(t, err) assert.Equal(t, "failed to parse output: invalid output \"invalid\"", err.Error()) @@ -2460,7 +2469,7 @@ func TestAPI_String(t *testing.T) { backoffat, err := time.Parse(inipkg.DateFormat, "2021-08-30T18:50:42-03:00") require.NoError(t, err) - api := paramscmd.API{ + api := cmdparams.API{ BackoffAt: backoffat, BackoffRetries: 5, DisableSSLVerify: true, @@ -2490,7 +2499,7 @@ func TestAPI_String(t *testing.T) { } func TestFilterParams_String(t *testing.T) { - filterparams := paramscmd.FilterParams{ + filterparams := cmdparams.FilterParams{ Exclude: []regex.Regex{regex.MustCompile("^/exclude")}, ExcludeUnknownProject: true, Include: []regex.Regex{regex.MustCompile("^/include")}, @@ -2506,7 +2515,7 @@ func TestFilterParams_String(t *testing.T) { } func TestHeartbeat_String(t *testing.T) { - heartbeat := paramscmd.Heartbeat{ + heartbeat := cmdparams.Heartbeat{ Category: heartbeat.CodingCategory, CursorPosition: heartbeat.PointerTo(15), Entity: "path/to/entity.go", @@ -2542,7 +2551,7 @@ func TestOffline_String(t *testing.T) { lastSentAt, err := time.Parse(inipkg.DateFormat, "2021-08-30T18:50:42-03:00") require.NoError(t, err) - offline := paramscmd.Offline{ + offline := cmdparams.Offline{ Disabled: true, LastSentAt: lastSentAt, PrintMax: 6, @@ -2562,7 +2571,7 @@ func TestOffline_String(t *testing.T) { } func TestProjectParams_String(t *testing.T) { - projectparams := paramscmd.ProjectParams{ + projectparams := cmdparams.ProjectParams{ Alternate: "alternate", BranchAlternate: "branch-alternate", MapPatterns: []project.MapPattern{{Name: "project-1", Regex: regex.MustCompile("^/regex")}}, @@ -2585,14 +2594,14 @@ func TestLoadHeartbeatParams_ProjectFromGitRemote(t *testing.T) { v.Set("git.project_from_git_remote", true) v.Set("entity", "/path/to/file") - params, err := paramscmd.LoadHeartbeatParams(v) + params, err := cmdparams.LoadHeartbeatParams(v) require.NoError(t, err) assert.True(t, params.Project.ProjectFromGitRemote) } func TestSanitizeParams_String(t *testing.T) { - sanitizeparams := paramscmd.SanitizeParams{ + sanitizeparams := cmdparams.SanitizeParams{ HideBranchNames: []regex.Regex{regex.MustCompile("^/hide")}, HideProjectFolder: true, HideFileNames: []regex.Regex{regex.MustCompile("^/hide")}, @@ -2609,7 +2618,7 @@ func TestSanitizeParams_String(t *testing.T) { } func TestStatusBar_String(t *testing.T) { - statusbar := paramscmd.StatusBar{ + statusbar := cmdparams.StatusBar{ HideCategories: true, Output: output.JSONOutput, }