Skip to content

Commit

Permalink
fixup! Cleanup tests and remove unused pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
gandarez committed Jul 28, 2024
1 parent deafaf7 commit 404d750
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 32 deletions.
14 changes: 12 additions & 2 deletions cmd/heartbeat/heartbeat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -847,8 +847,13 @@ func TestSendHeartbeats_ErrBackoff(t *testing.T) {

defer logFile.Close()

v := viper.New()
tmpFile, err := os.CreateTemp(tmpDir, "wakatime")
require.NoError(t, err)

defer tmpFile.Close()

v := viper.New()
v.Set("internal-config", tmpFile.Name())
v.Set("internal.backoff_at", time.Now().Add(10*time.Minute).Format(ini.DateFormat))
v.Set("internal.backoff_retries", "1")
v.SetDefault("sync-offline-activity", 1000)
Expand Down Expand Up @@ -912,8 +917,13 @@ func TestSendHeartbeats_ErrBackoff_Verbose(t *testing.T) {

defer logFile.Close()

v := viper.New()
tmpFile, err := os.CreateTemp(tmpDir, "wakatime")
require.NoError(t, err)

defer tmpFile.Close()

v := viper.New()
v.Set("internal-config", tmpFile.Name())
v.Set("internal.backoff_at", time.Now().Add(10*time.Minute).Format(ini.DateFormat))
v.Set("internal.backoff_retries", "1")
v.SetDefault("sync-offline-activity", 1000)
Expand Down
6 changes: 6 additions & 0 deletions cmd/offlinesync/offlinesync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,15 @@ func TestRunWithoutRateLimiting(t *testing.T) {
func TestRunWithRateLimiting_RateLimited(t *testing.T) {
resetSingleton(t)

tmpFile, err := os.CreateTemp(t.TempDir(), "wakatime")
require.NoError(t, err)

defer tmpFile.Close()

v := viper.New()
v.Set("key", "00000000-0000-4000-8000-000000000000")
v.Set("heartbeat-rate-limit-seconds", 500)
v.Set("internal-config", tmpFile.Name())
v.Set("internal.heartbeats_last_sent_at", time.Now().Add(-time.Minute).Format(time.RFC3339))

code, err := offlinesync.RunWithRateLimiting(v)
Expand Down
21 changes: 12 additions & 9 deletions cmd/run_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"net/http"
"net/http/httptest"
"os"
"runtime"
"testing"
"time"

Expand Down Expand Up @@ -111,10 +110,6 @@ func TestRunCmd_ErrOfflineEnqueue(t *testing.T) {
}

func TestRunCmd_BackoffLoggedWithVerbose(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Skipping because OS is windows.")
}

verbose := true

testServerURL, router, tearDown := setupTestServer()
Expand All @@ -135,6 +130,11 @@ func TestRunCmd_BackoffLoggedWithVerbose(t *testing.T) {

defer logFile.Close()

tmpFile, err := os.CreateTemp(tmpDir, "wakatime")
require.NoError(t, err)

defer tmpFile.Close()

offlineQueueFile, err := os.CreateTemp(tmpDir, "")
require.NoError(t, err)

Expand All @@ -151,6 +151,7 @@ func TestRunCmd_BackoffLoggedWithVerbose(t *testing.T) {
v.Set("key", "00000000-0000-4000-8000-000000000000")
v.Set("log-file", logFile.Name())
v.Set("offline-queue-file", offlineQueueFile.Name())
v.Set("internal-config", tmpFile.Name())
v.Set("internal.backoff_at", time.Now().Add(10*time.Minute).Format(ini.DateFormat))
v.Set("internal.backoff_retries", "1")
v.Set("verbose", verbose)
Expand All @@ -174,10 +175,6 @@ func TestRunCmd_BackoffLoggedWithVerbose(t *testing.T) {
}

func TestRunCmd_BackoffNotLogged(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Skipping because OS is windows.")
}

verbose := false

testServerURL, router, tearDown := setupTestServer()
Expand All @@ -203,6 +200,11 @@ func TestRunCmd_BackoffNotLogged(t *testing.T) {

defer logFile.Close()

tmpFile, err := os.CreateTemp(tmpDir, "wakatime")
require.NoError(t, err)

defer tmpFile.Close()

entity, err := os.CreateTemp(tmpDir, "")
require.NoError(t, err)

Expand All @@ -214,6 +216,7 @@ func TestRunCmd_BackoffNotLogged(t *testing.T) {
v.Set("key", "00000000-0000-4000-8000-000000000000")
v.Set("log-file", logFile.Name())
v.Set("offline-queue-file", offlineQueueFile.Name())
v.Set("internal-config", tmpFile.Name())
v.Set("internal.backoff_at", time.Now().Add(10*time.Minute).Format(ini.DateFormat))
v.Set("internal.backoff_retries", "1")
v.Set("verbose", verbose)
Expand Down
4 changes: 0 additions & 4 deletions pkg/project/tfvc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ import (
)

func TestTfvc_Detect(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Skipping because OS is windows.")
}

fp := setupTestTfvc(t, ".tf")

s := project.Tfvc{
Expand Down
17 changes: 0 additions & 17 deletions pkg/remote/remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"os"
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -64,10 +63,6 @@ func TestNewClient_Err(t *testing.T) {
}

func TestWithDetection_SshConfig_Hostname(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Skipping because OS is Windows.")
}

shutdown, host, port := testServer(t, false)
defer shutdown()

Expand Down Expand Up @@ -133,10 +128,6 @@ func TestWithDetection_SshConfig_Hostname(t *testing.T) {
}

func TestWithDetection_SshConfig_UserKnownHostsFile_Mismatch(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Skipping because OS is Windows.")
}

logs := bytes.NewBuffer(nil)

teardownLogCapture := captureLogs(logs)
Expand Down Expand Up @@ -199,10 +190,6 @@ func TestWithDetection_SshConfig_UserKnownHostsFile_Mismatch(t *testing.T) {
}

func TestWithDetection_SshConfig_UserKnownHostsFile_Match(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Skipping because OS is Windows.")
}

logs := bytes.NewBuffer(nil)

teardownLogCapture := captureLogs(logs)
Expand Down Expand Up @@ -282,10 +269,6 @@ func TestWithDetection_SshConfig_UserKnownHostsFile_Match(t *testing.T) {
}

func TestWithDetection_Filtered(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Skipping because OS is Windows.")
}

logs := bytes.NewBuffer(nil)

teardownLogCapture := captureLogs(logs)
Expand Down

0 comments on commit 404d750

Please sign in to comment.