Skip to content

Commit

Permalink
fix remaining unit tests failing in Windows (#360)
Browse files Browse the repository at this point in the history
  • Loading branch information
creativeprojects committed Apr 6, 2024
1 parent e6eed3d commit 16f5dc5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/capnspacehook/taskmaster v0.0.0-20210519235353-1629df7c85e9
github.com/coreos/go-systemd/v22 v22.5.0
github.com/creativeprojects/clog v0.14.0
github.com/creativeprojects/go-selfupdate v1.1.4
github.com/creativeprojects/go-selfupdate v1.2.0
github.com/distatus/battery v0.11.0
github.com/fatih/color v1.16.0
github.com/joho/godotenv v1.5.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/creativeprojects/clog v0.14.0 h1:kthfMG6efS9kI4ACgYRIOPZ2efQkXvW7VhqZigCtpzU=
github.com/creativeprojects/clog v0.14.0/go.mod h1:iHLlN4sZU+o5rRiFab6ZGHs2vApq09DyykMVJ2Sflro=
github.com/creativeprojects/go-selfupdate v1.1.4 h1:6/+Wfg08lXAbmU/qEU0v9W4w5Wp6TWf9x2DAttZEwzg=
github.com/creativeprojects/go-selfupdate v1.1.4/go.mod h1:zCTXcZolcs0Cw9WsfXZvlcX9AupkAlikQ14PQqIV2v0=
github.com/creativeprojects/go-selfupdate v1.2.0 h1:sHpsnSJuSxQ6pua32c+86Izm+nG1jEKPo3UP/MAE6IM=
github.com/creativeprojects/go-selfupdate v1.2.0/go.mod h1:zCTXcZolcs0Cw9WsfXZvlcX9AupkAlikQ14PQqIV2v0=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
Expand Down
13 changes: 6 additions & 7 deletions restic/downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package restic

import (
"context"
"fmt"
"path"
"path/filepath"
"testing"

sup "github.com/creativeprojects/go-selfupdate"
"github.com/creativeprojects/resticprofile/platform"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestDownloadBinary(t *testing.T) {
Expand All @@ -16,8 +17,6 @@ func TestDownloadBinary(t *testing.T) {
t.Skip()
}

temp := t.TempDir()

versions := []string{
"latest",
"0.13.0",
Expand All @@ -28,12 +27,12 @@ func TestDownloadBinary(t *testing.T) {
version := version
t.Run(version, func(t *testing.T) {
t.Parallel()
executable := path.Join(temp, fmt.Sprintf("restic-%s", version))
executable := platform.Executable(filepath.Join(t.TempDir(), "restic"))
err := DownloadBinary(executable, version)
assert.NoError(t, err)
require.NoError(t, err)

actualVersion, err := GetVersion(executable)
assert.NoError(t, err)
require.NoError(t, err)
assert.NotEmpty(t, actualVersion)
if version == "latest" {
assert.NotEqual(t, version, actualVersion)
Expand Down
16 changes: 12 additions & 4 deletions util/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package util

import (
"os"
"slices"
"strings"
"testing"

Expand All @@ -15,12 +16,19 @@ func TestCanReadOsEnv(t *testing.T) {

// All values are included
for _, value := range os.Environ() {
kv := strings.SplitN(value, "=", 2)
assert.Equal(t, kv[1], env.Get(strings.TrimSpace(kv[0])))
key, value, found := strings.Cut(value, "=")
key = strings.TrimSpace(key)
if found && key != "" {
assert.Equalf(t, value, env.Get(key), "key %q", key)
}
}

// Elements are retained like specified
assert.ElementsMatch(t, env.Values(), os.Environ())
// Elements are retained like specified, except for some strange values in cmd.exe
// https://stackoverflow.com/questions/10431689/what-are-these-strange-environment-variables
assert.ElementsMatch(t, env.Values(), slices.DeleteFunc(os.Environ(), func(value string) bool {
return strings.HasPrefix(value, "=")
}))

}

func TestEnvironmentPreservesCase(t *testing.T) {
Expand Down

0 comments on commit 16f5dc5

Please sign in to comment.