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

Provides interactive prompt for workspace option while starting Task/TaskRun #1005

Closed
wants to merge 1 commit into from
Closed

Provides interactive prompt for workspace option while starting Task/TaskRun #1005

wants to merge 1 commit into from

Conversation

anshulvermapatel
Copy link
Contributor

Provides interactive prompt for workspace options for Task/ClusterTask.

Fixes #958

Changes

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes tests (if functionality changed/added)
  • Run the code checkers with make check
  • Regenerate the manpages, docs and go formatting with make generated
  • Commit messages follow commit message best practices

See the contribution guide
for more details.

Release Notes

release-note

@tekton-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign piyush-garg
You can assign the PR to them by writing /assign @piyush-garg in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label May 31, 2020
@tekton-robot
Copy link
Contributor

Hi @anshulvermapatel. Thanks for your PR.

I'm waiting for a tektoncd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@tekton-robot tekton-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label May 31, 2020
@anshulvermapatel anshulvermapatel changed the title Provides interactive prompt for workspace option while starting `Ta… Provides interactive prompt for workspace option while starting Task/TaskRun May 31, 2020
@anshulvermapatel
Copy link
Contributor Author

In Addition, I tried adding tests for the Prompt asking for Workspace detail by adding the following code in the TestTaskStart_ExecuteCommand_Workspace_v1beta1 function in pkg/cmd/task/start_test.go file, and same can be implemented for ClusterTask as well, but It did not work. If you can help me on this, we can increase the test coverage.

Code Snippet in TestTaskStart_ExecuteCommand_Workspace_v1beta1 func -

	workspaces := [][]string{
		{"name=emptyDirWorkspace,subPath=emptyDirSubPath,emptyDir="},
	}

	testPromptParams := []struct {
		name string
		//resource string
		prompt prompt.Prompt
		//options  []string
		want []string
	}{
		{
			name: "emptyDir",
			//resource: ResourceNamePipeline,
			prompt: prompt.Prompt{
				CmdArgs: []string{},
				Procedure: func(c *goexpect.Console) error {
					fmt.Println("In Procedure")
					// if _, err := c.ExpectString("Please give specifications for the workspace: test"); err != nil {
					// 	return err
					// }
					fmt.Println("After First Condition")
					if _, err := c.ExpectString("? Name for the workspace :"); err != nil {
						return err
					}
					if _, err := c.Send("emptyDirWorkspace"); err != nil {
						return err
					}

					if _, err := c.ExpectString("Value of the Sub Path :"); err != nil {
						return err
					}
					if _, err := c.SendLine("emptyDirSubPath"); err != nil {
						return err
					}

					if _, err := c.ExpectString("Type of the Workspace :"); err != nil {
						return err
					}
					if _, err := c.SendLine("emptyDir"); err != nil {
						return err
					}

					if _, err := c.ExpectString("Type of EmtpyDir :"); err != nil {
						return err
					}
					if _, err := c.SendLine(""); err != nil {
						return err
					}

					return nil
				},
			},
			//options: options,
			//want: workspaces[0],
		},
	}

	for _, tp := range testPromptParams {
		t.Run(tp.name, func(t *testing.T) {
			opts := &startOptions{}
			//var cmd *cobra.Command
			// opts.stream = &cli.Stream{
			// 	Out: os.Stdout, //cmd.OutOrStdout(),
			// 	Err: os.Stderr, //cmd.OutOrStderr(),
			// }
			tp.prompt.RunTest(t, tp.prompt.Procedure, func(stdio terminal.Stdio) error {
				opts.askOpts = prompt.WithStdio(stdio)
				return opts.getInputWorkspaces(tasks[0])
			})
			fmt.Println(opts.Workspaces)
			if !reflect.DeepEqual(opts.Workspaces, workspaces[0]) {
				t.Errorf("Unexpected Workspace Values")
			}

		})
	}

This is how the prompts are unit tested for TR/PR logs in the file pkg/cmd/task/logs_test.go. I may have made some mistake in task start test.

@anshulvermapatel
Copy link
Contributor Author

For Task the same thing has already been implemented by #987. Closing this one. Will open a new one for CusterTask.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Workspace Option for tkn clustertask start
2 participants