Skip to content

Commit

Permalink
Attempt to make bracket use consistent in testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
EliZucker authored and tekton-robot committed Jul 22, 2019
1 parent ac0b5c6 commit 75bd14f
Show file tree
Hide file tree
Showing 12 changed files with 714 additions and 834 deletions.
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

0 comments on commit 75bd14f

Please sign in to comment.