diff options
Diffstat (limited to 'internal/slackware_com/package_test.go')
-rw-r--r-- | internal/slackware_com/package_test.go | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/internal/slackware_com/package_test.go b/internal/slackware_com/package_test.go new file mode 100644 index 0000000..271b8e8 --- /dev/null +++ b/internal/slackware_com/package_test.go @@ -0,0 +1,82 @@ +package slackware_com + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestPackageName(t *testing.T) { + tests := []struct { + Arg string + Exp PackageName + }{ + { + Arg: "aaa_base-15.0-x86_64-4_slack15.0", + Exp: PackageName{ + Application: "aaa_base", + Version: "15.0", + Arch: "x86_64", + Build: 4, + Tag: "_slack15.0", + }, + }, + { + Arg: "polkit-kde-agent-1-5.27.9-x86_64-1", + Exp: PackageName{ + Application: "polkit-kde-agent-1", + Version: "5.27.9", + Arch: "x86_64", + Build: 1, + Tag: "", + }, + }, + } + + for _, test := range tests { + pkgName, err := NewPackageName(test.Arg) + require.NoError(t, err) + assert.Equal(t, test.Exp, pkgName, test.Arg) + } +} + +func TestPackageNamePattern(t *testing.T) { + tests := []struct { + Pattern PackageNamePattern + Pkg PackageName + Exp bool + }{ + { + Pattern: "aaa_base", + Pkg: MustPackageName("aaa_base-15.0-x86_64-4_slack15.0"), + Exp: true, + }, + { + Pattern: "aaa", + Pkg: MustPackageName("aaa_base-15.0-x86_64-4_slack15.0"), + Exp: false, + }, + { + Pattern: "aaa_base-14.0", + Pkg: MustPackageName("aaa_base-15.0-x86_64-4_slack15.0"), + Exp: false, + }, + + { + Pattern: "bind-9.16", + Pkg: MustPackageName("bind-9.16.44-x86_64-1_slack15.0.txz"), + Exp: false, + }, + { + Pattern: "bind-9.18.19", + Pkg: MustPackageName("bind-9.18.19-x86_64-1_slack15.0.txz"), + Exp: true, + }, + } + + for _, test := range tests { + v := test.Pattern.IsMatch(test.Pkg) + assert.Equal(t, test.Exp, v, "%s match %s", test.Pattern, test.Pkg) + } +} |