MCPcopy Index your code
hub / github.com/coder/coder / TestCreateValidateRichParameters

Function TestCreateValidateRichParameters

cli/create_test.go:1818–2085  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1816}
1817
1818func TestCreateValidateRichParameters(t *testing.T) {
1819 t.Parallel()
1820
1821 const (
1822 stringParameterName = "string_parameter"
1823 stringParameterValue = "abc"
1824
1825 listOfStringsParameterName = "list_of_strings_parameter"
1826
1827 numberParameterName = "number_parameter"
1828 numberParameterValue = "7"
1829
1830 boolParameterName = "bool_parameter"
1831 boolParameterValue = "true"
1832 )
1833
1834 numberRichParameters := []*proto.RichParameter{
1835 {Name: numberParameterName, Type: "number", Mutable: true, ValidationMin: ptr.Ref(int32(3)), ValidationMax: ptr.Ref(int32(10))},
1836 }
1837
1838 numberCustomErrorRichParameters := []*proto.RichParameter{
1839 {
1840 Name: numberParameterName, Type: "number", Mutable: true,
1841 ValidationMin: ptr.Ref(int32(3)), ValidationMax: ptr.Ref(int32(10)),
1842 ValidationError: "These are values: {min}, {max}, and {value}.",
1843 },
1844 }
1845
1846 stringRichParameters := []*proto.RichParameter{
1847 {Name: stringParameterName, Type: "string", Mutable: true, ValidationRegex: "^[a-z]+$", ValidationError: "this is error"},
1848 }
1849
1850 listOfStringsRichParameters := []*proto.RichParameter{
1851 {Name: listOfStringsParameterName, Type: "list(string)", Mutable: true, DefaultValue: `["aaa","bbb","ccc"]`},
1852 }
1853
1854 boolRichParameters := []*proto.RichParameter{
1855 {Name: boolParameterName, Type: "bool", Mutable: true},
1856 }
1857
1858 t.Run("ValidateString", func(t *testing.T) {
1859 t.Parallel()
1860
1861 client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
1862 owner := coderdtest.CreateFirstUser(t, client)
1863 member, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)
1864 version := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, prepareEchoResponses(stringRichParameters))
1865 coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
1866
1867 template := coderdtest.CreateTemplate(t, client, owner.OrganizationID, version.ID)
1868
1869 inv, root := clitest.New(t, "create", "my-workspace", "--template", template.Name)
1870 clitest.SetupConfig(t, member, root)
1871 doneChan := make(chan struct{})
1872 pty := ptytest.New(t).Attach(inv)
1873 go func() {
1874 defer close(doneChan)
1875 err := inv.Run()

Callers

nothing calls this directly

Calls 15

RefFunction · 0.92
NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
CreateTemplateVersionFunction · 0.92
CreateTemplateFunction · 0.92
NewFunction · 0.92
SetupConfigFunction · 0.92
NewFunction · 0.92
StartFunction · 0.92
RunFunction · 0.92

Tested by

no test coverage detected