Skip to content

Commit dd6f8c2

Browse files
committed
fix(funcs,docs,docs-src): fix the reviewing issues
1 parent fdf8c24 commit dd6f8c2

File tree

4 files changed

+101
-14
lines changed

4 files changed

+101
-14
lines changed

docs-src/content/functions/semver.yaml renamed to docs-src/content/functions/semver.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ funcs:
2424
- |
2525
$ gomplate -i 'the pre release version is {{ ("v1.1.1" | semver.Semver).SetPrerelease "beta.1" }}'
2626
the pre release version is 1.1.1-beta.1
27-
- name: semver.MatchConstraint
27+
- name: semver.CheckConstraint
2828
description: |
2929
Test whether the input version matchs the constraint.
3030
@@ -39,11 +39,11 @@ funcs:
3939
description: The input semantic version string to test.
4040
examples:
4141
- |
42-
$ gomplate -i '{{ semver.MatchConstraint "> 1.0" "v1.1.1" }}'
42+
$ gomplate -i '{{ semver.CheckConstraint "> 1.0" "v1.1.1" }}'
4343
true
4444
- |
45-
$ gomplate -i '{{ semver.MatchConstraint "> 1.0, <1.1" "v1.1.1" }}'
45+
$ gomplate -i '{{ semver.CheckConstraint "> 1.0, <1.1" "v1.1.1" }}'
4646
false
4747
- |
48-
$ gomplate -i '{{ "v1.1.1" | semver.MatchConstraint "> 1.0" }}'
48+
$ gomplate -i '{{ "v1.1.1" | semver.CheckConstraint "> 1.0" }}'
4949
true

docs/content/functions/semver.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
title: semver functions
3+
menu:
4+
main:
5+
parent: functions
6+
---
7+
8+
These functions allow user you to parse a [semantic version](http://semver.org/) string or test it with constraint.
9+
10+
It's implemented with the https://github.com/Masterminds/semver library.
11+
12+
## `semver.Semver`_(unreleased)_
13+
**Unreleased:** _This function is in development, and not yet available in released builds of gomplate._
14+
15+
Returns a semantic version struct holding the `input` version string.
16+
17+
The returned struct are defined at: [`semver.Version`](https://pkg.go.dev/github.com/Masterminds/semver/v3#Version).
18+
19+
### Usage
20+
21+
```
22+
semver.Semver input
23+
```
24+
```
25+
input | semver.Semver
26+
```
27+
28+
### Arguments
29+
30+
| name | description |
31+
|------|-------------|
32+
| `input` | _(required)_ The input to parse |
33+
34+
### Examples
35+
36+
```console
37+
$ gomplate -i '{{ semver.Semver "v1.1.1"}}'
38+
1.1.1
39+
```
40+
```console
41+
$ gomplate -i '{{ (semver.Semver "v1.1.1").Major }}'
42+
1
43+
```
44+
```console
45+
$ gomplate -i 'the pre release version is {{ ("v1.1.1" | semver.Semver).SetPrerelease "beta.1" }}'
46+
the pre release version is 1.1.1-beta.1
47+
```
48+
49+
## `semver.CheckConstraint`_(unreleased)_
50+
**Unreleased:** _This function is in development, and not yet available in released builds of gomplate._
51+
52+
Test whether the input version matchs the constraint.
53+
54+
Ref: https://github.com/Masterminds/semver#checking-version-constraints
55+
56+
### Usage
57+
58+
```
59+
semver.CheckConstraint constraint input
60+
```
61+
```
62+
input | semver.CheckConstraint constraint
63+
```
64+
65+
### Arguments
66+
67+
| name | description |
68+
|------|-------------|
69+
| `constraint` | _(required)_ The constraints expression to test. |
70+
| `input` | _(required)_ The input semantic version string to test. |
71+
72+
### Examples
73+
74+
```console
75+
$ gomplate -i '{{ semver.CheckConstraint "> 1.0" "v1.1.1" }}'
76+
true
77+
```
78+
```console
79+
$ gomplate -i '{{ semver.CheckConstraint "> 1.0, <1.1" "v1.1.1" }}'
80+
false
81+
```
82+
```console
83+
$ gomplate -i '{{ "v1.1.1" | semver.CheckConstraint "> 1.0" }}'
84+
true
85+
```

funcs/semver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ func (SemverFuncs) Semver(version string) (*semver.Version, error) {
2424
return semver.NewVersion(version)
2525
}
2626

27-
// MatchConstraint -
28-
func (SemverFuncs) MatchConstraint(constraint, in string) (bool, error) {
27+
// CheckConstraint -
28+
func (SemverFuncs) CheckConstraint(constraint, in string) (bool, error) {
2929
c, err := semver.NewConstraint(constraint)
3030
if err != nil {
3131
return false, err

funcs/semver_test.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package funcs
33
import (
44
"context"
55
"testing"
6+
7+
"github.com/stretchr/testify/assert"
68
)
79

810
func TestSemverFuncs_MatchConstraint(t *testing.T) {
@@ -45,16 +47,16 @@ func TestSemverFuncs_MatchConstraint(t *testing.T) {
4547
for _, tt := range tests {
4648
t.Run(tt.name, func(t *testing.T) {
4749
s := SemverFuncs{
48-
ctx: context.TODO(),
49-
}
50-
got, err := s.MatchConstraint(tt.constraint, tt.in)
51-
if (err != nil) != tt.wantErr {
52-
t.Errorf("SemverFuncs.MatchConstraint() error = %v, wantErr %v", err, tt.wantErr)
53-
return
50+
ctx: context.Background(),
5451
}
55-
if got != tt.want {
56-
t.Errorf("SemverFuncs.MatchConstraint() = %v, want %v", got, tt.want)
52+
got, err := s.CheckConstraint(tt.constraint, tt.in)
53+
if tt.wantErr {
54+
assert.Errorf(t, err, "SemverFuncs.CheckConstraint() error = %v, wantErr %v", err, tt.wantErr)
55+
} else {
56+
assert.NoErrorf(t, err, "SemverFuncs.CheckConstraint() error = %v, wantErr %v", err, tt.wantErr)
5757
}
58+
59+
assert.Equal(t, tt.want, got)
5860
})
5961
}
6062
}

0 commit comments

Comments
 (0)