Skip to content

Commit

Permalink
Merge pull request #141 from jstrachan/changes2
Browse files Browse the repository at this point in the history
fix: add better test of validation
  • Loading branch information
jenkins-x-bot-test authored May 11, 2021
2 parents a265640 + a2e892c commit e9b60c4
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 27 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-20210511135523-62f970496185 // use a fork until https://github.com/alecthomas/jsonschema/issues/65 is fixed
github.com/rawlingsj/jsonschema v0.0.0-20210511142122-a9c2cfdb7dcf // 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 @@ -210,6 +210,8 @@ github.com/rawlingsj/jsonschema v0.0.0-20210511111326-a8f2a263bf66 h1:Y8axTXO1bA
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/rawlingsj/jsonschema v0.0.0-20210511142122-a9c2cfdb7dcf h1:YPl5D1RlBkDDxJBodNwBtzBnqDQobrDJcs/2x3Grfts=
github.com/rawlingsj/jsonschema v0.0.0-20210511142122-a9c2cfdb7dcf/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
71 changes: 71 additions & 0 deletions pkg/util/test_data/good_release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Source: jx-preview/templates/release.yaml
apiVersion: jenkins.io/v1
kind: Release
metadata:
creationTimestamp: "2021-04-30T14:33:00Z"
deletionTimestamp: null
name: 'jx-preview-0.0.181'
annotations:
meta.helm.sh/release-name: 'jx-preview'
namespace: jx
labels:
gitops.jenkins-x.io/pipeline: 'namespaces'
spec:
commits:
- author:
email: james.strachan@gmail.com
name: James Strachan
branch: master
committer:
email: noreply@github.com
name: GitHub
message: |-
fix: upgrade the boot image
so we get the same helmfile version as used in jx-preview
sha: 36d3520386c3441028603c125b839aed5c7fd8fb
- author:
email: james.strachan@gmail.com
name: James Strachan
branch: master
committer:
email: james.strachan@gmail.com
name: James Strachan
message: |
chore: upgrade deps
sha: 6140d7014f39bdabfada9cbd20041a002b1d7212
- author:
email: james.strachan@gmail.com
name: James Strachan
branch: master
committer:
email: james.strachan@gmail.com
name: James Strachan
message: |
fix: added JSON schema generation
sha: 99839eb735d02361f137c226a61a566de7c69766
- author:
email: wowq@users.noreply.github.com
name: wowq
branch: master
committer:
email: noreply@github.com
name: GitHub
message: Update values.yaml
sha: ef8ab029f2bb94791eac9d5f895c6aafa604a53d
- author:
email: jenkins-x@googlegroups.com
name: jenkins-x-bot
branch: master
committer:
email: jenkins-x@googlegroups.com
name: jenkins-x-bot
message: |
fix: value error
sha: a63e7f9097cd3be9b1ff54d6b8bcda4589c30848
gitHttpUrl: https://github.com/jenkins-x-plugins/jx-preview
gitOwner: jenkins-x-plugins
gitRepository: jx-preview
name: 'jx-preview'
version: 0.0.181
status: {}
19 changes: 19 additions & 0 deletions pkg/util/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,25 @@ func TestValidateSourceRepository(t *testing.T) {
require.Empty(t, results, "should not have validation errors for file %s", path)
}

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

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

deploy := &v1.Release{}
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
24 changes: 20 additions & 4 deletions schema/jenkins.io/v1/environment.json
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,11 @@
"type": "integer"
},
"completionTime": {
"$ref": "#/definitions/Time"
"type": [
"string",
"null"
],
"format": "date-time"
},
"conditions": {
"items": {
Expand All @@ -966,7 +970,11 @@
"type": "integer"
},
"startTime": {
"$ref": "#/definitions/Time"
"type": [
"string",
"null"
],
"format": "date-time"
},
"succeeded": {
"type": "integer"
Expand Down Expand Up @@ -1070,7 +1078,11 @@
"type": "string"
},
"time": {
"$ref": "#/definitions/Time"
"type": [
"string",
"null"
],
"format": "date-time"
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -1194,7 +1206,11 @@
"type": "integer"
},
"deletionTimestamp": {
"$ref": "#/definitions/Time"
"type": [
"string",
"null"
],
"format": "date-time"
},
"finalizers": {
"items": {
Expand Down
96 changes: 80 additions & 16 deletions schema/jenkins.io/v1/pipeline-activity.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@
"CoreActivityStep": {
"properties": {
"completedTimestamp": {
"$ref": "#/definitions/Time"
"type": [
"string",
"null"
],
"format": "date-time"
},
"description": {
"type": "string"
Expand All @@ -48,7 +52,11 @@
"type": "string"
},
"startedTimestamp": {
"$ref": "#/definitions/Time"
"type": [
"string",
"null"
],
"format": "date-time"
},
"status": {
"type": "string"
Expand Down Expand Up @@ -92,7 +100,11 @@
"type": "string"
},
"time": {
"$ref": "#/definitions/Time"
"type": [
"string",
"null"
],
"format": "date-time"
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -122,7 +134,11 @@
"type": "integer"
},
"deletionTimestamp": {
"$ref": "#/definitions/Time"
"type": [
"string",
"null"
],
"format": "date-time"
},
"finalizers": {
"items": {
Expand Down Expand Up @@ -260,7 +276,11 @@
"type": "string"
},
"completedTimestamp": {
"$ref": "#/definitions/Time"
"type": [
"string",
"null"
],
"format": "date-time"
},
"context": {
"type": "string"
Expand Down Expand Up @@ -296,7 +316,11 @@
"type": "string"
},
"startedTimestamp": {
"$ref": "#/definitions/Time"
"type": [
"string",
"null"
],
"format": "date-time"
},
"status": {
"type": "string"
Expand Down Expand Up @@ -351,7 +375,11 @@
"type": "string"
},
"completedTimestamp": {
"$ref": "#/definitions/Time"
"type": [
"string",
"null"
],
"format": "date-time"
},
"description": {
"type": "string"
Expand All @@ -366,7 +394,11 @@
"type": "string"
},
"startedTimestamp": {
"$ref": "#/definitions/Time"
"type": [
"string",
"null"
],
"format": "date-time"
},
"status": {
"type": "string"
Expand All @@ -381,7 +413,11 @@
"type": "string"
},
"completedTimestamp": {
"$ref": "#/definitions/Time"
"type": [
"string",
"null"
],
"format": "date-time"
},
"description": {
"type": "string"
Expand All @@ -397,7 +433,11 @@
"$ref": "#/definitions/PromotePullRequestStep"
},
"startedTimestamp": {
"$ref": "#/definitions/Time"
"type": [
"string",
"null"
],
"format": "date-time"
},
"status": {
"type": "string"
Expand All @@ -413,7 +453,11 @@
"PromotePullRequestStep": {
"properties": {
"completedTimestamp": {
"$ref": "#/definitions/Time"
"type": [
"string",
"null"
],
"format": "date-time"
},
"description": {
"type": "string"
Expand All @@ -428,7 +472,11 @@
"type": "string"
},
"startedTimestamp": {
"$ref": "#/definitions/Time"
"type": [
"string",
"null"
],
"format": "date-time"
},
"status": {
"type": "string"
Expand All @@ -440,7 +488,11 @@
"PromoteUpdateStep": {
"properties": {
"completedTimestamp": {
"$ref": "#/definitions/Time"
"type": [
"string",
"null"
],
"format": "date-time"
},
"description": {
"type": "string"
Expand All @@ -449,7 +501,11 @@
"type": "string"
},
"startedTimestamp": {
"$ref": "#/definitions/Time"
"type": [
"string",
"null"
],
"format": "date-time"
},
"status": {
"type": "string"
Expand Down Expand Up @@ -483,7 +539,11 @@
"StageActivityStep": {
"properties": {
"completedTimestamp": {
"$ref": "#/definitions/Time"
"type": [
"string",
"null"
],
"format": "date-time"
},
"description": {
"type": "string"
Expand All @@ -492,7 +552,11 @@
"type": "string"
},
"startedTimestamp": {
"$ref": "#/definitions/Time"
"type": [
"string",
"null"
],
"format": "date-time"
},
"status": {
"type": "string"
Expand Down
Loading

0 comments on commit e9b60c4

Please sign in to comment.