mirror of
https://github.com/restic/restic.git
synced 2026-05-28 04:35:41 -04:00
updated cmd_docs_test.go to be on par with cmd_docs_test.go
- rewrite a changed the tests stuct for TestOpenDocs - added a test for TestDocsURLForVersion
This commit is contained in:
parent
123ea0f7bd
commit
7fe5544bb1
1 changed files with 90 additions and 7 deletions
|
|
@ -2,14 +2,17 @@ package main
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/restic/restic/internal/global"
|
||||
)
|
||||
|
||||
func TestNewDocsCommand(t *testing.T) {
|
||||
cmd := newDocsCommand()
|
||||
cmd := newDocsCommand(&global.Options{})
|
||||
|
||||
if cmd.Use != "docs" {
|
||||
t.Errorf("expected command Use 'docs' got %q", cmd.Use)
|
||||
|
|
@ -39,7 +42,82 @@ func TestNewDocsCommand(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestDocsURLForVersion(t *testing.T) {
|
||||
// Dynamically build the expected URLs using the package's base constant
|
||||
stableURL := fmt.Sprintf("%s/stable", ResticURL)
|
||||
latestURL := fmt.Sprintf("%s/latest", ResticURL)
|
||||
tagURL := func(tag string) string {
|
||||
return fmt.Sprintf("%s/v%s", ResticURL, tag)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
version string
|
||||
want string
|
||||
}{
|
||||
// --- 1. Stable Tag Releases ---
|
||||
{
|
||||
name: "Exact Release Tag",
|
||||
version: "0.18.1",
|
||||
want: tagURL("0.18.1"),
|
||||
},
|
||||
{
|
||||
name: "Release Tag with Patch",
|
||||
version: "1.23.4",
|
||||
want: tagURL("1.23.4"),
|
||||
},
|
||||
|
||||
// --- 2. Development & Bleeding Edge Builds ---
|
||||
{
|
||||
name: "Dev Build with Suffix",
|
||||
version: "0.18.1-dev",
|
||||
want: latestURL,
|
||||
},
|
||||
{
|
||||
name: "Manually Compiled Binary",
|
||||
version: "0.18.1 (compiled manually)",
|
||||
want: latestURL,
|
||||
},
|
||||
{
|
||||
name: "Pure Dev Keyword",
|
||||
version: "dev",
|
||||
want: latestURL,
|
||||
},
|
||||
|
||||
// --- 3. Fallbacks & Unknown States ---
|
||||
{
|
||||
name: "Explicit Unknown Keyword",
|
||||
version: "unknown",
|
||||
want: stableURL,
|
||||
},
|
||||
{
|
||||
name: "Empty String Fallback",
|
||||
version: "",
|
||||
want: stableURL,
|
||||
},
|
||||
{
|
||||
name: "Malformed Version Fallback",
|
||||
version: "my-custom-version-string",
|
||||
want: stableURL,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := docsURLForVersion(tt.version); got != tt.want {
|
||||
t.Errorf("docsURLForVersion(%q) = %q, want %q", tt.version, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpenDocs(t *testing.T) {
|
||||
stableURL := fmt.Sprintf("%s/stable", ResticURL)
|
||||
latestURL := fmt.Sprintf("%s/latest", ResticURL)
|
||||
tagURL := func(tag string) string {
|
||||
return fmt.Sprintf("%s/v%s", ResticURL, tag)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
goos string
|
||||
|
|
@ -48,12 +126,17 @@ func TestOpenDocs(t *testing.T) {
|
|||
wantBin string
|
||||
wantArg string
|
||||
}{
|
||||
{"Linux User", "linux", ResticDocsURL, "user", "xdg-open", ResticDocsURL},
|
||||
{"Linux Dev", "linux", ResticDevDocsURL, "developer", "xdg-open", ResticDevDocsURL},
|
||||
{"Mac User", "darwin", ResticDocsURL, "user", "open", ResticDocsURL},
|
||||
{"Mac Dev", "darwin", ResticDevDocsURL, "developer", "open", ResticDevDocsURL},
|
||||
{"Windows User", "windows", ResticDocsURL, "user", "rundll32", "url.dll,FileProtocolHandler"},
|
||||
{"Windows Dev", "windows", ResticDevDocsURL, "developer", "rundll32", "url.dll,FileProtocolHandler"},
|
||||
{"Linux version", "linux", tagURL("v0.18.1"), "user", "xdg-open", tagURL("v0.18.1")},
|
||||
{"Linux User", "linux", stableURL, "user", "xdg-open", stableURL},
|
||||
{"Linux Dev", "linux", latestURL, "developer", "xdg-open", latestURL},
|
||||
|
||||
{"Mac Version", "darwin", tagURL("v0.18.1"), "user", "open", tagURL("v0.18.1")},
|
||||
{"Mac User", "darwin", stableURL, "user", "open", stableURL},
|
||||
{"Mac Dev", "darwin", latestURL, "developer", "open", latestURL},
|
||||
|
||||
{"Windows Version", "windows", tagURL("v0.18.1"), "user", "rundll32", "url.dll,FileProtocolHandler"},
|
||||
{"Windows User", "windows", stableURL, "user", "rundll32", "url.dll,FileProtocolHandler"},
|
||||
{"Windows Dev", "windows", latestURL, "developer", "rundll32", "url.dll,FileProtocolHandler"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
|
|||
Loading…
Reference in a new issue