本文整理汇总了Golang中github.com/blang/semver.MustParse函数的典型用法代码示例。如果您正苦于以下问题:Golang MustParse函数的具体用法?Golang MustParse怎么用?Golang MustParse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MustParse函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestComponentGetters
func TestComponentGetters(t *testing.T) {
testSatisfies := []Satisfies{{Narrative: "Narrative"}, {}, {}, {}}
component := Component{
Name: "Amazon Elastic Compute Cloud",
Key: "EC2",
References: common.GeneralReferences{{}},
Verifications: common.VerificationReferences{{}, {}},
Satisfies: testSatisfies,
SchemaVersion: semver.MustParse("2.0.0"),
}
// Test the getters
assert.Equal(t, "EC2", component.GetKey())
assert.Equal(t, "Amazon Elastic Compute Cloud", component.GetName())
assert.Equal(t, &common.GeneralReferences{{}}, component.GetReferences())
assert.Equal(t, &common.VerificationReferences{{}, {}}, component.GetVerifications())
assert.Equal(t, semver.MustParse("2.0.0"), component.GetVersion())
assert.Equal(t, "", component.GetResponsibleRole())
assert.Equal(t, len(testSatisfies), len(component.GetAllSatisfies()))
for idx, satisfies := range component.GetAllSatisfies() {
assert.Equal(t, satisfies.GetControlKey(), testSatisfies[idx].GetControlKey())
assert.Equal(t, satisfies.GetStandardKey(), testSatisfies[idx].GetStandardKey())
assert.Equal(t, satisfies.GetNarratives(), testSatisfies[idx].GetNarratives())
for i, narrative := range satisfies.GetNarratives() {
assert.Equal(t, "", narrative.GetKey())
assert.Equal(t, satisfies.GetNarratives()[i].GetText(), narrative.GetText())
}
assert.Equal(t, satisfies.GetParameters(), testSatisfies[idx].GetParameters())
assert.Equal(t, satisfies.GetCoveredBy(), testSatisfies[idx].GetCoveredBy())
assert.Equal(t, "", satisfies.GetControlOrigin())
}
}
开发者ID:geramirez,项目名称:compliance-masonry,代码行数:31,代码来源:component_test.go
示例2: ensureThinLsKernelVersion
func ensureThinLsKernelVersion(kernelVersion string) error {
// kernel 4.4.0 has the proper bug fixes to allow thin_ls to work without corrupting the thin pool
minKernelVersion := semver.MustParse("4.4.0")
// RHEL 7 kernel 3.10.0 release >= 366 has the proper bug fixes backported from 4.4.0 to allow
// thin_ls to work without corrupting the thin pool
minRhel7KernelVersion := semver.MustParse("3.10.0")
matches := version_re.FindStringSubmatch(kernelVersion)
if len(matches) < 4 {
return fmt.Errorf("error parsing kernel version: %q is not a semver", kernelVersion)
}
sem, err := semver.Make(matches[0])
if err != nil {
return err
}
if sem.GTE(minKernelVersion) {
// kernel 4.4+ - good
return nil
}
// Certain RHEL/Centos 7.x kernels have a backport to fix the corruption bug
if !strings.Contains(kernelVersion, ".el7") {
// not a RHEL 7.x kernel - won't work
return fmt.Errorf("kernel version 4.4.0 or later is required to use thin_ls - you have %q", kernelVersion)
}
// RHEL/Centos 7.x from here on
if sem.Major != 3 {
// only 3.x kernels *may* work correctly
return fmt.Errorf("RHEL/Centos 7.x kernel version 3.10.0-366 or later is required to use thin_ls - you have %q", kernelVersion)
}
if sem.GT(minRhel7KernelVersion) {
// 3.10.1+ - good
return nil
}
if sem.EQ(minRhel7KernelVersion) {
// need to check release
releaseRE := regexp.MustCompile(`^[^-]+-([0-9]+)\.`)
releaseMatches := releaseRE.FindStringSubmatch(kernelVersion)
if len(releaseMatches) != 2 {
return fmt.Errorf("unable to determine RHEL/Centos 7.x kernel release from %q", kernelVersion)
}
release, err := strconv.Atoi(releaseMatches[1])
if err != nil {
return fmt.Errorf("error parsing release %q: %v", releaseMatches[1], err)
}
if release >= 366 {
return nil
}
}
return fmt.Errorf("RHEL/Centos 7.x kernel version 3.10.0-366 or later is required to use thin_ls - you have %q", kernelVersion)
}
开发者ID:jbeda,项目名称:kubernetes,代码行数:59,代码来源:factory.go
示例3: TestComponentSetters
func TestComponentSetters(t *testing.T) {
component := Component{}
// Test the setters.
// Change the version.
component.SetVersion(semver.MustParse("3.0.0"))
assert.Equal(t, semver.MustParse("3.0.0"), component.GetVersion())
// Change the key.
component.SetKey("FooKey")
assert.Equal(t, "FooKey", component.GetKey())
}
开发者ID:geramirez,项目名称:compliance-masonry,代码行数:10,代码来源:component_test.go
示例4: TestComponentGetters
func TestComponentGetters(t *testing.T) {
testSatisfies := []Satisfies{
{
ControlOrigin: "inherited",
ControlOrigins: []string{"inherited"},
ImplementationStatus: "partial",
ImplementationStatuses: []string{"partial"},
Parameters: []Section{Section{Key: "key", Text: "text"}},
Narrative: []NarrativeSection{
NarrativeSection{Key: "key", Text: "text"},
NarrativeSection{Text: "text"},
},
}, {}}
component := Component{
Name: "Amazon Elastic Compute Cloud",
Key: "EC2",
ResponsibleRole: "AWS Staff",
References: common.GeneralReferences{{}},
Verifications: common.VerificationReferences{{}, {}},
Satisfies: testSatisfies,
SchemaVersion: semver.MustParse("3.1.0"),
}
// Test the getters
assert.Equal(t, "EC2", component.GetKey())
assert.Equal(t, "Amazon Elastic Compute Cloud", component.GetName())
assert.Equal(t, &common.GeneralReferences{{}}, component.GetReferences())
assert.Equal(t, &common.VerificationReferences{{}, {}}, component.GetVerifications())
assert.Equal(t, semver.MustParse("3.1.0"), component.GetVersion())
assert.Equal(t, "AWS Staff", component.GetResponsibleRole())
assert.Equal(t, len(testSatisfies), len(component.GetAllSatisfies()))
for idx, satisfies := range component.GetAllSatisfies() {
assert.Equal(t, satisfies.GetControlKey(), testSatisfies[idx].GetControlKey())
assert.Equal(t, satisfies.GetStandardKey(), testSatisfies[idx].GetStandardKey())
assert.Equal(t, satisfies.GetNarratives(), testSatisfies[idx].GetNarratives())
for i, narrative := range satisfies.GetNarratives() {
assert.Equal(t, satisfies.GetNarratives()[i].GetKey(), narrative.GetKey())
assert.Equal(t, satisfies.GetNarratives()[i].GetText(), narrative.GetText())
}
assert.Equal(t, satisfies.GetParameters(), testSatisfies[idx].GetParameters())
for i, parameter := range satisfies.GetParameters() {
assert.Equal(t, satisfies.GetParameters()[i].GetKey(), parameter.GetKey())
assert.Equal(t, satisfies.GetParameters()[i].GetText(), parameter.GetText())
}
assert.Equal(t, satisfies.GetCoveredBy(), testSatisfies[idx].GetCoveredBy())
assert.Equal(t, satisfies.GetControlOrigin(), testSatisfies[idx].GetControlOrigin())
assert.Equal(t, satisfies.GetControlOrigins(), testSatisfies[idx].GetControlOrigins())
assert.Equal(t, satisfies.GetImplementationStatus(), testSatisfies[idx].GetImplementationStatus())
assert.Equal(t, satisfies.GetImplementationStatuses(), testSatisfies[idx].GetImplementationStatuses())
}
}
开发者ID:opencontrol,项目名称:compliance-masonry,代码行数:50,代码来源:component_test.go
示例5: checkVersion
func checkVersion() {
server := new(Version)
mustGetObject("/version", nil, server)
grindCurrent := semver.MustParse(CurrentVersion.Version)
grindRequired := semver.MustParse(server.GrindVersionRequired)
if grindRequired.GT(grindCurrent) {
log.Printf("this is grind version %s, but the server requires %s or higher", CurrentVersion.Version, server.GrindVersionRequired)
log.Fatalf(" you must upgrade to continue")
}
grindRecommended := semver.MustParse(server.GrindVersionRecommended)
if grindRecommended.GT(grindCurrent) {
log.Printf("this is grind version %s, but the server recommends %s or higher", CurrentVersion.Version, server.GrindVersionRecommended)
log.Printf(" please upgrade as soon as possible")
}
}
开发者ID:RidleyLarsen,项目名称:codegrinder,代码行数:15,代码来源:main.go
示例6: use
func use(version dockerversion.Version) {
writeDebug("dvm use %s", version)
if version.IsEmpty() {
die("The use command requires that a version is specified or the DOCKER_VERSION environment variable is set.", nil, retCodeInvalidOperation)
}
if version.HasAlias() && aliasExists(version.Alias) {
aliasedVersion, _ := ioutil.ReadFile(getAliasPath(version.Alias))
version.SemVer = semver.MustParse(string(aliasedVersion))
writeDebug("Using alias: %s -> %s", version.Alias, version.SemVer)
}
ensureVersionIsInstalled(version)
if version.IsSystem() {
version, _ = getSystemDockerVersion()
} else if version.IsExperimental() {
version, _ = getExperimentalDockerVersion()
}
removePreviousDockerVersionFromPath()
if !version.IsSystem() {
prependDockerVersionToPath(version)
}
writePathScript()
writeInfo("Now using Docker %s", version)
}
开发者ID:getcarina,项目名称:dvm,代码行数:29,代码来源:dvm-helper.go
示例7: TestUnmarshal
func TestUnmarshal(t *testing.T) {
w := testutils.Wrap(t)
var err error
version := semver.MustParse("0.0.1")
jsonData := []byte(`{
"version": "0.0.1",
"path": "./test_artifacts"
}`)
cfg := config.NewConfig(version)
err = json.Unmarshal(jsonData, &cfg)
w.BailIfErrorf(err, "deserializazion failed: %v", err)
provider, err := FromConfig(cfg)
w.BailIfErrorf(err, "instantiation failed: %v", err)
root, err := provider.Root()
w.BailIfError(err)
_, err = checkDirectoryContents(root, expectedRootEntries())
w.BailIfErrorf(err, "provider path differs")
}
开发者ID:DirtyHairy,项目名称:csync,代码行数:26,代码来源:marshalling_test.go
示例8: getLatestVersion
func getLatestVersion(zipFile []byte, prefix, suffix string) (string, error) {
r, err := zip.NewReader(bytes.NewReader(zipFile), int64(len(zipFile)))
if err != nil {
return "", err
}
latest := ""
for _, f := range r.File {
artifact := path.Base(f.Name)
if strings.HasPrefix(artifact, prefix) && strings.HasSuffix(artifact, suffix) {
v := extractVersion(artifact)
if latest == "" {
latest = v
}
v1, err := semver.Parse(v)
if err != nil {
return "", err
}
l := semver.MustParse(latest)
if v1.GT(l) {
latest = v
}
}
}
return latest, nil
}
开发者ID:fikridroid,项目名称:gradleplease,代码行数:25,代码来源:get_versions.go
示例9: getReleases
func getReleases() ([]semver.Version, map[string]Version, error) {
res, err := http.Get("https://api.github.com/repos/nlf/dhyve-os/releases")
if err != nil {
return nil, nil, err
}
defer res.Body.Close()
vers := []Version{}
decoder := json.NewDecoder(res.Body)
err = decoder.Decode(vers)
if err != nil {
return nil, nil, err
}
versions := map[string]Version{}
rng, err := semver.ParseRange(">= 3.0.0-beta0")
if err != nil {
return nil, nil, err
}
svers := []semver.Version{}
for _, vers := range versions {
v := semver.MustParse(vers.Tag)
if rng(v) {
versions[vers.Tag] = vers
svers = append(svers, v)
}
}
semver.Sort(svers)
return svers, versions, nil
}
开发者ID:carriercomm,项目名称:dlite,代码行数:32,代码来源:os.go
示例10: TestMarshalUnmarshal
func TestMarshalUnmarshal(t *testing.T) {
w := testutils.Wrap(t)
var err error
version := semver.MustParse("0.0.1")
provider, err := local.NewLocalFS("./test_artifacts")
w.BailIfError(err)
cfg := provider.Marshal()
jsonData, err := json.Marshal(cfg)
w.BailIfErrorf(err, "serialization failed: %v", err)
if !strings.Contains(string(jsonData), "test_artifacts") {
t.Fatalf("JSON does not contain the proper path: %s", string(jsonData))
}
unmarshalledConfig := config.NewConfig(version)
err = json.Unmarshal(jsonData, &unmarshalledConfig)
w.BailIfErrorf(err, "deserialization failed: %v", err)
_, err = FromConfig(unmarshalledConfig)
w.BailIfErrorf(err, "reinstation of fs provider failed: %v", err)
}
开发者ID:DirtyHairy,项目名称:csync,代码行数:28,代码来源:marshalling_test.go
示例11: getOSReleases
func getOSReleases() (Releases, error) {
res, err := http.Get("https://api.github.com/repos/nlf/dlite-os/releases")
if err != nil {
return nil, err
}
defer res.Body.Close()
releases := Releases{}
decoder := json.NewDecoder(res.Body)
err = decoder.Decode(&releases)
if err != nil {
return nil, err
}
allowedReleases := Releases{}
for _, release := range releases {
release.Version = semver.MustParse(strings.TrimPrefix(release.Tag, "v"))
if allowedRange(release.Version) {
allowedReleases = append(allowedReleases, release)
}
}
sort.Sort(allowedReleases)
return allowedReleases, nil
}
开发者ID:nlf,项目名称:dlite,代码行数:25,代码来源:os.go
示例12: CheckDockerVersion
// CheckDockerVersion checks that the appropriate Docker version is installed based on whether we are using the nsenter mounter
// or shared volumes for OpenShift
func (c *ClientStartConfig) CheckDockerVersion(io.Writer) error {
var minDockerVersion semver.Version
if c.UseNsenterMount {
minDockerVersion = semver.MustParse("1.8.1")
} else {
minDockerVersion = semver.MustParse("1.10.0")
}
ver, err := c.DockerHelper().Version()
if err != nil {
return err
}
glog.V(5).Infof("Checking that docker version is at least %v", minDockerVersion)
if ver.LT(minDockerVersion) {
return fmt.Errorf("Docker version is %v, it needs to be %v", ver, minDockerVersion)
}
return nil
}
开发者ID:bmeng,项目名称:origin,代码行数:19,代码来源:up.go
示例13: validate
func validate(deps map[string][]semver.Version, expected map[string]string, t *testing.T) {
for name, ver := range expected {
vers, ok := deps[name]
if !ok || !exists(vers, semver.MustParse(ver)) {
t.Fatalf("Expected ver %s for %s, got: %v", ver, name, vers)
}
}
}
开发者ID:AgFlow,项目名称:jsversion,代码行数:8,代码来源:versions_test.go
示例14: main
func main() {
customRawPrevVersion := flag.String("prev", "", "Force a previous version number")
var customPrevVersion *semver.Version
flag.Parse()
if *customRawPrevVersion != "" {
tmp := semver.MustParse(*customRawPrevVersion)
customPrevVersion = &tmp
}
args := flag.Args()
endRev := "HEAD"
startRev := ""
repoPath, err := GetRepoPath()
tags := getTags(repoPath)
var newVersion *semver.Version
var oldVersion *semver.Version
if err != nil {
log.Fatalf("Failed to open repository: %s", err.Error())
}
if len(args) == 0 {
startRev, oldVersion, err = getPreviousVersionRev(repoPath, tags)
if err != nil {
log.Fatalf("Failed to retrieve previous version: %s", err.Error())
}
} else if len(args) == 1 {
_, oldVersion, err = getPreviousVersionRev(repoPath, tags)
startRev = args[0]
} else {
startRev = args[0]
_, oldVersion, err = getPreviousVersionRev(repoPath, tags)
endRev = args[1]
}
if customPrevVersion != nil {
oldVersion = customPrevVersion
}
if oldVersion == nil {
log.Println("No previous version found")
newVersion = &semver.Version{Major: 1, Minor: 0, Patch: 0}
}
if oldVersion != nil {
log.Printf("Previous version: %s (%s)\n", oldVersion, startRev)
}
if newVersion == nil {
newVersion, err = getNewVersion(repoPath, startRev, endRev, oldVersion, tags)
if err != nil {
log.Fatalf("Failed to generate new version: %s", err.Error())
}
}
fmt.Println(newVersion)
}
开发者ID:zerok,项目名称:gensemver,代码行数:58,代码来源:main.go
示例15: UnmarshalYAML
// UnmarshalYAML is a overridden implementation of YAML parsing the component.yaml
// This method is similar to the one found here: http://choly.ca/post/go-json-marshalling/
// This is necessary because we want to have backwards compatibility with parsing the old types of version 2.0
// (type =float).
// To compensate for that, we have to hand roll our own UnmarshalYAML that can decide what to do for parsing
// the older version of type float and converting it into semver. In addition, we will use this logic to parse strings
// into semver.
func (b *Base) UnmarshalYAML(unmarshal func(v interface{}) error) error {
// When we call "unmarshal" callback on an object, it will call that object's "UnmarshalYAML" if defined.
// Since we are currently in the implementation of Component's "UnmarshalYAML", when finally we call
// unmarshal again, if it's on type Component, we would end up in a recursive infinite loop.
// To prevent this, we create a separate type, called Alias.
type Alias Base
// Create an anonymous struct with an interface{} type for the schema_version that we want to parse
aux := &struct {
SchemaVersion interface{} `yaml:"schema_version" json:"schema_version"`
Alias `yaml:",inline"`
}{
Alias: (Alias)(*b),
}
// Call unmarshal on the new Alias type. Don't return the error yet because we want to gather more information
// if we can below.
err := unmarshal(&aux)
// Create a placeholder variable for the converted semver.
var ver semver.Version
// Create a placeholder variable for the error.
var versionErr error
// Store the version value for conciseness.
value := aux.SchemaVersion
// Try to cast the value from interface{} to certain types.
switch v := value.(type) {
// For float types, which are the old types, we need to upcast it to semver if it's an older version.
case float32, float64:
switch v {
// Schema Version started being documented with "2.0".
// We should be able to parse it for backwards compatibility.
// All future versioning should be in semver format already.
case 2.0:
ver = semver.MustParse("2.0.0")
// If not the older version, it needs to be in semver format, send an error.
default:
return BaseComponentParseError{fmt.Sprintf("Version %v is not in semver format", v)}
}
// The interface type will default to string if not numeric which is what all semver types will be initially.
case string:
ver, versionErr = semver.Parse(v)
if versionErr != nil {
return BaseComponentParseError{constants.ErrMissingVersion}
}
// In the case, it's just missing completely.
default:
return BaseComponentParseError{constants.ErrMissingVersion}
}
// Copy everything from the Alias back to the original component.
*b = (Base)(aux.Alias)
// Get the version
b.SchemaVersion = ver
return err
}
开发者ID:opencontrol,项目名称:compliance-masonry,代码行数:65,代码来源:component.go
示例16: useDiscoveryRESTMapper
// useDiscoveryRESTMapper checks the server version to see if its recent enough to have
// enough discovery information available to reliably build a RESTMapper. If not, use the
// hardcoded mapper in this client (legacy behavior)
func useDiscoveryRESTMapper(serverVersion string) bool {
if len(serverVersion) == 0 {
return false
}
serverSemVer, err := semver.Parse(serverVersion[1:])
if err != nil {
return false
}
return serverSemVer.GE(semver.MustParse("1.3.0"))
}
开发者ID:PeterLamar,项目名称:kubernetes,代码行数:13,代码来源:factory.go
示例17: useDiscoveryRESTMapper
// useDiscoveryRESTMapper checks the server version to see if its recent enough to have
// enough discovery information avaiable to reliably build a RESTMapper. If not, use the
// hardcoded mapper in this client (legacy behavior)
func useDiscoveryRESTMapper(serverVersion string) bool {
serverSemVer, err := semver.Parse(serverVersion[1:])
if err != nil {
return false
}
if serverSemVer.LT(semver.MustParse("1.3.0")) {
return false
}
return true
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:13,代码来源:factory.go
示例18: Specific
func Specific(vers string) (Version, error) {
sv := semver.MustParse(vers)
svers, mvers, err := getReleases()
if err != nil {
return Version{}, err
}
for _, v := range svers {
if v.Equals(sv) {
return mvers[v.String()], nil
}
}
return Version{}, fmt.Errorf("Cannot find version %s", vers)
}
开发者ID:carriercomm,项目名称:dlite,代码行数:15,代码来源:os.go
示例19: TestUnmarshalLocalWithInvalidJSON
func TestUnmarshalLocalWithInvalidJSON(t *testing.T) {
w := testutils.Wrap(t)
var err error
version := semver.MustParse("0.0.1")
jsonData := `{
"type": "local",
"path": "."
`
cfg := config.NewConfig(version)
err = json.Unmarshal([]byte(jsonData), &cfg)
w.ShouldFailf(err, "unmarshalling should fail due to invalid JSON")
}
开发者ID:DirtyHairy,项目名称:csync,代码行数:16,代码来源:marshalling_test.go
示例20: TestUnmarshalWithLocalFS
func TestUnmarshalWithLocalFS(t *testing.T) {
w := testutils.Wrap(t)
var err error
version := semver.MustParse("0.0.1")
jsonData := []byte(`{
"foo": {
"plain": true,
"storage": {
"type": "local",
"path": "."
}
},
"bar": {
"plain": true,
"storage": {
"type": "local",
"path": ".."
}
}
}`)
cfg := config.NewConfig(version)
err = json.Unmarshal(jsonData, &cfg)
w.BailIfErrorf(err, "deserialization failed: %v", err)
registry, err := CreateFromConfig(cfg)
w.BailIfErrorf(err, "unmarshalling failed: %v", err)
if registry.Size() != 2 {
t.Fatalf("registry has the wrong size; expected 2, got %d", registry.Size())
}
if registry.Get("foo") == nil {
t.Fatalf("foo: no such key")
}
if registry.Get("bar") == nil {
t.Fatalf("bar: no such key")
}
}
开发者ID:DirtyHairy,项目名称:csync,代码行数:44,代码来源:marshalling_test.go
注:本文中的github.com/blang/semver.MustParse函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论