mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-05 19:21:46 +00:00
This caused a dependency chain reaction (sigh):
* All the k8s packages had to be fetched again. This in turn required:
* Pining github.com/docker/docker/pkg/parsers to
0f5c9d301b9b1cca66b3ea0f9dec3b5317d3686d to cirvumvent
https://github.com/kubernetes/kubernetes/issues/18774
* Update github.com/juju/ratelimit
* Make probe/kubernetes/client.go comply with API changes.
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package semver
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strconv"
|
|
"testing"
|
|
)
|
|
|
|
func TestJSONMarshal(t *testing.T) {
|
|
versionString := "3.1.4-alpha.1.5.9+build.2.6.5"
|
|
v, err := Parse(versionString)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
versionJSON, err := json.Marshal(v)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
quotedVersionString := strconv.Quote(versionString)
|
|
|
|
if string(versionJSON) != quotedVersionString {
|
|
t.Fatalf("JSON marshaled semantic version not equal: expected %q, got %q", quotedVersionString, string(versionJSON))
|
|
}
|
|
}
|
|
|
|
func TestJSONUnmarshal(t *testing.T) {
|
|
versionString := "3.1.4-alpha.1.5.9+build.2.6.5"
|
|
quotedVersionString := strconv.Quote(versionString)
|
|
|
|
var v Version
|
|
if err := json.Unmarshal([]byte(quotedVersionString), &v); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if v.String() != versionString {
|
|
t.Fatalf("JSON unmarshaled semantic version not equal: expected %q, got %q", versionString, v.String())
|
|
}
|
|
|
|
badVersionString := strconv.Quote("3.1.4.1.5.9.2.6.5-other-digits-of-pi")
|
|
if err := json.Unmarshal([]byte(badVersionString), &v); err == nil {
|
|
t.Fatal("expected JSON unmarshal error, got nil")
|
|
}
|
|
}
|