aboutsummaryrefslogtreecommitdiff
path: root/internal/slackware_com/package_test.go
blob: 271b8e874a128a7a1f5644978dad2020fc800132 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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)
	}
}