-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
78 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,3 +40,5 @@ gitbackup | |
|
||
# | ||
dist/ | ||
|
||
testdata/**expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,65 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"path" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestCli(t *testing.T) { | ||
cmd := exec.Command("go", "build", "-o", "gitbackup_test_bin") | ||
func TestCliUsage(t *testing.T) { | ||
cmd := exec.Command("go", "env") | ||
stdoutStderr, err := cmd.CombinedOutput() | ||
t.Log(cmd.Environ()) | ||
t.Fatalf(string(stdoutStderr)) | ||
|
||
cmd = exec.Command("go", "build", "-v", "-o", "gitbackup_test_bin") | ||
stdoutStderr, err = cmd.CombinedOutput() | ||
if err != nil { | ||
t.Fatal(err) | ||
t.Fatalf("Error building test binary: %v - %v", err, string(stdoutStderr)) | ||
} | ||
defer func() { | ||
err := os.Remove("gitbackup_test_bin") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
}() | ||
|
||
var stdout, stderr bytes.Buffer | ||
goldenFilepath := path.Join("testdata", t.Name()+".golden") | ||
goldenFilepathNew := goldenFilepath + ".expected" | ||
|
||
cmd = exec.Command("./gitbackup_test_bin", "-h") | ||
stdoutStderr, err = cmd.CombinedOutput() | ||
cmd.Stdout = &stdout | ||
cmd.Stderr = &stderr | ||
err = cmd.Run() | ||
if err != nil { | ||
log.Println(string(stderr.Bytes())) | ||
t.Fatal(err) | ||
} | ||
t.Log(string(stdoutStderr)) | ||
|
||
gotUsage := stderr.Bytes() | ||
|
||
expectedUsage, err := os.ReadFile(goldenFilepath) | ||
if err != nil { | ||
t.Errorf("couldn't read %[1]s..writing expected output to %[1]s", goldenFilepath) | ||
if err := writeExpectedGoldenFile(goldenFilepath, gotUsage); err != nil { | ||
t.Fatal("Error writing file", err) | ||
} | ||
t.FailNow() | ||
} | ||
if !reflect.DeepEqual(expectedUsage, gotUsage) { | ||
t.Errorf("expected and got data mismatch. ..writing expected output to %[1]s", goldenFilepathNew) | ||
if err := writeExpectedGoldenFile(goldenFilepathNew, gotUsage); err != nil { | ||
t.Fatal("Error writing file", err) | ||
} | ||
t.FailNow() | ||
} | ||
} | ||
|
||
func writeExpectedGoldenFile(filePath string, data []byte) error { | ||
return os.WriteFile(filePath, data, 0644) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
Usage of ./gitbackup_test_bin: | ||
-backupdir string | ||
Backup directory | ||
-bare | ||
Clone bare repositories | ||
-githost.url string | ||
DNS of the custom Git host | ||
-github.createUserMigration | ||
Download user data | ||
-github.createUserMigrationRetry | ||
Retry creating the GitHub user migration if we get an error (default true) | ||
-github.createUserMigrationRetryMax int | ||
Number of retries to attempt for creating GitHub user migration (default 5) | ||
-github.listUserMigrations | ||
List available user migrations | ||
-github.namespaceWhitelist string | ||
Organizations/Users from where we should clone (separate each value by a comma: 'user1,org2') | ||
-github.repoType string | ||
Repo types to backup (all, owner, member, starred) (default "all") | ||
-github.waitForUserMigration | ||
Wait for migration to complete (default true) | ||
-gitlab.projectMembershipType string | ||
Project type to clone (all, owner, member, starred) (default "all") | ||
-gitlab.projectVisibility string | ||
Visibility level of Projects to clone (internal, public, private) (default "internal") | ||
-ignore-fork | ||
Ignore repositories which are forks | ||
-ignore-private | ||
Ignore private repositories/projects | ||
-service string | ||
Git Hosted Service Name (github/gitlab/bitbucket) | ||
-use-https-clone | ||
Use HTTPS for cloning instead of SSH |