Skip to content

Commit

Permalink
Merge pull request #140 from jstrachan/changes2
Browse files Browse the repository at this point in the history
fix: handle better validation of times
  • Loading branch information
jenkins-x-bot-test authored May 11, 2021
2 parents 70f0c19 + ddf9e88 commit a265640
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 11 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/jenkins-x/jx-logging/v3 v3.0.3
github.com/mattbaird/jsonpatch v0.0.0-20171005235357-81af80346b1a
github.com/pkg/errors v0.9.1
github.com/rawlingsj/jsonschema v0.0.0-20210511111326-a8f2a263bf66 // use a fork until https://github.com/alecthomas/jsonschema/issues/65 is fixed
github.com/rawlingsj/jsonschema v0.0.0-20210511135523-62f970496185 // use a fork until https://github.com/alecthomas/jsonschema/issues/65 is fixed
github.com/stretchr/testify v1.6.1
github.com/vrischmann/envconfig v1.2.0
github.com/xeipuuv/gojsonschema v1.2.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ github.com/rawlingsj/jsonschema v0.0.0-20201130104235-44c4fb269f83 h1:+2o6r9BUAI
github.com/rawlingsj/jsonschema v0.0.0-20201130104235-44c4fb269f83/go.mod h1:8LFgdjjkhuo3+T0/kprWPWGqh2+v8QC4hLyjNK6j15s=
github.com/rawlingsj/jsonschema v0.0.0-20210511111326-a8f2a263bf66 h1:Y8axTXO1bABk6UfkKNbv6Qq/GHDf12ff3/4MPMtQSf8=
github.com/rawlingsj/jsonschema v0.0.0-20210511111326-a8f2a263bf66/go.mod h1:8LFgdjjkhuo3+T0/kprWPWGqh2+v8QC4hLyjNK6j15s=
github.com/rawlingsj/jsonschema v0.0.0-20210511135523-62f970496185 h1:j1WDAw2vDfeAr6Oe5J4za3VwnDjg6GNo4+jqzfVj77M=
github.com/rawlingsj/jsonschema v0.0.0-20210511135523-62f970496185/go.mod h1:8LFgdjjkhuo3+T0/kprWPWGqh2+v8QC4hLyjNK6j15s=
github.com/rickar/props v0.0.0-20170718221555-0b06aeb2f037 h1:HFsTO5S+nnw/Xs9lRYF+UUJvH8wMSRMRal321W0hfdY=
github.com/rickar/props v0.0.0-20170718221555-0b06aeb2f037/go.mod h1:F1p8BNM4IXv2UcptwSp8HJOapKurodd/PYu1D6Gtn9Y=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
Expand Down
20 changes: 20 additions & 0 deletions pkg/util/test_data/good_sr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: jenkins.io/v1
kind: SourceRepository
metadata:
creationTimestamp: null
labels:
owner: jenkins-x-plugins
provider: github
repository: jx-gitops
name: jenkins-x-plugins-jx-gitops
spec:
httpCloneURL: https://github.com/jenkins-x-plugins/jx-gitops.git
org: jenkins-x-plugins
provider: https://github.com
providerKind: github
providerName: github
repo: jx-gitops
scheduler:
kind: ""
name: cheese
url: https://github.com/jenkins-x-plugins/jx-gitops
19 changes: 19 additions & 0 deletions pkg/util/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@ func TestValidation(t *testing.T) {
require.Empty(t, results, "should not have validation errors for file %s", path)
}

func TestValidateSourceRepository(t *testing.T) {
t.Parallel()

path := filepath.Join("test_data", "good_sr.yaml")
data, err := ioutil.ReadFile(path)
require.NoError(t, err, "failed to load %s", path)

deploy := &v1.SourceRepository{}
err = yaml.Unmarshal(data, deploy)
require.NoError(t, err, "failed to unmarshal %s", path)

results, err := util.ValidateYaml(deploy, data)
t.Logf("got results %#v\n", results)

require.NoError(t, err, "should not have failed to validate yaml file %s", path)

require.Empty(t, results, "should not have validation errors for file %s", path)
}

func TestValidationFails(t *testing.T) {
t.Parallel()

Expand Down
19 changes: 15 additions & 4 deletions schema/jenkins.io/v1/environment.json
Original file line number Diff line number Diff line change
Expand Up @@ -886,10 +886,18 @@
"JobCondition": {
"properties": {
"lastProbeTime": {
"$ref": "#/definitions/Time"
"type": [
"string",
"null"
],
"format": "date-time"
},
"lastTransitionTime": {
"$ref": "#/definitions/Time"
"type": [
"string",
"null"
],
"format": "date-time"
},
"message": {
"type": "string"
Expand Down Expand Up @@ -1176,8 +1184,11 @@
"type": "string"
},
"creationTimestamp": {
"$schema": "http://json-schema.org/draft-04/schema#",
"$ref": "#/definitions/Time"
"type": [
"string",
"null"
],
"format": "date-time"
},
"deletionGracePeriodSeconds": {
"type": "integer"
Expand Down
7 changes: 5 additions & 2 deletions schema/jenkins.io/v1/pipeline-activity.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,11 @@
"type": "string"
},
"creationTimestamp": {
"$schema": "http://json-schema.org/draft-04/schema#",
"$ref": "#/definitions/Time"
"type": [
"string",
"null"
],
"format": "date-time"
},
"deletionGracePeriodSeconds": {
"type": "integer"
Expand Down
7 changes: 5 additions & 2 deletions schema/jenkins.io/v1/release.json
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,11 @@
"type": "string"
},
"creationTimestamp": {
"$schema": "http://json-schema.org/draft-04/schema#",
"$ref": "#/definitions/Time"
"type": [
"string",
"null"
],
"format": "date-time"
},
"deletionGracePeriodSeconds": {
"type": "integer"
Expand Down
7 changes: 5 additions & 2 deletions schema/jenkins.io/v1/source-repository.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@
"type": "string"
},
"creationTimestamp": {
"$schema": "http://json-schema.org/draft-04/schema#",
"$ref": "#/definitions/Time"
"type": [
"string",
"null"
],
"format": "date-time"
},
"deletionGracePeriodSeconds": {
"type": "integer"
Expand Down

0 comments on commit a265640

Please sign in to comment.