Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Watch
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Container Registry
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSS
Libraries
Go
Utilities
Watch
Commits
e2701d8a
Verified
Commit
e2701d8a
authored
6 months ago
by
Volker Schukai
Browse files
Options
Downloads
Patches
Plain Diff
fix: test should use temp (flake is readonly
parent
7d8ca14e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
hash_test.go
+19
-22
19 additions, 22 deletions
hash_test.go
nix/config/release.nix
+1
-1
1 addition, 1 deletion
nix/config/release.nix
with
20 additions
and
23 deletions
hash_test.go
+
19
−
22
View file @
e2701d8a
...
@@ -5,6 +5,7 @@ package watch
...
@@ -5,6 +5,7 @@ package watch
import
(
import
(
"os"
"os"
"path/filepath"
"testing"
"testing"
"time"
"time"
)
)
...
@@ -95,11 +96,10 @@ func TestFileHashing(t *testing.T) {
...
@@ -95,11 +96,10 @@ func TestFileHashing(t *testing.T) {
t
.
Errorf
(
"Expected Has to return true, got false"
)
t
.
Errorf
(
"Expected Has to return true, got false"
)
}
}
}
}
func
TestAddAndRemoveFileHash
(
t
*
testing
.
T
)
{
func
TestAddAndRemoveFileHash
(
t
*
testing
.
T
)
{
// Test cases
// Test cases
testCases
:=
[]
struct
{
testCases
:=
[]
struct
{
path
string
fileName
string
shouldExist
bool
shouldExist
bool
sleepTime
time
.
Duration
sleepTime
time
.
Duration
expectedErr
error
expectedErr
error
...
@@ -110,10 +110,18 @@ func TestAddAndRemoveFileHash(t *testing.T) {
...
@@ -110,10 +110,18 @@ func TestAddAndRemoveFileHash(t *testing.T) {
{
"testfile1.txt"
,
true
,
2
*
time
.
Second
,
nil
},
// Test expiration
{
"testfile1.txt"
,
true
,
2
*
time
.
Second
,
nil
},
// Test expiration
}
}
// Create test files
// Create a temporary directory for test files
tempDir
,
err
:=
os
.
MkdirTemp
(
""
,
"testdir"
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to create temp directory: %v"
,
err
)
}
defer
os
.
RemoveAll
(
tempDir
)
// Clean up the temp directory at the end
// Create test files in the temp directory
for
_
,
tc
:=
range
testCases
{
for
_
,
tc
:=
range
testCases
{
if
tc
.
shouldExist
{
if
tc
.
shouldExist
{
file
,
err
:=
os
.
Create
(
tc
.
path
)
filePath
:=
filepath
.
Join
(
tempDir
,
tc
.
fileName
)
file
,
err
:=
os
.
Create
(
filePath
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
...
@@ -122,18 +130,12 @@ func TestAddAndRemoveFileHash(t *testing.T) {
...
@@ -122,18 +130,12 @@ func TestAddAndRemoveFileHash(t *testing.T) {
}
}
for
_
,
tc
:=
range
testCases
{
for
_
,
tc
:=
range
testCases
{
if
tc
.
shouldExist
{
filePath
:=
filepath
.
Join
(
tempDir
,
tc
.
fileName
)
file
,
err
:=
os
.
Create
(
tc
.
path
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
// Stop the test if the file cannot be created
}
_
=
file
.
Close
()
}
//Add hash
//Add hash
err
:=
AddFileHash
(
tc
.
p
ath
)
err
:=
AddFileHash
(
fileP
ath
)
if
err
!=
tc
.
expectedErr
{
if
err
!=
tc
.
expectedErr
{
t
.
Errorf
(
"Add(%q) error: got %v, want %v"
,
tc
.
p
ath
,
err
,
tc
.
expectedErr
)
t
.
Errorf
(
"Add(%q) error: got %v, want %v"
,
fileP
ath
,
err
,
tc
.
expectedErr
)
}
}
if
tc
.
sleepTime
>
0
{
if
tc
.
sleepTime
>
0
{
...
@@ -141,19 +143,14 @@ func TestAddAndRemoveFileHash(t *testing.T) {
...
@@ -141,19 +143,14 @@ func TestAddAndRemoveFileHash(t *testing.T) {
}
}
// Remove hash
// Remove hash
err
=
RemoveFileHash
(
tc
.
p
ath
)
err
=
RemoveFileHash
(
fileP
ath
)
if
err
!=
tc
.
expectedErr
{
if
err
!=
tc
.
expectedErr
{
t
.
Errorf
(
"Remove(%q) error: got %v, want %v"
,
tc
.
p
ath
,
err
,
tc
.
expectedErr
)
t
.
Errorf
(
"Remove(%q) error: got %v, want %v"
,
fileP
ath
,
err
,
tc
.
expectedErr
)
}
}
_
,
ok
:=
watcherImpl
.
cache
.
Load
(
tc
.
p
ath
)
_
,
ok
:=
watcherImpl
.
cache
.
Load
(
fileP
ath
)
if
ok
{
if
ok
{
t
.
Errorf
(
"Remove(%q) failed: value still exists in cache"
,
tc
.
path
)
t
.
Errorf
(
"Remove(%q) failed: value still exists in cache"
,
filePath
)
}
// Delete test files
if
tc
.
shouldExist
{
_
=
os
.
Remove
(
tc
.
path
)
}
}
}
}
}
}
This diff is collapsed.
Click to expand it.
nix/config/release.nix
+
1
−
1
View file @
e2701d8a
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
# please don't edit it manually
# please don't edit it manually
version
=
"0.4.0"
;
version
=
"0.4.0"
;
commit
=
"
06935e5d8a7a9cae337241a19903c7a4bd149002
"
;
commit
=
"
7d8ca14e254c24b813596cbe516da7233f3ae83d
"
;
projectURL
=
"https://gitlab.schukai.com/oss/libraries/go/utilities/watch"
;
projectURL
=
"https://gitlab.schukai.com/oss/libraries/go/utilities/watch"
;
name
=
"Watch"
;
name
=
"Watch"
;
mnemonic
=
"watch"
;
mnemonic
=
"watch"
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment