-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from jstrachan/changes2
fix: add fix and tests for validation
- Loading branch information
Showing
12 changed files
with
359 additions
and
384 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Source: jxboot-helmfile-resources/templates/environments.yaml | ||
apiVersion: jenkins.io/v1 | ||
kind: Environment | ||
metadata: | ||
labels: | ||
env: "dev" | ||
team: jx | ||
name: "bad" | ||
spec: | ||
invalidPropertyName: cheese | ||
source: | ||
ref: "master" | ||
url: https://github.com/myorg/environment-mycluster-dev.git | ||
kind: Development | ||
label: Development | ||
namespace: jx | ||
promotionStrategy: "Never" | ||
webHookEngine: "Lighthouse" | ||
teamSettings: | ||
appsRepository: http://chartmuseum.jenkins-x.io | ||
defaultScheduler: | ||
apiVersion: jenkins.io/v1 | ||
kind: Scheduler | ||
name: jx-meta-pipeline | ||
dockerRegistryOrg: "" | ||
envOrganisation: myorg | ||
gitServer: https://github.com | ||
gitPublic: true | ||
kubeProvider: "kubernetes" | ||
pipelineUsername: "jenkins-x-labs-bot" | ||
pipelineUserEmail: "jenkins-x@googlegroups.com" | ||
prowConfig: Scheduler |
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,31 @@ | ||
# Source: jxboot-helmfile-resources/templates/environments.yaml | ||
apiVersion: jenkins.io/v1 | ||
kind: Environment | ||
metadata: | ||
labels: | ||
env: "dev" | ||
team: jx | ||
name: "dev" | ||
spec: | ||
source: | ||
ref: "master" | ||
url: https://github.com/myorg/environment-mycluster-dev.git | ||
kind: Development | ||
label: Development | ||
namespace: jx | ||
promotionStrategy: "Never" | ||
webHookEngine: "Lighthouse" | ||
teamSettings: | ||
appsRepository: http://chartmuseum.jenkins-x.io | ||
defaultScheduler: | ||
apiVersion: jenkins.io/v1 | ||
kind: Scheduler | ||
name: jx-meta-pipeline | ||
dockerRegistryOrg: "" | ||
envOrganisation: myorg | ||
gitServer: https://github.com | ||
gitPublic: true | ||
kubeProvider: "kubernetes" | ||
pipelineUsername: "jenkins-x-labs-bot" | ||
pipelineUserEmail: "jenkins-x@googlegroups.com" | ||
prowConfig: Scheduler |
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,49 @@ | ||
package util_test | ||
|
||
import ( | ||
"github.com/ghodss/yaml" | ||
v1 "github.com/jenkins-x/jx-api/v4/pkg/apis/jenkins.io/v1" | ||
"github.com/jenkins-x/jx-api/v4/pkg/util" | ||
"github.com/stretchr/testify/require" | ||
"io/ioutil" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
func TestValidation(t *testing.T) { | ||
t.Parallel() | ||
|
||
path := filepath.Join("test_data", "good_env.yaml") | ||
data, err := ioutil.ReadFile(path) | ||
require.NoError(t, err, "failed to load %s", path) | ||
|
||
deploy := &v1.Environment{} | ||
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() | ||
|
||
path := filepath.Join("test_data", "bad_env.yaml") | ||
data, err := ioutil.ReadFile(path) | ||
require.NoError(t, err, "failed to load %s", path) | ||
|
||
deploy := &v1.Environment{} | ||
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.NotEmpty(t, results, "should have validation errors for file %s", path) | ||
} |
Oops, something went wrong.