A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/orgrim/pg_back/commit/965b06872874f9655701a03d66fcfb45f6bee3ab below:

Fix or skip tests on windows and macos · orgrim/pg_back@965b068 · GitHub

@@ -30,6 +30,7 @@ import (

30 30

"io/ioutil"

31 31

"os"

32 32

"path/filepath"

33 +

"runtime"

33 34

"testing"

34 35

"time"

35 36

)

@@ -43,49 +44,63 @@ func TestPurgeDumps(t *testing.T) {

43 44

}

44 45

defer os.RemoveAll(dir)

45 46 46 -

// empty path

47 +

// empty path - on windows chmod does not work as expected

47 48

wd := filepath.Join(dir, "real", "bad")

48 49

if err := os.MkdirAll(wd, 0755); err != nil {

49 50

t.Fatal("could not create test dir")

50 51

}

51 -

os.Chmod(filepath.Dir(wd), 0444)

52 -

err = purgeDumps(wd, "", 0, time.Time{})

53 -

if err == nil {

54 -

t.Errorf("empty path gave error <nil>\n")

52 + 53 +

if runtime.GOOS != "windows" {

54 +

os.Chmod(filepath.Dir(wd), 0444)

55 +

err = purgeDumps(wd, "", 0, time.Time{})

56 +

if err == nil {

57 +

t.Errorf("empty path gave error <nil>\n")

58 +

}

59 +

os.Chmod(filepath.Dir(wd), 0755)

55 60

}

56 -

os.Chmod(filepath.Dir(wd), 0755)

57 61 58 62

// empty dbname

59 -

tf := formatDumpPath(wd, time.RFC3339, "dump", "", time.Now().Add(-time.Hour))

63 +

when := time.Now().Add(-time.Hour)

64 +

tf := formatDumpPath(wd, "2006-01-02_15-04-05", "dump", "", when)

65 +

f, err := os.Create(tf)

66 +

if err != nil {

67 +

t.Errorf("could not create temp file %s: %s", tf, err)

68 +

}

69 + 70 +

f.Close()

71 +

os.Chtimes(tf, when, when)

72 + 60 73

err = purgeDumps(wd, "", 0, time.Now())

61 74

if err != nil {

62 -

t.Errorf("empty dbname gave error %s", err)

75 +

t.Errorf("empty dbname (file: %s) gave error %s", tf, err)

63 76

}

64 77

if _, err := os.Stat(tf); err == nil {

65 78

t.Errorf("file still exists")

66 79

}

67 80 68 81

// file without write perms

69 -

tf = formatDumpPath(wd, time.RFC3339, "dump", "db", time.Now().Add(-time.Hour))

70 -

ioutil.WriteFile(tf, []byte("truc\n"), 0644)

71 -

os.Chmod(filepath.Dir(tf), 0555)

82 +

if runtime.GOOS != "windows" {

83 +

tf = formatDumpPath(wd, time.RFC3339, "dump", "db", time.Now().Add(-time.Hour))

84 +

ioutil.WriteFile(tf, []byte("truc\n"), 0644)

85 +

os.Chmod(filepath.Dir(tf), 0555)

72 86 73 -

err = purgeDumps(wd, "db", 0, time.Now())

74 -

if err == nil {

75 -

t.Errorf("bad perms on file did not gave an error")

76 -

}

77 -

os.Chmod(filepath.Dir(tf), 0755)

87 +

err = purgeDumps(wd, "db", 0, time.Now())

88 +

if err == nil {

89 +

t.Errorf("bad perms on file did not gave an error")

90 +

}

91 +

os.Chmod(filepath.Dir(tf), 0755)

78 92 79 -

// dir without write perms

80 -

tf = formatDumpPath(wd, time.RFC3339, "d", "db", time.Now().Add(-time.Hour))

81 -

os.MkdirAll(tf, 0755)

82 -

os.Chmod(filepath.Dir(tf), 0555)

93 +

// dir without write perms

94 +

tf = formatDumpPath(wd, time.RFC3339, "d", "db", time.Now().Add(-time.Hour))

95 +

os.MkdirAll(tf, 0755)

96 +

os.Chmod(filepath.Dir(tf), 0555)

83 97 84 -

err = purgeDumps(wd, "db", 0, time.Now())

85 -

if err == nil {

86 -

t.Errorf("bad perms on dir did not gave an error")

98 +

err = purgeDumps(wd, "db", 0, time.Now())

99 +

if err == nil {

100 +

t.Errorf("bad perms on dir did not gave an error")

101 +

}

102 +

os.Chmod(filepath.Dir(tf), 0755)

87 103

}

88 -

os.Chmod(filepath.Dir(tf), 0755)

89 104 90 105

// time and keep limits

91 106

var tests = []struct {

@@ -111,7 +126,7 @@ func TestPurgeDumps(t *testing.T) {

111 126

}

112 127

for i := 1; i <= 3; i++ {

113 128

when := time.Now().Add(-time.Hour * time.Duration(i))

114 -

tf = formatDumpPath(wd, time.RFC3339, "dump", "db", when)

129 +

tf = formatDumpPath(wd, "2006-01-02_15-04-05", "dump", "db", when)

115 130

ioutil.WriteFile(tf, []byte("truc\n"), 0644)

116 131

os.Chtimes(tf, when, when)

117 132

}


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4