Welcome to mirror list, hosted at ThFree Co, Russian Federation.

utils_test.go « operations « service « gitaly « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2d1016e9847f3bfcc6040c2113a91e0db09a4041 (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
//go:build !gitaly_test_sha256

package operations

import (
	"errors"
	"testing"
	"time"

	"github.com/stretchr/testify/assert"
	"gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb"
	"google.golang.org/protobuf/types/known/timestamppb"
)

func TestDateFromProto(t *testing.T) {
	locUtc, _ := time.LoadLocation("UTC")
	locShanghai, _ := time.LoadLocation("Asia/Shanghai")
	staticNow := time.Now()

	testCases := []struct {
		timezone string
		want     *time.Location
		err      error
	}{
		{"UTC", locUtc, nil},
		{"Asia/Shanghai", locShanghai, nil},
		{"Illegal/Format", locUtc, errors.New("unknown time zone Illegal/Format")},
		{"", locUtc, nil},
	}
	for _, testCase := range testCases {
		t.Run(testCase.timezone, func(t *testing.T) {
			req := &gitalypb.UserSquashRequest{
				User:      &gitalypb.User{Timezone: testCase.timezone},
				Timestamp: timestamppb.New(staticNow),
			}
			got, err := dateFromProto(req)

			if testCase.err != nil {
				assert.Equal(t, testCase.err.Error(), err.Error())
			} else {
				assert.Equal(t, staticNow.UnixNano(), got.UnixNano())
			}
			assert.Equal(t, testCase.want, got.Location())
		})
	}
}