2024-06-08 05:02:35 +00:00
|
|
|
package config_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
2024-08-14 02:55:18 +00:00
|
|
|
"github.com/badjware/gitforgefs/config"
|
2024-06-08 05:02:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestLoadConfig(t *testing.T) {
|
|
|
|
tests := map[string]struct {
|
|
|
|
input string
|
|
|
|
expected *config.Config
|
|
|
|
}{
|
|
|
|
"LoadConfig": {
|
|
|
|
input: "config.test.yaml",
|
|
|
|
expected: &config.Config{
|
|
|
|
FS: config.FSConfig{
|
2024-08-14 02:55:18 +00:00
|
|
|
Mountpoint: "/tmp/gitforgefs/test/mnt/gitlab",
|
2024-06-08 05:02:35 +00:00
|
|
|
MountOptions: "nodev",
|
2024-08-05 01:45:51 +00:00
|
|
|
Forge: "gitlab",
|
2024-06-08 05:02:35 +00:00
|
|
|
},
|
2024-08-04 19:44:50 +00:00
|
|
|
Gitlab: config.GitlabClientConfig{
|
2024-07-18 04:25:13 +00:00
|
|
|
URL: "https://example.com",
|
|
|
|
Token: "12345",
|
|
|
|
PullMethod: "ssh",
|
|
|
|
GroupIDs: []int{123},
|
2024-08-14 04:01:47 +00:00
|
|
|
UserNames: []int{456},
|
2024-07-18 04:25:13 +00:00
|
|
|
ArchivedProjectHandling: "hide",
|
|
|
|
IncludeCurrentUser: true,
|
2024-06-08 05:02:35 +00:00
|
|
|
},
|
2024-08-04 19:44:50 +00:00
|
|
|
Github: config.GithubClientConfig{
|
|
|
|
Token: "12345",
|
|
|
|
PullMethod: "http",
|
|
|
|
OrgNames: []string{"test-org"},
|
|
|
|
UserNames: []string{"test-user"},
|
|
|
|
ArchivedRepoHandling: "hide",
|
|
|
|
IncludeCurrentUser: true,
|
|
|
|
},
|
2024-08-09 20:13:57 +00:00
|
|
|
Gitea: config.GiteaClientConfig{
|
|
|
|
URL: "https://example.com",
|
|
|
|
Token: "12345",
|
|
|
|
PullMethod: "http",
|
|
|
|
OrgNames: []string{"test-org"},
|
|
|
|
UserNames: []string{"test-user"},
|
|
|
|
ArchivedRepoHandling: "hide",
|
|
|
|
IncludeCurrentUser: true,
|
|
|
|
},
|
2024-08-04 19:44:50 +00:00
|
|
|
Git: config.GitClientConfig{
|
2024-08-14 02:55:18 +00:00
|
|
|
CloneLocation: "/tmp/gitforgefs/test/cache/gitlab",
|
2024-06-08 05:02:35 +00:00
|
|
|
Remote: "origin",
|
|
|
|
OnClone: "clone",
|
|
|
|
AutoPull: false,
|
|
|
|
Depth: 0,
|
|
|
|
QueueSize: 100,
|
|
|
|
QueueWorkerCount: 1,
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, test := range tests {
|
|
|
|
test := test
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
got, err := config.LoadConfig(test.input)
|
|
|
|
expected := test.expected
|
|
|
|
if !reflect.DeepEqual(got, expected) {
|
|
|
|
t.Fatalf("LoadConfig(%v) returned %v; expected %v; error: %v", test.input, got, expected, err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMakeGitConfig(t *testing.T) {
|
|
|
|
tests := map[string]struct {
|
|
|
|
input *config.Config
|
2024-08-04 19:44:50 +00:00
|
|
|
expected *config.GitClientConfig
|
2024-06-08 05:02:35 +00:00
|
|
|
}{
|
|
|
|
"ValidConfig": {
|
|
|
|
input: &config.Config{
|
2024-08-04 19:44:50 +00:00
|
|
|
FS: config.FSConfig{
|
2024-08-05 01:45:51 +00:00
|
|
|
Forge: "gitlab",
|
2024-08-04 19:44:50 +00:00
|
|
|
},
|
|
|
|
Git: config.GitClientConfig{
|
2024-06-08 05:02:35 +00:00
|
|
|
CloneLocation: "/tmp",
|
|
|
|
Remote: "origin",
|
|
|
|
OnClone: "init",
|
|
|
|
AutoPull: false,
|
|
|
|
Depth: 0,
|
|
|
|
QueueSize: 200,
|
|
|
|
QueueWorkerCount: 5,
|
|
|
|
},
|
|
|
|
},
|
2024-08-04 19:44:50 +00:00
|
|
|
expected: &config.GitClientConfig{
|
2024-06-08 05:02:35 +00:00
|
|
|
CloneLocation: "/tmp",
|
|
|
|
Remote: "origin",
|
|
|
|
OnClone: "init",
|
|
|
|
AutoPull: false,
|
|
|
|
Depth: 0,
|
|
|
|
QueueSize: 200,
|
|
|
|
QueueWorkerCount: 5,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"InvalidOnClone": {
|
|
|
|
input: &config.Config{
|
2024-08-04 19:44:50 +00:00
|
|
|
FS: config.FSConfig{
|
2024-08-05 01:45:51 +00:00
|
|
|
Forge: "gitlab",
|
2024-08-04 19:44:50 +00:00
|
|
|
},
|
|
|
|
Git: config.GitClientConfig{
|
2024-06-08 05:02:35 +00:00
|
|
|
CloneLocation: "/tmp",
|
|
|
|
Remote: "origin",
|
|
|
|
OnClone: "invalid",
|
|
|
|
AutoPull: false,
|
|
|
|
Depth: 0,
|
|
|
|
QueueSize: 200,
|
|
|
|
QueueWorkerCount: 5,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: nil,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, test := range tests {
|
|
|
|
test := test
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
got, err := config.MakeGitConfig(test.input)
|
|
|
|
expected := test.expected
|
|
|
|
if !reflect.DeepEqual(got, expected) {
|
|
|
|
t.Fatalf("MakeGitConfig(%v) returned %v; expected %v; error %v", test.input, got, expected, err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMakeGitlabConfig(t *testing.T) {
|
|
|
|
tests := map[string]struct {
|
|
|
|
input *config.Config
|
2024-08-04 19:44:50 +00:00
|
|
|
expected *config.GitlabClientConfig
|
2024-06-08 05:02:35 +00:00
|
|
|
}{
|
|
|
|
"ValidConfig": {
|
|
|
|
input: &config.Config{
|
2024-08-04 19:44:50 +00:00
|
|
|
FS: config.FSConfig{
|
2024-08-05 01:45:51 +00:00
|
|
|
Forge: "gitlab",
|
2024-08-04 19:44:50 +00:00
|
|
|
},
|
|
|
|
Gitlab: config.GitlabClientConfig{
|
2024-07-18 04:25:13 +00:00
|
|
|
URL: "https://gitlab.com",
|
|
|
|
PullMethod: "http",
|
|
|
|
Token: "",
|
|
|
|
GroupIDs: []int{9970},
|
2024-08-14 04:01:47 +00:00
|
|
|
UserNames: []int{},
|
2024-07-18 04:25:13 +00:00
|
|
|
ArchivedProjectHandling: "hide",
|
|
|
|
IncludeCurrentUser: true,
|
2024-06-08 05:02:35 +00:00
|
|
|
},
|
|
|
|
},
|
2024-08-04 19:44:50 +00:00
|
|
|
expected: &config.GitlabClientConfig{
|
2024-07-18 04:25:13 +00:00
|
|
|
URL: "https://gitlab.com",
|
|
|
|
PullMethod: "http",
|
|
|
|
Token: "",
|
|
|
|
GroupIDs: []int{9970},
|
2024-08-14 04:01:47 +00:00
|
|
|
UserNames: []int{},
|
2024-07-18 04:25:13 +00:00
|
|
|
ArchivedProjectHandling: "hide",
|
|
|
|
IncludeCurrentUser: true,
|
2024-06-08 05:02:35 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
"InvalidPullMethod": {
|
|
|
|
input: &config.Config{
|
2024-08-04 19:44:50 +00:00
|
|
|
FS: config.FSConfig{
|
2024-08-05 01:45:51 +00:00
|
|
|
Forge: "gitlab",
|
2024-08-04 19:44:50 +00:00
|
|
|
},
|
|
|
|
Gitlab: config.GitlabClientConfig{
|
2024-07-18 04:25:13 +00:00
|
|
|
URL: "https://gitlab.com",
|
|
|
|
PullMethod: "invalid",
|
|
|
|
Token: "",
|
|
|
|
GroupIDs: []int{9970},
|
2024-08-14 04:01:47 +00:00
|
|
|
UserNames: []int{},
|
2024-07-18 04:25:13 +00:00
|
|
|
ArchivedProjectHandling: "hide",
|
|
|
|
IncludeCurrentUser: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: nil,
|
|
|
|
},
|
|
|
|
"InvalidArchiveHandling": {
|
|
|
|
input: &config.Config{
|
2024-08-04 19:44:50 +00:00
|
|
|
Gitlab: config.GitlabClientConfig{
|
2024-07-18 04:25:13 +00:00
|
|
|
URL: "https://gitlab.com",
|
|
|
|
PullMethod: "http",
|
|
|
|
Token: "",
|
|
|
|
GroupIDs: []int{9970},
|
2024-08-14 04:01:47 +00:00
|
|
|
UserNames: []int{},
|
2024-07-18 04:25:13 +00:00
|
|
|
IncludeCurrentUser: true,
|
|
|
|
ArchivedProjectHandling: "invalid",
|
2024-06-08 05:02:35 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: nil,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, test := range tests {
|
|
|
|
test := test
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
got, err := config.MakeGitlabConfig(test.input)
|
|
|
|
expected := test.expected
|
|
|
|
if !reflect.DeepEqual(got, expected) {
|
|
|
|
t.Fatalf("MakeGitlabConfig(%v) returned %v; expected %v; error: %v", test.input, got, expected, err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|