File: version_test.go

package info (click to toggle)
rclone 1.69.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 45,716 kB
  • sloc: sh: 1,115; xml: 857; python: 754; javascript: 612; makefile: 299; ansic: 101; php: 74
file content (77 lines) | stat: -rw-r--r-- 2,419 bytes parent folder | download | duplicates (5)
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
package version_test

import (
	"testing"
	"time"

	"github.com/rclone/rclone/fstest"
	"github.com/rclone/rclone/lib/version"
	"github.com/stretchr/testify/assert"
)

var (
	emptyT time.Time
	t0     = fstest.Time("1970-01-01T01:01:01.123456789Z")
	t0r    = fstest.Time("1970-01-01T01:01:01.123000000Z")
	t1     = fstest.Time("2001-02-03T04:05:06.123000000Z")
)

func TestVersionAdd(t *testing.T) {
	for _, test := range []struct {
		t        time.Time
		in       string
		expected string
	}{
		{t0, "potato.txt", "potato-v1970-01-01-010101-123.txt"},
		{t0, "potato-v2001-02-03-040506-123.txt", "potato-v2001-02-03-040506-123-v1970-01-01-010101-123.txt"},
		{t0, "123.!!lipps", "123-v1970-01-01-010101-123.!!lipps"},
		{t1, "potato", "potato-v2001-02-03-040506-123"},
		{t1, ".potato", ".potato-v2001-02-03-040506-123"},
		{t1, ".potato.conf", ".potato-v2001-02-03-040506-123.conf"},
		{t1, "", "-v2001-02-03-040506-123"},
	} {
		actual := version.Add(test.in, test.t)
		assert.Equal(t, test.expected, actual, test.in)
	}
}

func TestVersionRemove(t *testing.T) {
	for _, test := range []struct {
		in             string
		expectedT      time.Time
		expectedRemote string
	}{
		{"potato.txt", emptyT, "potato.txt"},
		{"potato-v1970-01-01-010101-123.txt", t0r, "potato.txt"},
		{"potato-v2001-02-03-040506-123-v1970-01-01-010101-123.txt", t0r, "potato-v2001-02-03-040506-123.txt"},
		{"potato-v2001-02-03-040506-123", t1, "potato"},
		{".potato-v2001-02-03-040506-123", t1, ".potato"},
		{".potato-v2001-02-03-040506-123.conf", t1, ".potato.conf"},
		{"-v2001-02-03-040506-123", t1, ""},
		{"potato-v2A01-02-03-040506-123", emptyT, "potato-v2A01-02-03-040506-123"},
		{"potato-v2001-02-03-040506=123", emptyT, "potato-v2001-02-03-040506=123"},
	} {
		actualT, actualRemote := version.Remove(test.in)
		assert.Equal(t, test.expectedT, actualT, test.in)
		assert.Equal(t, test.expectedRemote, actualRemote, test.in)
	}
}

func TestVersionMatch(t *testing.T) {
	for _, test := range []struct {
		in       string
		expected bool
	}{
		{"potato.txt", false},
		{"potato", false},
		{"", false},
		{"potato-v1970-01-01-010101-123.txt", true},
		{"potato-v2001-02-03-040506-123-v1970-01-01-010101-123.txt", true},
		{"potato-v2001-02-03-040506-123", true},
		{"-v2001-02-03-040506-123", true},
		{"-v9999-99-99-999999-999", true},
	} {
		actual := version.Match(test.in)
		assert.Equal(t, test.expected, actual, test.in)
	}
}