-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In this change, we clean up the `isCustomTask` function: - Remove unused `context.Context` - Remove the check that either `TaskRef` or `TaskSpec` is specified because we check that way before - see [code]. - Define the check that `TaskRef` is a `CustomTask` as a member function of `TaskRef`; and add tests for the member function. - Define the check that `TaskSpec` is a `CustomTask` as a member function of `TaskSpec`; and add tests for the member function. There are no user-facing changes in this commit. [code]: https://github.com/tektoncd/pipeline/blob/b7d815a9d8528547994f65da097050f472bbb8b2/pkg/apis/pipeline/v1beta1/pipeline_types.go#L216-L227
- Loading branch information
Showing
10 changed files
with
215 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package v1 | ||
|
||
import "testing" | ||
|
||
func TestTaskRef_IsCustomTask(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
tr *TaskRef | ||
want bool | ||
}{{ | ||
name: "not a custom task - apiVersion and Kind are not set", | ||
tr: &TaskRef{ | ||
Name: "foo", | ||
}, | ||
want: false, | ||
}, { | ||
name: "not a custom task - apiVersion is not set", | ||
tr: &TaskRef{ | ||
Name: "foo", | ||
Kind: "Example", | ||
}, | ||
want: false, | ||
}, { | ||
name: "not a custom task - kind is not set", | ||
tr: &TaskRef{ | ||
Name: "foo", | ||
APIVersion: "example/v0", | ||
}, | ||
want: false, | ||
}, { | ||
name: "custom task with name", | ||
tr: &TaskRef{ | ||
Name: "foo", | ||
Kind: "Example", | ||
APIVersion: "example/v0", | ||
}, | ||
want: true, | ||
}, { | ||
name: "custom task without name", | ||
tr: &TaskRef{ | ||
Kind: "Example", | ||
APIVersion: "example/v0", | ||
}, | ||
want: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := tt.tr.IsCustomTask(); got != tt.want { | ||
t.Errorf("IsCustomTask() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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,54 @@ | ||
package v1beta1 | ||
|
||
import "testing" | ||
|
||
func TestTaskRef_IsCustomTask(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
tr *TaskRef | ||
want bool | ||
}{{ | ||
name: "not a custom task - apiVersion and Kind are not set", | ||
tr: &TaskRef{ | ||
Name: "foo", | ||
}, | ||
want: false, | ||
}, { | ||
name: "not a custom task - apiVersion is not set", | ||
tr: &TaskRef{ | ||
Name: "foo", | ||
Kind: "Example", | ||
}, | ||
want: false, | ||
}, { | ||
name: "not a custom task - kind is not set", | ||
tr: &TaskRef{ | ||
Name: "foo", | ||
APIVersion: "example/v0", | ||
}, | ||
want: false, | ||
}, { | ||
name: "custom task with name", | ||
tr: &TaskRef{ | ||
Name: "foo", | ||
Kind: "Example", | ||
APIVersion: "example/v0", | ||
}, | ||
want: true, | ||
}, { | ||
name: "custom task without name", | ||
tr: &TaskRef{ | ||
Kind: "Example", | ||
APIVersion: "example/v0", | ||
}, | ||
want: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := tt.tr.IsCustomTask(); got != tt.want { | ||
t.Errorf("IsCustomTask() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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