-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added list, prune, disable, and remove tests.
- Loading branch information
Showing
15 changed files
with
286 additions
and
29 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
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
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,68 @@ | ||
package cmd | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/trgeiger/copr-tool/internal/testutil" | ||
) | ||
|
||
func TestDisableCmd(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
args []string | ||
repoFiles [][]string // format: file/reponame, test directory folder | ||
otherFiles [][]string // format: filename, path, test directory folder | ||
expected string | ||
}{ | ||
{ | ||
name: "Disable invalid repo name", | ||
args: []string{ | ||
"copr-tool", | ||
}, | ||
expected: "invalid repository name: copr-tool\n", | ||
}, | ||
{ | ||
name: "Repo does not exist", | ||
args: []string{ | ||
"example/example", | ||
}, | ||
expected: "repository example/example is not installed\n", | ||
}, | ||
{ | ||
name: "Repo already exists and already disabled", | ||
args: []string{ | ||
"kylegospo/bazzite", | ||
}, | ||
repoFiles: [][]string{ | ||
{"_copr:copr.fedorainfracloud.org:kylegospo:bazzite.repo", "disabled"}, | ||
}, | ||
expected: "Repository kylegospo/bazzite is already disabled.\n", | ||
}, | ||
{ | ||
name: "Repo already exists but not disabled", | ||
args: []string{ | ||
"kylegospo/bazzite", | ||
}, | ||
repoFiles: [][]string{ | ||
{"_copr:copr.fedorainfracloud.org:kylegospo:bazzite.repo", "enabled"}, | ||
}, | ||
expected: "Repository kylegospo/bazzite disabled.\n", | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
|
||
b := new(bytes.Buffer) | ||
fs := testutil.AssembleTestFs(test.repoFiles, test.otherFiles) | ||
cmd := NewDisableCmd(fs, b) | ||
cmd.SetOut(b) | ||
cmd.SetArgs(test.args) | ||
|
||
cmd.Execute() | ||
|
||
if b.String() != test.expected { | ||
t.Fatalf("Test \"%s\" failed", test.name) | ||
} | ||
} | ||
} |
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
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
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,45 @@ | ||
package cmd | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/trgeiger/copr-tool/internal/testutil" | ||
) | ||
|
||
func TestListCmd(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
repoFiles [][]string // format: file/reponame, test directory folder | ||
otherFiles [][]string // format: filename, path, test directory folder | ||
expected string | ||
}{ | ||
{ | ||
name: "List existing repos", | ||
repoFiles: [][]string{ | ||
{"_copr:copr.fedorainfracloud.org:kylegospo:bazzite.repo", "enabled"}, | ||
{"_copr:copr.fedorainfracloud.org:bieszczaders:kernel-cachyos.repo", "enabled"}, | ||
}, | ||
expected: "bieszczaders/kernel-cachyos\nkylegospo/bazzite\n", | ||
}, | ||
{ | ||
name: "No repos to list", | ||
expected: "No installed Copr repositories.\n", | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
|
||
b := new(bytes.Buffer) | ||
fs := testutil.AssembleTestFs(test.repoFiles, test.otherFiles) | ||
cmd := NewListCmd(fs, b) | ||
cmd.SetOut(b) | ||
|
||
cmd.Execute() | ||
|
||
if b.String() != test.expected { | ||
t.Fatalf("Test \"%s\" failed", test.name) | ||
} | ||
} | ||
|
||
} |
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
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,53 @@ | ||
package cmd | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/trgeiger/copr-tool/internal/testutil" | ||
) | ||
|
||
func TestPruneCmd(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
repoFiles [][]string // format: file/reponame, test directory folder | ||
otherFiles [][]string // format: filename, path, test directory folder | ||
expected string | ||
}{ | ||
{ | ||
name: "No repositories installed", | ||
expected: "Nothing to prune.\n", | ||
}, | ||
{ | ||
name: "Remove 1 duplicate", | ||
repoFiles: [][]string{ | ||
{"_copr:copr.fedorainfracloud.org:kylegospo:bazzite.repo", "enabled"}, | ||
{"_copr:copr.fedorainfracloud.org:kylegospo:bazzite-copy.repo", "enabled"}, | ||
}, | ||
expected: "Removed 1 duplicate entry for kylegospo/bazzite.\n", | ||
}, | ||
{ | ||
name: "Remove multiple duplicates", | ||
repoFiles: [][]string{ | ||
{"_copr:copr.fedorainfracloud.org:kylegospo:bazzite.repo", "enabled"}, | ||
{"_copr:copr.fedorainfracloud.org:kylegospo:bazzite-copy.repo", "enabled"}, | ||
{"_copr:copr.fedorainfracloud.org:kylegospo:bazzite-copy2.repo", "enabled"}, | ||
}, | ||
expected: "Removed 2 duplicate entries for kylegospo/bazzite.\n", | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
|
||
b := new(bytes.Buffer) | ||
fs := testutil.AssembleTestFs(test.repoFiles, test.otherFiles) | ||
cmd := NewPruneCmd(fs, b) | ||
cmd.SetOut(b) | ||
|
||
cmd.Execute() | ||
|
||
if b.String() != test.expected { | ||
t.Fatalf("Test \"%s\" failed", test.name) | ||
} | ||
} | ||
} |
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
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,58 @@ | ||
package cmd | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/trgeiger/copr-tool/internal/testutil" | ||
) | ||
|
||
func TestRemoveCmd(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
args []string | ||
repoFiles [][]string // format: file/reponame, test directory folder | ||
otherFiles [][]string // format: filename, path, test directory folder | ||
expected string | ||
}{ | ||
{ | ||
name: "Remove invalid repo name", | ||
args: []string{ | ||
"copr-tool", | ||
}, | ||
expected: "invalid repository name: copr-tool\n", | ||
}, | ||
{ | ||
name: "Remove uninstalled repo", | ||
args: []string{ | ||
"example/example", | ||
}, | ||
expected: "Repository example/example does not exist locally. Nothing to delete.\n", | ||
}, | ||
{ | ||
name: "Remove installed repo", | ||
args: []string{ | ||
"kylegospo/bazzite", | ||
}, | ||
repoFiles: [][]string{ | ||
{"_copr:copr.fedorainfracloud.org:kylegospo:bazzite.repo", "enabled"}, | ||
}, | ||
expected: "Repository kylegospo/bazzite deleted.\n", | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
|
||
b := new(bytes.Buffer) | ||
fs := testutil.AssembleTestFs(test.repoFiles, test.otherFiles) | ||
cmd := NewRemoveCmd(fs, b) | ||
cmd.SetOut(b) | ||
cmd.SetArgs(test.args) | ||
|
||
cmd.Execute() | ||
|
||
if b.String() != test.expected { | ||
t.Fatalf("Test \"%s\" failed", test.name) | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
cmd/test/enabled/_copr:copr.fedorainfracloud.org:bieszczaders:kernel-cachyos.repo
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,10 @@ | ||
[copr:copr.fedorainfracloud.org:bieszczaders:kernel-cachyos] | ||
name=Copr repo for kernel-cachyos owned by bieszczaders | ||
baseurl=https://download.copr.fedorainfracloud.org/results/bieszczaders/kernel-cachyos/fedora-$releasever-$basearch/ | ||
type=rpm-md | ||
skip_if_unavailable=True | ||
gpgcheck=1 | ||
gpgkey=https://download.copr.fedorainfracloud.org/results/bieszczaders/kernel-cachyos/pubkey.gpg | ||
repo_gpgcheck=0 | ||
enabled=1 | ||
enabled_metadata=1 |
10 changes: 10 additions & 0 deletions
10
cmd/test/enabled/_copr:copr.fedorainfracloud.org:kylegospo:bazzite-copy.repo
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,10 @@ | ||
[copr:copr.fedorainfracloud.org:kylegospo:bazzite] | ||
name=Copr repo for bazzite owned by kylegospo | ||
baseurl=https://download.copr.fedorainfracloud.org/results/kylegospo/bazzite/fedora-$releasever-$basearch/ | ||
type=rpm-md | ||
skip_if_unavailable=True | ||
gpgcheck=1 | ||
gpgkey=https://download.copr.fedorainfracloud.org/results/kylegospo/bazzite/pubkey.gpg | ||
repo_gpgcheck=0 | ||
enabled=1 | ||
enabled_metadata=1 |
10 changes: 10 additions & 0 deletions
10
cmd/test/enabled/_copr:copr.fedorainfracloud.org:kylegospo:bazzite-copy2.repo
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,10 @@ | ||
[copr:copr.fedorainfracloud.org:kylegospo:bazzite] | ||
name=Copr repo for bazzite owned by kylegospo | ||
baseurl=https://download.copr.fedorainfracloud.org/results/kylegospo/bazzite/fedora-$releasever-$basearch/ | ||
type=rpm-md | ||
skip_if_unavailable=True | ||
gpgcheck=1 | ||
gpgkey=https://download.copr.fedorainfracloud.org/results/kylegospo/bazzite/pubkey.gpg | ||
repo_gpgcheck=0 | ||
enabled=1 | ||
enabled_metadata=1 |
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
Oops, something went wrong.