Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor consistency fixes #1094

Merged
merged 2 commits into from
Jul 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 39 additions & 42 deletions pkg/apis/pipeline/v1alpha1/pull_request_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,53 +64,50 @@ type testcase struct {
}

func containerTestCases(mode string) []testcase {
return []testcase{
{
in: &v1alpha1.PullRequestResource{
Name: "nocreds",
DestinationDir: "/workspace",
URL: "https://example.com",
},
out: []corev1.Container{{
Name: "pr-source-nocreds-9l9zj",
Image: "override-with-pr:latest",
WorkingDir: v1alpha1.WorkspaceDir,
Command: []string{"/ko-app/pullrequest-init"},
Args: []string{"-url", "https://example.com", "-path", "/workspace", "-mode", mode},
Env: []corev1.EnvVar{},
return []testcase{{
in: &v1alpha1.PullRequestResource{
Name: "nocreds",
DestinationDir: "/workspace",
URL: "https://example.com",
},
out: []corev1.Container{{
Name: "pr-source-nocreds-9l9zj",
Image: "override-with-pr:latest",
WorkingDir: v1alpha1.WorkspaceDir,
Command: []string{"/ko-app/pullrequest-init"},
Args: []string{"-url", "https://example.com", "-path", "/workspace", "-mode", mode},
Env: []corev1.EnvVar{},
}},
}, {
in: &v1alpha1.PullRequestResource{
Name: "creds",
DestinationDir: "/workspace",
URL: "https://example.com",
Secrets: []v1alpha1.SecretParam{{
FieldName: "githubToken",
SecretName: "github-creds",
SecretKey: "token",
}},
},
{
in: &v1alpha1.PullRequestResource{
Name: "creds",
DestinationDir: "/workspace",
URL: "https://example.com",
Secrets: []v1alpha1.SecretParam{{
FieldName: "githubToken",
SecretName: "github-creds",
SecretKey: "token",
}},
},
out: []corev1.Container{{
Name: "pr-source-creds-mz4c7",
Image: "override-with-pr:latest",
WorkingDir: v1alpha1.WorkspaceDir,
Command: []string{"/ko-app/pullrequest-init"},
Args: []string{"-url", "https://example.com", "-path", "/workspace", "-mode", mode},
Env: []corev1.EnvVar{{
Name: "GITHUBTOKEN",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: "github-creds",
},
Key: "token",
out: []corev1.Container{{
Name: "pr-source-creds-mz4c7",
Image: "override-with-pr:latest",
WorkingDir: v1alpha1.WorkspaceDir,
Command: []string{"/ko-app/pullrequest-init"},
Args: []string{"-url", "https://example.com", "-path", "/workspace", "-mode", mode},
Env: []corev1.EnvVar{{
Name: "GITHUBTOKEN",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: "github-creds",
},
Key: "token",
},
}},
},
}},
},
}
}},
}}
}

func TestPullRequest_GetDownloadContainerSpec(t *testing.T) {
Expand Down
55 changes: 25 additions & 30 deletions pkg/apis/pipeline/v1alpha1/result_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,40 +41,35 @@ func TestValidate_Invalid(t *testing.T) {
name string
results *v1alpha1.Results
want *apis.FieldError
}{
{
name: "invalid task type result",
results: &v1alpha1.Results{
URL: "http://www.google.com",
Type: "wrongtype",
},
want: apis.ErrInvalidValue("wrongtype", "spec.results.Type"),
}{{
name: "invalid task type result",
results: &v1alpha1.Results{
URL: "http://www.google.com",
Type: "wrongtype",
},
{
name: "invalid task type results missing url",
results: &v1alpha1.Results{
Type: v1alpha1.ResultTargetTypeGCS,
URL: "",
},
want: apis.ErrMissingField("spec.results.URL"),
want: apis.ErrInvalidValue("wrongtype", "spec.results.Type"),
}, {
name: "invalid task type results missing url",
results: &v1alpha1.Results{
Type: v1alpha1.ResultTargetTypeGCS,
URL: "",
},
{
name: "invalid task type results bad url",
results: &v1alpha1.Results{
Type: v1alpha1.ResultTargetTypeGCS,
URL: "badurl",
},
want: apis.ErrInvalidValue("badurl", "spec.results.URL"),
want: apis.ErrMissingField("spec.results.URL"),
}, {
name: "invalid task type results bad url",
results: &v1alpha1.Results{
Type: v1alpha1.ResultTargetTypeGCS,
URL: "badurl",
},
{
name: "invalid task type results type",
results: &v1alpha1.Results{
Type: "badtype",
URL: "http://www.google.com",
},
want: apis.ErrInvalidValue("badtype", "spec.results.Type"),
want: apis.ErrInvalidValue("badurl", "spec.results.URL"),
}, {
name: "invalid task type results type",
results: &v1alpha1.Results{
Type: "badtype",
URL: "http://www.google.com",
},
}
want: apis.ErrInvalidValue("badtype", "spec.results.Type"),
}}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
path := "spec.results"
Expand Down
Loading