Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
FriendlyForgeFormat
gofff
Commits
c4717fe5
Verified
Commit
c4717fe5
authored
Apr 24, 2022
by
Loïc Dachary
Browse files
forges: file: add fixtures functions instead of static files
parent
17cc5d1e
Pipeline
#991
failed with stage
in 1 minute and 30 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
forges/file/file_test.go
View file @
c4717fe5
...
...
@@ -17,56 +17,35 @@ package file
import
(
"bytes"
"os/exec"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
func
assertFileEquals
(
t
*
testing
.
T
,
a
,
b
*
File
,
filename
string
)
{
fa
:=
filepath
.
Join
(
a
.
options
.
Directory
,
filename
)
fb
:=
filepath
.
Join
(
b
.
options
.
Directory
,
filename
)
cmd
:=
exec
.
Command
(
"diff"
,
"-r"
,
fa
,
fb
)
func
assertFileEquals
(
t
*
testing
.
T
,
a
,
b
*
File
)
{
cmd
:=
exec
.
Command
(
"diff"
,
"-r"
,
a
.
options
.
Directory
,
b
.
options
.
Directory
)
var
out
bytes
.
Buffer
cmd
.
Stdout
=
&
out
cmd
.
Stderr
=
&
out
assert
.
NoError
(
t
,
cmd
.
Run
(),
out
.
String
())
}
func
originalAndCopy
(
t
*
testing
.
T
)
(
original
,
copy
*
File
)
{
tmpDir
:=
t
.
TempDir
()
copy
=
&
File
{}
copy
.
Init
(
Options
{
Directory
:
tmpDir
,
Validation
:
true
,
})
func
TestFile
(
t
*
testing
.
T
)
{
fixture
:=
NewFixture
(
t
)
fixture
.
CreateProject
()
original
=
&
File
{}
original
.
Init
(
Options
{
Directory
:
"testdata/repo1"
})
return
}
func
TestFileProject
(
t
*
testing
.
T
)
{
original
,
copy
:=
originalAndCopy
(
t
)
copy
.
CreateProject
(
original
.
GetProject
())
assert
.
EqualValues
(
t
,
original
.
GetProject
(),
copy
.
GetProject
())
assertFileEquals
(
t
,
copy
,
original
,
"project.json"
)
}
func
TestFileIssues
(
t
*
testing
.
T
)
{
original
,
copy
:=
originalAndCopy
(
t
)
original
,
copy
:=
fixture
.
OriginalAndCopy
()
assert
.
NotEmpty
(
t
,
original
.
GetIssues
())
copy
.
CreateIssues
(
original
.
GetIssues
()
...
)
assert
.
EqualValues
(
t
,
original
.
GetIssues
(),
copy
.
GetIssues
())
assertFileEquals
(
t
,
copy
,
original
,
"issue.json"
)
}
func
TestFileReleases
(
t
*
testing
.
T
)
{
original
,
copy
:=
originalAndCopy
(
t
)
assert
.
NotEmpty
(
t
,
original
.
GetReleases
())
copy
.
CreateReleases
(
original
.
GetReleases
()
...
)
assert
.
EqualValues
(
t
,
original
.
GetReleases
(),
copy
.
GetReleases
())
assertFileEquals
(
t
,
copy
,
original
,
"release.json"
)
copy
.
CreateProject
(
original
.
GetProject
())
assert
.
EqualValues
(
t
,
original
.
GetProject
(),
copy
.
GetProject
())
assertFileEquals
(
t
,
copy
,
original
)
}
forges/file/fixtures.go
0 → 100644
View file @
c4717fe5
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
package
file
import
(
"testing"
"time"
"lab.forgefriends.org/friendlyforgeformat/gofff/format"
)
type
Fixture
struct
{
t
*
testing
.
T
d
string
f
*
File
}
func
NewFixture
(
t
*
testing
.
T
)
*
Fixture
{
directory
:=
t
.
TempDir
()
f
:=
&
File
{}
f
.
Init
(
Options
{
Directory
:
directory
})
return
&
Fixture
{
t
:
t
,
d
:
directory
,
f
:
f
,
}
}
func
(
f
*
Fixture
)
OriginalAndCopy
()
(
original
,
copy
*
File
)
{
copy
=
&
File
{}
copy
.
Init
(
Options
{
Directory
:
f
.
t
.
TempDir
(),
Validation
:
true
,
})
original
=
f
.
f
return
}
func
(
f
*
Fixture
)
CreateProject
()
{
project
:=
&
format
.
Project
{
Index
:
1
,
Name
:
"projectname"
,
Owner
:
"root"
,
IsPrivate
:
false
,
IsMirror
:
false
,
Description
:
"project description"
,
CloneURL
:
"https://example.com/clone"
,
OriginalURL
:
"https://example.com/original"
,
DefaultBranch
:
"main"
,
}
f
.
f
.
CreateProject
(
project
)
type
User
struct
{
id
int64
name
string
email
string
}
user1
:=
User
{
1
,
"user1"
,
"user1@example.com"
}
now
:=
time
.
Now
()
tick
:=
time
.
Duration
(
1
)
tick
++
updated
:=
now
.
Add
(
tick
)
tick
++
closed
:=
now
.
Add
(
tick
)
tick
++
created
:=
now
.
Add
(
tick
)
issues
:=
[]
*
format
.
Issue
{
{
Number
:
1
,
PosterID
:
user1
.
id
,
PosterName
:
user1
.
name
,
PosterEmail
:
user1
.
email
,
Title
:
"title"
,
Content
:
"content"
,
Milestone
:
"milestone"
,
State
:
"closed"
,
IsLocked
:
false
,
Created
:
created
,
Updated
:
updated
,
Closed
:
&
closed
,
Ref
:
""
,
},
}
f
.
f
.
CreateIssues
(
issues
...
)
tick
++
releaseCreated
:=
now
.
Add
(
tick
)
tick
++
releasePublished
:=
now
.
Add
(
tick
)
tick
++
assetCreated
:=
now
.
Add
(
tick
)
tick
++
assetUpdated
:=
now
.
Add
(
tick
)
size
:=
50
downloadCount
:=
10
contentType
:=
"application/zip"
downloadURL
:=
"https://example.com/asset5"
releases
:=
[]
*
format
.
Release
{
{
TagName
:
"tag"
,
TargetCommitish
:
"stable"
,
Name
:
"v12 name"
,
Body
:
"v12 body"
,
Draft
:
false
,
Prerelease
:
false
,
PublisherID
:
user1
.
id
,
PublisherName
:
user1
.
name
,
PublisherEmail
:
user1
.
email
,
Assets
:
[]
*
format
.
ReleaseAsset
{
{
ID
:
5
,
Name
:
"asset 5"
,
ContentType
:
&
contentType
,
Size
:
&
size
,
DownloadCount
:
&
downloadCount
,
Created
:
assetCreated
,
Updated
:
assetUpdated
,
DownloadURL
:
&
downloadURL
,
},
},
Created
:
releaseCreated
,
Published
:
releasePublished
,
},
}
f
.
f
.
CreateReleases
(
releases
...
)
}
forges/file/testdata/repo1/comments/1.json
deleted
100644 → 0
View file @
17cc5d1e
[
{
"issue_index"
:
1
,
"index"
:
5
,
"poster_id"
:
1
,
"poster_name"
:
"name_a"
,
"poster_email"
:
"email_a"
,
"created"
:
"1985-04-12T23:20:50.52Z"
,
"updated"
:
"1986-04-12T23:20:50.52Z"
,
"content"
:
"comment_content_5"
,
"reactions"
:
null
}
]
forges/file/testdata/repo1/issue.json
deleted
100644 → 0
View file @
17cc5d1e
[
{
"number"
:
1
,
"poster_id"
:
1
,
"poster_name"
:
"name_a"
,
"poster_email"
:
"email_a"
,
"title"
:
"title_a"
,
"content"
:
"content_a"
,
"milestone"
:
""
,
"state"
:
"closed"
,
"is_locked"
:
false
,
"created"
:
"1985-04-12T23:20:50.52Z"
,
"updated"
:
"1986-04-12T23:20:50.52Z"
,
"closed"
:
"1987-04-12T23:20:50.52Z"
,
"labels"
:
null
,
"reactions"
:
null
,
"assignees"
:
null
,
"ref"
:
""
}
]
forges/file/testdata/repo1/project.json
deleted
100644 → 0
View file @
17cc5d1e
{
"index"
:
1
,
"name"
:
"projectname"
,
"owner"
:
"root"
,
"is_private"
:
false
,
"is_mirror"
:
true
,
"description"
:
"project description"
,
"clone_url"
:
"https://example.com/clone"
,
"original_url"
:
"https://example.com/original"
,
"default_branch"
:
"main"
}
forges/file/testdata/repo1/release.json
deleted
100644 → 0
View file @
17cc5d1e
[
{
"tag_name"
:
"v12"
,
"target_commitish"
:
"stable"
,
"name"
:
"v12 name"
,
"body"
:
"v12 body"
,
"draft"
:
false
,
"prerelease"
:
false
,
"publisher_id"
:
1
,
"publisher_name"
:
"name_1"
,
"publisher_email"
:
"email_1"
,
"assets"
:
[
{
"id"
:
5
,
"name"
:
"asset_5"
,
"content_type"
:
"application/zip"
,
"size"
:
50
,
"download_count"
:
10
,
"created"
:
"1985-04-12T23:20:50.52Z"
,
"updated"
:
"1986-04-12T23:20:50.52Z"
,
"download_url"
:
"url_asset_5"
}
],
"created"
:
"1985-04-12T23:20:50.52Z"
,
"published"
:
"1985-04-12T23:20:50.52Z"
}
]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment