Skip to content

chore(docs): document how to correctly override list(string) parameters #15497

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

Merged
merged 4 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
address PR comments
  • Loading branch information
johnstcn committed Nov 13, 2024
commit b1d032648b1019e06a841327bf3aff94c0dcb779
41 changes: 8 additions & 33 deletions cli/create_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package cli_test

import (
"bytes"
"context"
"encoding/csv"
"encoding/json"
"fmt"
"net/http"
"os"
"regexp"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -874,19 +870,10 @@ func TestCreateValidateRichParameters(t *testing.T) {
pty := ptytest.New(t).Attach(inv)
clitest.Start(t, inv)

matches := []string{
listOfStringsParameterName, "",
"aaa, bbb, ccc", "",
"Confirm create?", "yes",
}
for i := 0; i < len(matches); i += 2 {
match := matches[i]
value := matches[i+1]
pty.ExpectMatch(match)
if value != "" {
pty.WriteLine(value)
}
}
pty.ExpectMatch(listOfStringsParameterName)
pty.ExpectMatch("aaa, bbb, ccc")
pty.ExpectMatch("Confirm create?")
pty.WriteLine("yes")
})

t.Run("Default", func(t *testing.T) {
Expand All @@ -898,25 +885,13 @@ func TestCreateValidateRichParameters(t *testing.T) {

t.Run("CLIOverride/DoubleQuote", func(t *testing.T) {
t.Parallel()
inv, root := clitest.New(t, "create", "my-workspace-3", "--template", template.Name, "--parameter", "\""+listOfStringsParameterName+"=[\"\"ddd=foo\"\",\"\"eee=bar\"\",\"\"fff=baz\"\"]\"", "--yes")

// Note: see https://go.dev/play/p/vhTUTZsVrEb for how to escape this properly
parameterArg := fmt.Sprintf(`"%s=[""ddd=foo"",""eee=bar"",""fff=baz""]"`, listOfStringsParameterName)
inv, root := clitest.New(t, "create", "my-workspace-3", "--template", template.Name, "--parameter", parameterArg, "--yes")
clitest.SetupConfig(t, member, root)
clitest.Run(t, inv)
})

t.Run("WhatShouldItLookLike", func(t *testing.T) {
t.Parallel()

var (
b bytes.Buffer
sb strings.Builder
)
require.NoError(t, json.NewEncoder(&b).Encode([]string{"ddd=foo", "eee=bar", "fff=baz"}))
cw := csv.NewWriter(&sb)
require.NoError(t, cw.Write([]string{listOfStringsParameterName + "=" + b.String()}))
cw.Flush()
require.NoError(t, cw.Error())
t.Logf("it looks like this: \n%q", strings.TrimSpace(sb.String()))
})
})

t.Run("ValidateListOfStrings_YAMLFile", func(t *testing.T) {
Expand Down
3 changes: 0 additions & 3 deletions docs/admin/templates/extending-templates/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ data "coder_parameter" "security_groups" {
> --parameter "\"security_groups=[\"\"DevOps Security Group\"\",\"\"Backend Security Group\"\"]\""
> ```
>
> You can use [this Go Playground link](https://go.dev/play/p/yvI9rdtS0ch) to
> generate a correctly-quoted argument.
>
> Alternatively, you can use `--rich-parameter-file` to work around the above
> issues. This allows you to specify parameters as YAML. An equivalent parameter
> file for the above `--parameter` is provided below:
Expand Down
Loading