File: parse_test.go

package info (click to toggle)
syncthing 1.29.5~ds1-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 22,848 kB
  • sloc: javascript: 37,288; sh: 1,838; xml: 1,115; makefile: 66
file content (72 lines) | stat: -rw-r--r-- 2,180 bytes parent folder | download | duplicates (2)
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
// Copyright (C) 2019 The Syncthing Authors.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

package build

import (
	"fmt"
	"testing"
)

func TestParseVersion(t *testing.T) {
	cases := []struct {
		longVersion string
		parsed      VersionParts
	}{
		{
			longVersion: `syncthing v1.1.4-rc.1+30-g6aaae618-dirty-crashrep "Erbium Earthworm" (go1.12.5 darwin-amd64) jb@kvin.kastelo.net 2019-05-23 16:08:14 UTC`,
			parsed: VersionParts{
				Version:  "v1.1.4-rc.1+30-g6aaae618-dirty-crashrep",
				Tag:      "v1.1.4-rc.1",
				Commit:   "6aaae618",
				Codename: "Erbium Earthworm",
				Runtime:  "go1.12.5",
				GOOS:     "darwin",
				GOARCH:   "amd64",
				Builder:  "jb@kvin.kastelo.net",
			},
		},
		{
			longVersion: `syncthing v1.1.4-rc.1+30-g6aaae618-dirty-crashrep "Erbium Earthworm" (go1.12.5 darwin-amd64) jb@kvin.kastelo.net 2019-05-23 16:08:14 UTC [foo, bar]`,
			parsed: VersionParts{
				Version:  "v1.1.4-rc.1+30-g6aaae618-dirty-crashrep",
				Tag:      "v1.1.4-rc.1",
				Commit:   "6aaae618",
				Codename: "Erbium Earthworm",
				Runtime:  "go1.12.5",
				GOOS:     "darwin",
				GOARCH:   "amd64",
				Builder:  "jb@kvin.kastelo.net",
				Extra:    []string{"foo", "bar"},
			},
		},
		{
			longVersion: `syncthing v1.23.7-dev.26.gdf7b56ae-stversionextra "Fermium Flea" (go1.20.5 darwin-arm64) jb@ok.kastelo.net 2023-07-12 06:55:26 UTC [Some Wrapper, purego, stnoupgrade]`,
			parsed: VersionParts{
				Version:  "v1.23.7-dev.26.gdf7b56ae-stversionextra",
				Tag:      "v1.23.7-dev",
				Commit:   "df7b56ae",
				Codename: "Fermium Flea",
				Runtime:  "go1.20.5",
				GOOS:     "darwin",
				GOARCH:   "arm64",
				Builder:  "jb@ok.kastelo.net",
				Extra:    []string{"Some Wrapper", "purego", "stnoupgrade"},
			},
		},
	}

	for _, tc := range cases {
		v, err := ParseVersion(tc.longVersion)
		if err != nil {
			t.Errorf("%s\nerror: %v\n", tc.longVersion, err)
			continue
		}
		if fmt.Sprint(v) != fmt.Sprint(tc.parsed) {
			t.Errorf("%s\nA: %v\nE: %v\n", tc.longVersion, v, tc.parsed)
		}
	}
}