-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Follow-up to gzip encoding of request body (#343)
* Add semver to go.mod * Bring back tests for sourcegraphVersionCheck * Extract version check into public function * Move check for gzip compression to campaigns service * Fix unmarshaling of sourcegraph version * Add CHANGELOG
- Loading branch information
Showing
13 changed files
with
213 additions
and
111 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
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,30 @@ | ||
package api | ||
|
||
import ( | ||
"regexp" | ||
|
||
"github.com/Masterminds/semver" | ||
) | ||
|
||
func CheckSourcegraphVersion(version, constraint, minDate string) (bool, error) { | ||
if version == "dev" || version == "0.0.0+dev" { | ||
return true, nil | ||
} | ||
|
||
buildDate := regexp.MustCompile(`^\d+_(\d{4}-\d{2}-\d{2})_[a-z0-9]{7}$`) | ||
matches := buildDate.FindStringSubmatch(version) | ||
if len(matches) > 1 { | ||
return matches[1] >= minDate, nil | ||
} | ||
|
||
c, err := semver.NewConstraint(constraint) | ||
if err != nil { | ||
return false, nil | ||
} | ||
|
||
v, err := semver.NewVersion(version) | ||
if err != nil { | ||
return false, err | ||
} | ||
return c.Check(v), 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,74 @@ | ||
package api | ||
|
||
import "testing" | ||
|
||
func TestCheckSourcegraphVersion(t *testing.T) { | ||
for _, tc := range []struct { | ||
currentVersion, constraint, minDate string | ||
expected bool | ||
}{ | ||
{ | ||
currentVersion: "3.12.6", | ||
constraint: ">= 3.12.6", | ||
minDate: "2020-01-19", | ||
expected: true, | ||
}, | ||
{ | ||
currentVersion: "3.12.6-rc.1", | ||
constraint: ">= 3.12.6-0", | ||
minDate: "2020-01-19", | ||
expected: true, | ||
}, | ||
{ | ||
currentVersion: "3.12.6", | ||
constraint: ">= 3.13", | ||
minDate: "2020-01-19", | ||
expected: false, | ||
}, | ||
{ | ||
currentVersion: "3.13.0", | ||
constraint: ">= 3.13", | ||
minDate: "2020-01-19", | ||
expected: true, | ||
}, | ||
{ | ||
currentVersion: "dev", | ||
constraint: ">= 3.13", | ||
minDate: "2020-01-19", | ||
expected: true, | ||
}, | ||
{ | ||
currentVersion: "0.0.0+dev", | ||
constraint: ">= 3.13", | ||
minDate: "2020-01-19", | ||
expected: true, | ||
}, | ||
{ | ||
currentVersion: "54959_2020-01-29_9258595", | ||
minDate: "2020-01-19", | ||
constraint: ">= 999.13", | ||
expected: true, | ||
}, | ||
{ | ||
currentVersion: "54959_2020-01-29_9258595", | ||
minDate: "2020-01-30", | ||
constraint: ">= 999.13", | ||
expected: false, | ||
}, | ||
{ | ||
currentVersion: "54959_2020-01-29_9258595", | ||
minDate: "2020-01-29", | ||
constraint: ">= 0.0", | ||
expected: true, | ||
}, | ||
} { | ||
actual, err := CheckSourcegraphVersion(tc.currentVersion, tc.constraint, tc.minDate) | ||
if err != nil { | ||
t.Errorf("err: %s", err) | ||
} | ||
|
||
if actual != tc.expected { | ||
t.Errorf("wrong result. want=%t, got=%t (version=%q, constraint=%q)", tc.expected, actual, tc.currentVersion, tc.constraint) | ||
} | ||
} | ||
} |
Oops, something went wrong.