-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
221 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package core | ||
|
||
// Version is the current yomo version. | ||
const Version = "1.16.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Package version provides functionality for parsing versions.. | ||
package version | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
// Version is used by the source/sfn to communicate their version to the server. | ||
type Version struct { | ||
Major int | ||
Minor int | ||
Patch int | ||
} | ||
|
||
// Parse parses a string into a Version.The string format must follow the `Major.Minor.Patch` | ||
// formatting, and the Major, Minor, and Patch components must be numeric. If they are not, | ||
// a parse error will be returned. | ||
func Parse(str string) (*Version, error) { | ||
vs := strings.Split(str, ".") | ||
if len(vs) != 3 { | ||
return nil, fmt.Errorf("invalid semantic version, params=%s", str) | ||
} | ||
|
||
major, err := strconv.Atoi(vs[0]) | ||
if err != nil { | ||
return nil, fmt.Errorf("invalid version major, params=%s", str) | ||
} | ||
|
||
minor, err := strconv.Atoi(vs[1]) | ||
if err != nil { | ||
return nil, fmt.Errorf("invalid version minor, params=%s", str) | ||
} | ||
|
||
patch, err := strconv.Atoi(vs[2]) | ||
if err != nil { | ||
return nil, fmt.Errorf("invalid version patch, params=%s", str) | ||
} | ||
|
||
ver := &Version{Major: major, Minor: minor, Patch: patch} | ||
|
||
return ver, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package version | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestParse(t *testing.T) { | ||
type args struct { | ||
str string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want *Version | ||
wantErr error | ||
}{ | ||
{ | ||
name: "ok", | ||
args: args{ | ||
str: "1.16.3", | ||
}, | ||
want: &Version{Major: 1, Minor: 16, Patch: 3}, | ||
}, | ||
{ | ||
name: "invalid semantic version", | ||
args: args{ | ||
str: "1.16.3-beta.1", | ||
}, | ||
want: nil, | ||
wantErr: errors.New("invalid semantic version, params=1.16.3-beta.1"), | ||
}, | ||
{ | ||
name: "invalid version major", | ||
args: args{ | ||
str: "xx.16.3", | ||
}, | ||
want: nil, | ||
wantErr: errors.New("invalid version major, params=xx.16.3"), | ||
}, | ||
{ | ||
name: "invalid version minor", | ||
args: args{ | ||
str: "1.yy.3", | ||
}, | ||
want: nil, | ||
wantErr: errors.New("invalid version minor, params=1.yy.3"), | ||
}, | ||
{ | ||
name: "invalid version patch", | ||
args: args{ | ||
str: "1.16.3-beta", | ||
}, | ||
want: nil, | ||
wantErr: errors.New("invalid version patch, params=1.16.3-beta"), | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, gotErr := Parse(tt.args.str) | ||
assert.Equal(t, tt.wantErr, gotErr) | ||
assert.Equal(t, tt.want, got) | ||
}) | ||
} | ||
} |