Best K6 code snippet using ui.Run
bindingrule_update_test.go
Source:bindingrule_update_test.go
...16 _ "github.com/hashicorp/consul/agent/consul/authmethod/testauth"17)18func TestBindingRuleUpdateCommand_noTabs(t *testing.T) {19 t.Parallel()20 if strings.ContainsRune(New(cli.NewMockUi()).Help(), '\t') {21 t.Fatal("help has tabs")22 }23}24func TestBindingRuleUpdateCommand(t *testing.T) {25 t.Parallel()26 testDir := testutil.TempDir(t, "acl")27 defer os.RemoveAll(testDir)28 a := agent.NewTestAgent(t, `29 primary_datacenter = "dc1"30 acl {31 enabled = true32 tokens {33 master = "root"34 }35 }`)36 defer a.Shutdown()37 testrpc.WaitForLeader(t, a.RPC, "dc1")38 client := a.Client()39 // create an auth method in advance40 {41 _, _, err := client.ACL().AuthMethodCreate(42 &api.ACLAuthMethod{43 Name: "test",44 Type: "testing",45 },46 &api.WriteOptions{Token: "root"},47 )48 require.NoError(t, err)49 }50 deleteRules := func(t *testing.T) {51 rules, _, err := client.ACL().BindingRuleList(52 "test",53 &api.QueryOptions{Token: "root"},54 )55 require.NoError(t, err)56 for _, rule := range rules {57 _, err := client.ACL().BindingRuleDelete(58 rule.ID,59 &api.WriteOptions{Token: "root"},60 )61 require.NoError(t, err)62 }63 }64 t.Run("rule id required", func(t *testing.T) {65 args := []string{66 "-http-addr=" + a.HTTPAddr(),67 "-token=root",68 }69 ui := cli.NewMockUi()70 cmd := New(ui)71 code := cmd.Run(args)72 require.Equal(t, code, 1)73 require.Contains(t, ui.ErrorWriter.String(), "Cannot update a binding rule without specifying the -id parameter")74 })75 t.Run("rule id partial matches nothing", func(t *testing.T) {76 fakeID, err := uuid.GenerateUUID()77 require.NoError(t, err)78 ui := cli.NewMockUi()79 cmd := New(ui)80 args := []string{81 "-http-addr=" + a.HTTPAddr(),82 "-id=" + fakeID[0:5],83 "-token=root",84 "-description=test rule edited",85 }86 code := cmd.Run(args)87 require.Equal(t, code, 1)88 require.Contains(t, ui.ErrorWriter.String(), "Error determining binding rule ID")89 })90 t.Run("rule id exact match doesn't exist", func(t *testing.T) {91 fakeID, err := uuid.GenerateUUID()92 require.NoError(t, err)93 ui := cli.NewMockUi()94 cmd := New(ui)95 args := []string{96 "-http-addr=" + a.HTTPAddr(),97 "-id=" + fakeID,98 "-token=root",99 "-description=test rule edited",100 }101 code := cmd.Run(args)102 require.Equal(t, code, 1)103 require.Contains(t, ui.ErrorWriter.String(), "Binding rule not found with ID")104 })105 createRule := func(t *testing.T) string {106 rule, _, err := client.ACL().BindingRuleCreate(107 &api.ACLBindingRule{108 AuthMethod: "test",109 Description: "test rule",110 BindType: api.BindingRuleBindTypeService,111 BindName: "test-${serviceaccount.name}",112 Selector: "serviceaccount.namespace==default",113 },114 &api.WriteOptions{Token: "root"},115 )116 require.NoError(t, err)117 return rule.ID118 }119 createDupe := func(t *testing.T) string {120 for {121 // Check for 1-char duplicates.122 rules, _, err := client.ACL().BindingRuleList(123 "test",124 &api.QueryOptions{Token: "root"},125 )126 require.NoError(t, err)127 m := make(map[byte]struct{})128 for _, rule := range rules {129 c := rule.ID[0]130 if _, ok := m[c]; ok {131 return string(c)132 }133 m[c] = struct{}{}134 }135 _ = createRule(t)136 }137 }138 t.Run("rule id partial matches multiple", func(t *testing.T) {139 prefix := createDupe(t)140 ui := cli.NewMockUi()141 cmd := New(ui)142 args := []string{143 "-http-addr=" + a.HTTPAddr(),144 "-id=" + prefix,145 "-token=root",146 "-description=test rule edited",147 }148 code := cmd.Run(args)149 require.Equal(t, code, 1)150 require.Contains(t, ui.ErrorWriter.String(), "Error determining binding rule ID")151 })152 t.Run("must use roughly valid selector", func(t *testing.T) {153 id := createRule(t)154 args := []string{155 "-http-addr=" + a.HTTPAddr(),156 "-token=root",157 "-id", id,158 "-selector", "foo",159 }160 ui := cli.NewMockUi()161 cmd := New(ui)162 code := cmd.Run(args)163 require.Equal(t, code, 1)164 require.Contains(t, ui.ErrorWriter.String(), "Selector is invalid")165 })166 t.Run("update all fields", func(t *testing.T) {167 id := createRule(t)168 ui := cli.NewMockUi()169 cmd := New(ui)170 args := []string{171 "-http-addr=" + a.HTTPAddr(),172 "-token=root",173 "-id", id,174 "-description=test rule edited",175 "-bind-type", "role",176 "-bind-name=role-updated",177 "-selector=serviceaccount.namespace==alt and serviceaccount.name==demo",178 }179 code := cmd.Run(args)180 require.Equal(t, code, 0, "err: %s", ui.ErrorWriter.String())181 require.Empty(t, ui.ErrorWriter.String())182 rule, _, err := client.ACL().BindingRuleRead(183 id,184 &api.QueryOptions{Token: "root"},185 )186 require.NoError(t, err)187 require.NotNil(t, rule)188 require.Equal(t, "test rule edited", rule.Description)189 require.Equal(t, "role-updated", rule.BindName)190 require.Equal(t, api.BindingRuleBindTypeRole, rule.BindType)191 require.Equal(t, "serviceaccount.namespace==alt and serviceaccount.name==demo", rule.Selector)192 })193 t.Run("update all fields - partial", func(t *testing.T) {194 deleteRules(t) // reset since we created a bunch that might be dupes195 id := createRule(t)196 ui := cli.NewMockUi()197 cmd := New(ui)198 args := []string{199 "-http-addr=" + a.HTTPAddr(),200 "-token=root",201 "-id", id[0:5],202 "-description=test rule edited",203 "-bind-type", "role",204 "-bind-name=role-updated",205 "-selector=serviceaccount.namespace==alt and serviceaccount.name==demo",206 }207 code := cmd.Run(args)208 require.Equal(t, code, 0, "err: %s", ui.ErrorWriter.String())209 require.Empty(t, ui.ErrorWriter.String())210 rule, _, err := client.ACL().BindingRuleRead(211 id,212 &api.QueryOptions{Token: "root"},213 )214 require.NoError(t, err)215 require.NotNil(t, rule)216 require.Equal(t, "test rule edited", rule.Description)217 require.Equal(t, "role-updated", rule.BindName)218 require.Equal(t, api.BindingRuleBindTypeRole, rule.BindType)219 require.Equal(t, "serviceaccount.namespace==alt and serviceaccount.name==demo", rule.Selector)220 })221 t.Run("update all fields but description", func(t *testing.T) {222 id := createRule(t)223 ui := cli.NewMockUi()224 cmd := New(ui)225 args := []string{226 "-http-addr=" + a.HTTPAddr(),227 "-token=root",228 "-id", id,229 "-bind-type", "role",230 "-bind-name=role-updated",231 "-selector=serviceaccount.namespace==alt and serviceaccount.name==demo",232 }233 code := cmd.Run(args)234 require.Equal(t, code, 0, "err: %s", ui.ErrorWriter.String())235 require.Empty(t, ui.ErrorWriter.String())236 rule, _, err := client.ACL().BindingRuleRead(237 id,238 &api.QueryOptions{Token: "root"},239 )240 require.NoError(t, err)241 require.NotNil(t, rule)242 require.Equal(t, "test rule", rule.Description)243 require.Equal(t, api.BindingRuleBindTypeRole, rule.BindType)244 require.Equal(t, "role-updated", rule.BindName)245 require.Equal(t, "serviceaccount.namespace==alt and serviceaccount.name==demo", rule.Selector)246 })247 t.Run("update all fields but bind name", func(t *testing.T) {248 id := createRule(t)249 ui := cli.NewMockUi()250 cmd := New(ui)251 args := []string{252 "-http-addr=" + a.HTTPAddr(),253 "-token=root",254 "-id", id,255 "-description=test rule edited",256 "-bind-type", "role",257 "-selector=serviceaccount.namespace==alt and serviceaccount.name==demo",258 }259 code := cmd.Run(args)260 require.Equal(t, code, 0, "err: %s", ui.ErrorWriter.String())261 require.Empty(t, ui.ErrorWriter.String())262 rule, _, err := client.ACL().BindingRuleRead(263 id,264 &api.QueryOptions{Token: "root"},265 )266 require.NoError(t, err)267 require.NotNil(t, rule)268 require.Equal(t, "test rule edited", rule.Description)269 require.Equal(t, api.BindingRuleBindTypeRole, rule.BindType)270 require.Equal(t, "test-${serviceaccount.name}", rule.BindName)271 require.Equal(t, "serviceaccount.namespace==alt and serviceaccount.name==demo", rule.Selector)272 })273 t.Run("update all fields but must exist", func(t *testing.T) {274 id := createRule(t)275 ui := cli.NewMockUi()276 cmd := New(ui)277 args := []string{278 "-http-addr=" + a.HTTPAddr(),279 "-token=root",280 "-id", id,281 "-description=test rule edited",282 "-bind-name=role-updated",283 "-selector=serviceaccount.namespace==alt and serviceaccount.name==demo",284 }285 code := cmd.Run(args)286 require.Equal(t, code, 0, "err: %s", ui.ErrorWriter.String())287 require.Empty(t, ui.ErrorWriter.String())288 rule, _, err := client.ACL().BindingRuleRead(289 id,290 &api.QueryOptions{Token: "root"},291 )292 require.NoError(t, err)293 require.NotNil(t, rule)294 require.Equal(t, "test rule edited", rule.Description)295 require.Equal(t, api.BindingRuleBindTypeService, rule.BindType)296 require.Equal(t, "role-updated", rule.BindName)297 require.Equal(t, "serviceaccount.namespace==alt and serviceaccount.name==demo", rule.Selector)298 })299 t.Run("update all fields but selector", func(t *testing.T) {300 id := createRule(t)301 ui := cli.NewMockUi()302 cmd := New(ui)303 args := []string{304 "-http-addr=" + a.HTTPAddr(),305 "-token=root",306 "-id", id,307 "-description=test rule edited",308 "-bind-type", "role",309 "-bind-name=role-updated",310 }311 code := cmd.Run(args)312 require.Equal(t, code, 0, "err: %s", ui.ErrorWriter.String())313 require.Empty(t, ui.ErrorWriter.String())314 rule, _, err := client.ACL().BindingRuleRead(315 id,316 &api.QueryOptions{Token: "root"},317 )318 require.NoError(t, err)319 require.NotNil(t, rule)320 require.Equal(t, "test rule edited", rule.Description)321 require.Equal(t, api.BindingRuleBindTypeRole, rule.BindType)322 require.Equal(t, "role-updated", rule.BindName)323 require.Equal(t, "serviceaccount.namespace==default", rule.Selector)324 })325 t.Run("update all fields clear selector", func(t *testing.T) {326 id := createRule(t)327 ui := cli.NewMockUi()328 cmd := New(ui)329 args := []string{330 "-http-addr=" + a.HTTPAddr(),331 "-token=root",332 "-id", id,333 "-description=test rule edited",334 "-bind-type", "role",335 "-bind-name=role-updated",336 "-selector=",337 }338 code := cmd.Run(args)339 require.Equal(t, code, 0, "err: %s", ui.ErrorWriter.String())340 require.Empty(t, ui.ErrorWriter.String())341 rule, _, err := client.ACL().BindingRuleRead(342 id,343 &api.QueryOptions{Token: "root"},344 )345 require.NoError(t, err)346 require.NotNil(t, rule)347 require.Equal(t, "test rule edited", rule.Description)348 require.Equal(t, api.BindingRuleBindTypeRole, rule.BindType)349 require.Equal(t, "role-updated", rule.BindName)350 require.Empty(t, rule.Selector)351 })352 t.Run("update all fields json formatted", func(t *testing.T) {353 id := createRule(t)354 ui := cli.NewMockUi()355 cmd := New(ui)356 args := []string{357 "-http-addr=" + a.HTTPAddr(),358 "-token=root",359 "-id", id,360 "-description=test rule edited",361 "-bind-type", "role",362 "-bind-name=role-updated",363 "-selector=serviceaccount.namespace==alt and serviceaccount.name==demo",364 "-format=json",365 }366 code := cmd.Run(args)367 require.Equal(t, code, 0, "err: %s", ui.ErrorWriter.String())368 require.Empty(t, ui.ErrorWriter.String())369 rule, _, err := client.ACL().BindingRuleRead(370 id,371 &api.QueryOptions{Token: "root"},372 )373 require.NoError(t, err)374 require.NotNil(t, rule)375 require.Equal(t, "test rule edited", rule.Description)376 require.Equal(t, "role-updated", rule.BindName)377 require.Equal(t, api.BindingRuleBindTypeRole, rule.BindType)378 require.Equal(t, "serviceaccount.namespace==alt and serviceaccount.name==demo", rule.Selector)379 output := ui.OutputWriter.String()380 var jsonOutput json.RawMessage381 err = json.Unmarshal([]byte(output), &jsonOutput)382 assert.NoError(t, err)383 })384}385func TestBindingRuleUpdateCommand_noMerge(t *testing.T) {386 t.Parallel()387 testDir := testutil.TempDir(t, "acl")388 defer os.RemoveAll(testDir)389 a := agent.NewTestAgent(t, `390 primary_datacenter = "dc1"391 acl {392 enabled = true393 tokens {394 master = "root"395 }396 }`)397 defer a.Shutdown()398 testrpc.WaitForLeader(t, a.RPC, "dc1")399 client := a.Client()400 // create an auth method in advance401 {402 _, _, err := client.ACL().AuthMethodCreate(403 &api.ACLAuthMethod{404 Name: "test",405 Type: "testing",406 },407 &api.WriteOptions{Token: "root"},408 )409 require.NoError(t, err)410 }411 deleteRules := func(t *testing.T) {412 rules, _, err := client.ACL().BindingRuleList(413 "test",414 &api.QueryOptions{Token: "root"},415 )416 require.NoError(t, err)417 for _, rule := range rules {418 _, err := client.ACL().BindingRuleDelete(419 rule.ID,420 &api.WriteOptions{Token: "root"},421 )422 require.NoError(t, err)423 }424 }425 t.Run("rule id required", func(t *testing.T) {426 args := []string{427 "-http-addr=" + a.HTTPAddr(),428 "-token=root",429 "-no-merge",430 }431 ui := cli.NewMockUi()432 cmd := New(ui)433 code := cmd.Run(args)434 require.Equal(t, code, 1)435 require.Contains(t, ui.ErrorWriter.String(), "Cannot update a binding rule without specifying the -id parameter")436 })437 t.Run("rule id partial matches nothing", func(t *testing.T) {438 fakeID, err := uuid.GenerateUUID()439 require.NoError(t, err)440 ui := cli.NewMockUi()441 cmd := New(ui)442 args := []string{443 "-http-addr=" + a.HTTPAddr(),444 "-id=" + fakeID[0:5],445 "-token=root",446 "-no-merge",447 "-description=test rule edited",448 }449 code := cmd.Run(args)450 require.Equal(t, code, 1)451 require.Contains(t, ui.ErrorWriter.String(), "Error determining binding rule ID")452 })453 t.Run("rule id exact match doesn't exist", func(t *testing.T) {454 fakeID, err := uuid.GenerateUUID()455 require.NoError(t, err)456 ui := cli.NewMockUi()457 cmd := New(ui)458 args := []string{459 "-http-addr=" + a.HTTPAddr(),460 "-id=" + fakeID,461 "-token=root",462 "-no-merge",463 "-description=test rule edited",464 }465 code := cmd.Run(args)466 require.Equal(t, code, 1)467 require.Contains(t, ui.ErrorWriter.String(), "Binding rule not found with ID")468 })469 createRule := func(t *testing.T) string {470 rule, _, err := client.ACL().BindingRuleCreate(471 &api.ACLBindingRule{472 AuthMethod: "test",473 Description: "test rule",474 BindType: api.BindingRuleBindTypeRole,475 BindName: "test-${serviceaccount.name}",476 Selector: "serviceaccount.namespace==default",477 },478 &api.WriteOptions{Token: "root"},479 )480 require.NoError(t, err)481 return rule.ID482 }483 createDupe := func(t *testing.T) string {484 for {485 // Check for 1-char duplicates.486 rules, _, err := client.ACL().BindingRuleList(487 "test",488 &api.QueryOptions{Token: "root"},489 )490 require.NoError(t, err)491 m := make(map[byte]struct{})492 for _, rule := range rules {493 c := rule.ID[0]494 if _, ok := m[c]; ok {495 return string(c)496 }497 m[c] = struct{}{}498 }499 _ = createRule(t)500 }501 }502 t.Run("rule id partial matches multiple", func(t *testing.T) {503 prefix := createDupe(t)504 ui := cli.NewMockUi()505 cmd := New(ui)506 args := []string{507 "-http-addr=" + a.HTTPAddr(),508 "-id=" + prefix,509 "-token=root",510 "-no-merge",511 "-description=test rule edited",512 }513 code := cmd.Run(args)514 require.Equal(t, code, 1)515 require.Contains(t, ui.ErrorWriter.String(), "Error determining binding rule ID")516 })517 t.Run("must use roughly valid selector", func(t *testing.T) {518 id := createRule(t)519 ui := cli.NewMockUi()520 cmd := New(ui)521 args := []string{522 "-http-addr=" + a.HTTPAddr(),523 "-token=root",524 "-no-merge",525 "-id", id,526 "-description=test rule edited",527 "-bind-type", "service",528 "-bind-name=role-updated",529 "-selector", "foo",530 }531 code := cmd.Run(args)532 require.Equal(t, code, 1)533 require.Contains(t, ui.ErrorWriter.String(), "Selector is invalid")534 })535 t.Run("update all fields", func(t *testing.T) {536 id := createRule(t)537 ui := cli.NewMockUi()538 cmd := New(ui)539 args := []string{540 "-http-addr=" + a.HTTPAddr(),541 "-token=root",542 "-no-merge",543 "-id", id,544 "-description=test rule edited",545 "-bind-type", "service",546 "-bind-name=role-updated",547 "-selector=serviceaccount.namespace==alt and serviceaccount.name==demo",548 }549 code := cmd.Run(args)550 require.Equal(t, code, 0, "err: %s", ui.ErrorWriter.String())551 require.Empty(t, ui.ErrorWriter.String())552 rule, _, err := client.ACL().BindingRuleRead(553 id,554 &api.QueryOptions{Token: "root"},555 )556 require.NoError(t, err)557 require.NotNil(t, rule)558 require.Equal(t, "test rule edited", rule.Description)559 require.Equal(t, api.BindingRuleBindTypeService, rule.BindType)560 require.Equal(t, "role-updated", rule.BindName)561 require.Equal(t, "serviceaccount.namespace==alt and serviceaccount.name==demo", rule.Selector)562 })563 t.Run("update all fields - partial", func(t *testing.T) {564 deleteRules(t) // reset since we created a bunch that might be dupes565 id := createRule(t)566 ui := cli.NewMockUi()567 cmd := New(ui)568 args := []string{569 "-http-addr=" + a.HTTPAddr(),570 "-token=root",571 "-no-merge",572 "-id", id[0:5],573 "-description=test rule edited",574 "-bind-type", "service",575 "-bind-name=role-updated",576 "-selector=serviceaccount.namespace==alt and serviceaccount.name==demo",577 }578 code := cmd.Run(args)579 require.Equal(t, code, 0, "err: %s", ui.ErrorWriter.String())580 require.Empty(t, ui.ErrorWriter.String())581 rule, _, err := client.ACL().BindingRuleRead(582 id,583 &api.QueryOptions{Token: "root"},584 )585 require.NoError(t, err)586 require.NotNil(t, rule)587 require.Equal(t, "test rule edited", rule.Description)588 require.Equal(t, api.BindingRuleBindTypeService, rule.BindType)589 require.Equal(t, "role-updated", rule.BindName)590 require.Equal(t, "serviceaccount.namespace==alt and serviceaccount.name==demo", rule.Selector)591 })592 t.Run("update all fields but description", func(t *testing.T) {593 id := createRule(t)594 ui := cli.NewMockUi()595 cmd := New(ui)596 args := []string{597 "-http-addr=" + a.HTTPAddr(),598 "-token=root",599 "-no-merge",600 "-id", id,601 "-bind-type", "service",602 "-bind-name=role-updated",603 "-selector=serviceaccount.namespace==alt and serviceaccount.name==demo",604 }605 code := cmd.Run(args)606 require.Equal(t, code, 0, "err: %s", ui.ErrorWriter.String())607 require.Empty(t, ui.ErrorWriter.String())608 rule, _, err := client.ACL().BindingRuleRead(609 id,610 &api.QueryOptions{Token: "root"},611 )612 require.NoError(t, err)613 require.NotNil(t, rule)614 require.Empty(t, rule.Description)615 require.Equal(t, api.BindingRuleBindTypeService, rule.BindType)616 require.Equal(t, "role-updated", rule.BindName)617 require.Equal(t, "serviceaccount.namespace==alt and serviceaccount.name==demo", rule.Selector)618 })619 t.Run("missing bind name", func(t *testing.T) {620 id := createRule(t)621 ui := cli.NewMockUi()622 cmd := New(ui)623 args := []string{624 "-http-addr=" + a.HTTPAddr(),625 "-token=root",626 "-no-merge",627 "-id=" + id,628 "-description=test rule edited",629 "-bind-type", "role",630 "-selector=serviceaccount.namespace==alt and serviceaccount.name==demo",631 }632 code := cmd.Run(args)633 require.Equal(t, code, 1)634 require.Contains(t, ui.ErrorWriter.String(), "Missing required '-bind-name' flag")635 })636 t.Run("update all fields but selector", func(t *testing.T) {637 id := createRule(t)638 ui := cli.NewMockUi()639 cmd := New(ui)640 args := []string{641 "-http-addr=" + a.HTTPAddr(),642 "-token=root",643 "-no-merge",644 "-id", id,645 "-description=test rule edited",646 "-bind-type", "service",647 "-bind-name=role-updated",648 }649 code := cmd.Run(args)650 require.Equal(t, code, 0, "err: %s", ui.ErrorWriter.String())651 require.Empty(t, ui.ErrorWriter.String())652 rule, _, err := client.ACL().BindingRuleRead(653 id,654 &api.QueryOptions{Token: "root"},655 )656 require.NoError(t, err)657 require.NotNil(t, rule)658 require.Equal(t, "test rule edited", rule.Description)659 require.Equal(t, api.BindingRuleBindTypeService, rule.BindType)660 require.Equal(t, "role-updated", rule.BindName)661 require.Empty(t, rule.Selector)662 })663}...
authmethod_create_test.go
Source:authmethod_create_test.go
...21 _ "github.com/hashicorp/consul/agent/consul/authmethod/testauth"22)23func TestAuthMethodCreateCommand_noTabs(t *testing.T) {24 t.Parallel()25 if strings.ContainsRune(New(cli.NewMockUi()).Help(), '\t') {26 t.Fatal("help has tabs")27 }28}29func TestAuthMethodCreateCommand(t *testing.T) {30 t.Parallel()31 testDir := testutil.TempDir(t, "acl")32 defer os.RemoveAll(testDir)33 a := agent.NewTestAgent(t, `34 primary_datacenter = "dc1"35 acl {36 enabled = true37 tokens {38 master = "root"39 }40 }`)41 defer a.Shutdown()42 testrpc.WaitForLeader(t, a.RPC, "dc1")43 client := a.Client()44 t.Run("type required", func(t *testing.T) {45 args := []string{46 "-http-addr=" + a.HTTPAddr(),47 "-token=root",48 }49 ui := cli.NewMockUi()50 cmd := New(ui)51 code := cmd.Run(args)52 require.Equal(t, code, 1)53 require.Contains(t, ui.ErrorWriter.String(), "Missing required '-type' flag")54 })55 t.Run("name required", func(t *testing.T) {56 args := []string{57 "-http-addr=" + a.HTTPAddr(),58 "-token=root",59 "-type=testing",60 }61 ui := cli.NewMockUi()62 cmd := New(ui)63 code := cmd.Run(args)64 require.Equal(t, code, 1)65 require.Contains(t, ui.ErrorWriter.String(), "Missing required '-name' flag")66 })67 t.Run("invalid type", func(t *testing.T) {68 args := []string{69 "-http-addr=" + a.HTTPAddr(),70 "-token=root",71 "-type=invalid",72 "-name=my-method",73 }74 ui := cli.NewMockUi()75 cmd := New(ui)76 code := cmd.Run(args)77 require.Equal(t, code, 1)78 require.Contains(t, ui.ErrorWriter.String(), "Invalid Auth Method: Type should be one of")79 })80 t.Run("create testing", func(t *testing.T) {81 name := getTestName(t)82 args := []string{83 "-http-addr=" + a.HTTPAddr(),84 "-token=root",85 "-type=testing",86 "-name", name,87 "-description=desc",88 "-display-name=display",89 }90 ui := cli.NewMockUi()91 cmd := New(ui)92 code := cmd.Run(args)93 require.Equal(t, code, 0)94 require.Empty(t, ui.ErrorWriter.String())95 got := getTestMethod(t, client, name)96 expect := &api.ACLAuthMethod{97 Name: name,98 Type: "testing",99 DisplayName: "display",100 Description: "desc",101 }102 require.Equal(t, expect, got)103 })104 t.Run("create testing with max token ttl", func(t *testing.T) {105 name := getTestName(t)106 args := []string{107 "-http-addr=" + a.HTTPAddr(),108 "-token=root",109 "-type=testing",110 "-name", name,111 "-description=desc",112 "-display-name=display",113 "-max-token-ttl=5m",114 }115 ui := cli.NewMockUi()116 cmd := New(ui)117 code := cmd.Run(args)118 require.Equal(t, code, 0, "err: "+ui.ErrorWriter.String())119 require.Empty(t, ui.ErrorWriter.String())120 got := getTestMethod(t, client, name)121 expect := &api.ACLAuthMethod{122 Name: name,123 Type: "testing",124 DisplayName: "display",125 Description: "desc",126 MaxTokenTTL: 5 * time.Minute,127 }128 require.Equal(t, expect, got)129 })130}131func TestAuthMethodCreateCommand_JSON(t *testing.T) {132 t.Parallel()133 testDir := testutil.TempDir(t, "acl")134 defer os.RemoveAll(testDir)135 a := agent.NewTestAgent(t, `136 primary_datacenter = "dc1"137 acl {138 enabled = true139 tokens {140 master = "root"141 }142 }`)143 defer a.Shutdown()144 testrpc.WaitForLeader(t, a.RPC, "dc1")145 client := a.Client()146 t.Run("type required", func(t *testing.T) {147 args := []string{148 "-http-addr=" + a.HTTPAddr(),149 "-token=root",150 "-format=json",151 }152 ui := cli.NewMockUi()153 cmd := New(ui)154 code := cmd.Run(args)155 require.Equal(t, code, 1)156 require.Contains(t, ui.ErrorWriter.String(), "Missing required '-type' flag")157 })158 t.Run("create testing", func(t *testing.T) {159 name := getTestName(t)160 args := []string{161 "-http-addr=" + a.HTTPAddr(),162 "-token=root",163 "-type=testing",164 "-name", name,165 "-description=desc",166 "-display-name=display",167 "-format=json",168 }169 ui := cli.NewMockUi()170 cmd := New(ui)171 code := cmd.Run(args)172 out := ui.OutputWriter.String()173 require.Equal(t, code, 0)174 require.Empty(t, ui.ErrorWriter.String())175 require.Contains(t, out, name)176 var jsonOutput json.RawMessage177 require.NoError(t, json.Unmarshal([]byte(out), &jsonOutput))178 got := getTestMethod(t, client, name)179 expect := &api.ACLAuthMethod{180 Name: name,181 Type: "testing",182 DisplayName: "display",183 Description: "desc",184 }185 require.Equal(t, expect, got)186 })187 t.Run("create testing with max token ttl", func(t *testing.T) {188 name := getTestName(t)189 args := []string{190 "-http-addr=" + a.HTTPAddr(),191 "-token=root",192 "-type=testing",193 "-name", name,194 "-description=desc",195 "-display-name=display",196 "-max-token-ttl=5m",197 "-format=json",198 }199 ui := cli.NewMockUi()200 cmd := New(ui)201 code := cmd.Run(args)202 out := ui.OutputWriter.String()203 require.Equal(t, code, 0)204 require.Empty(t, ui.ErrorWriter.String())205 require.Contains(t, out, name)206 got := getTestMethod(t, client, name)207 expect := &api.ACLAuthMethod{208 Name: name,209 Type: "testing",210 DisplayName: "display",211 Description: "desc",212 MaxTokenTTL: 5 * time.Minute,213 }214 require.Equal(t, expect, got)215 var raw map[string]interface{}216 require.NoError(t, json.Unmarshal([]byte(out), &raw))217 delete(raw, "CreateIndex")218 delete(raw, "ModifyIndex")219 delete(raw, "Namespace")220 require.Equal(t, map[string]interface{}{221 "Name": name,222 "Type": "testing",223 "DisplayName": "display",224 "Description": "desc",225 "MaxTokenTTL": "5m0s",226 "Config": nil,227 }, raw)228 })229}230func TestAuthMethodCreateCommand_k8s(t *testing.T) {231 t.Parallel()232 testDir := testutil.TempDir(t, "acl")233 defer os.RemoveAll(testDir)234 a := agent.NewTestAgent(t, `235 primary_datacenter = "dc1"236 acl {237 enabled = true238 tokens {239 master = "root"240 }241 }`)242 defer a.Shutdown()243 testrpc.WaitForLeader(t, a.RPC, "dc1")244 client := a.Client()245 t.Run("k8s host required", func(t *testing.T) {246 name := getTestName(t)247 args := []string{248 "-http-addr=" + a.HTTPAddr(),249 "-token=root",250 "-type=kubernetes",251 "-name", name,252 }253 ui := cli.NewMockUi()254 cmd := New(ui)255 code := cmd.Run(args)256 require.Equal(t, code, 1)257 require.Contains(t, ui.ErrorWriter.String(), "Missing required '-kubernetes-host' flag")258 })259 t.Run("k8s ca cert required", func(t *testing.T) {260 name := getTestName(t)261 args := []string{262 "-http-addr=" + a.HTTPAddr(),263 "-token=root",264 "-type=kubernetes",265 "-name", name,266 "-kubernetes-host=https://foo.internal:8443",267 }268 ui := cli.NewMockUi()269 cmd := New(ui)270 code := cmd.Run(args)271 require.Equal(t, code, 1)272 require.Contains(t, ui.ErrorWriter.String(), "Missing required '-kubernetes-ca-cert' flag")273 })274 ca := connect.TestCA(t, nil)275 t.Run("k8s jwt required", func(t *testing.T) {276 name := getTestName(t)277 args := []string{278 "-http-addr=" + a.HTTPAddr(),279 "-token=root",280 "-type=kubernetes",281 "-name", name,282 "-kubernetes-host=https://foo.internal:8443",283 "-kubernetes-ca-cert", ca.RootCert,284 }285 ui := cli.NewMockUi()286 cmd := New(ui)287 code := cmd.Run(args)288 require.Equal(t, code, 1)289 require.Contains(t, ui.ErrorWriter.String(), "Missing required '-kubernetes-service-account-jwt' flag")290 })291 t.Run("create k8s", func(t *testing.T) {292 name := getTestName(t)293 args := []string{294 "-http-addr=" + a.HTTPAddr(),295 "-token=root",296 "-type=kubernetes",297 "-name", name,298 "-kubernetes-host", "https://foo.internal:8443",299 "-kubernetes-ca-cert", ca.RootCert,300 "-kubernetes-service-account-jwt", acl.TestKubernetesJWT_A,301 }302 ui := cli.NewMockUi()303 cmd := New(ui)304 code := cmd.Run(args)305 require.Equal(t, 0, code)306 require.Empty(t, ui.ErrorWriter.String())307 got := getTestMethod(t, client, name)308 expect := &api.ACLAuthMethod{309 Name: name,310 Type: "kubernetes",311 Config: map[string]interface{}{312 "Host": "https://foo.internal:8443",313 "CACert": ca.RootCert,314 "ServiceAccountJWT": acl.TestKubernetesJWT_A,315 },316 }317 require.Equal(t, expect, got)318 })319 caFile := filepath.Join(testDir, "ca.crt")320 require.NoError(t, ioutil.WriteFile(caFile, []byte(ca.RootCert), 0600))321 t.Run("create k8s with cert file", func(t *testing.T) {322 name := getTestName(t)323 args := []string{324 "-http-addr=" + a.HTTPAddr(),325 "-token=root",326 "-type=kubernetes",327 "-name", name,328 "-kubernetes-host", "https://foo.internal:8443",329 "-kubernetes-ca-cert", "@" + caFile,330 "-kubernetes-service-account-jwt", acl.TestKubernetesJWT_A,331 }332 ui := cli.NewMockUi()333 cmd := New(ui)334 code := cmd.Run(args)335 require.Equal(t, code, 0)336 require.Empty(t, ui.ErrorWriter.String())337 got := getTestMethod(t, client, name)338 expect := &api.ACLAuthMethod{339 Name: name,340 Type: "kubernetes",341 Config: map[string]interface{}{342 "Host": "https://foo.internal:8443",343 "CACert": ca.RootCert,344 "ServiceAccountJWT": acl.TestKubernetesJWT_A,345 },346 }347 require.Equal(t, expect, got)348 })349}350func TestAuthMethodCreateCommand_config(t *testing.T) {351 t.Parallel()352 testDir := testutil.TempDir(t, "auth-method")353 defer os.RemoveAll(testDir)354 a := agent.NewTestAgent(t, `355 primary_datacenter = "dc1"356 acl {357 enabled = true358 tokens {359 master = "root"360 }361 }`)362 defer a.Shutdown()363 testrpc.WaitForLeader(t, a.RPC, "dc1")364 client := a.Client()365 checkMethod := func(t *testing.T, methodName string) {366 method, _, err := client.ACL().AuthMethodRead(367 methodName,368 &api.QueryOptions{Token: "root"},369 )370 require.NoError(t, err)371 require.NotNil(t, method)372 require.Equal(t, "foo", method.Config["SessionID"])373 }374 t.Run("config file", func(t *testing.T) {375 name := getTestName(t)376 configFile := filepath.Join(testDir, "config.json")377 jsonConfig := `{"SessionID":"foo"}`378 require.NoError(t, ioutil.WriteFile(configFile, []byte(jsonConfig), 0644))379 args := []string{380 "-http-addr=" + a.HTTPAddr(),381 "-token=root",382 "-type=testing",383 "-name", name,384 "-config=@" + configFile,385 }386 ui := cli.NewMockUi()387 cmd := New(ui)388 code := cmd.Run(args)389 require.Equal(t, 0, code)390 require.Empty(t, ui.ErrorWriter.String())391 checkMethod(t, name)392 })393 t.Run("config std-in", func(t *testing.T) {394 name := getTestName(t)395 stdinR, stdinW := io.Pipe()396 ui := cli.NewMockUi()397 cmd := New(ui)398 cmd.testStdin = stdinR399 go func() {400 stdinW.Write([]byte(`{"SessionID":"foo"}`))401 stdinW.Close()402 }()403 args := []string{404 "-http-addr=" + a.HTTPAddr(),405 "-token=root",406 "-type=testing",407 "-name", name,408 "-config=-",409 }410 code := cmd.Run(args)411 require.Equal(t, 0, code)412 require.Empty(t, ui.ErrorWriter.String())413 checkMethod(t, name)414 })415 t.Run("config string", func(t *testing.T) {416 name := getTestName(t)417 ui := cli.NewMockUi()418 cmd := New(ui)419 args := []string{420 "-http-addr=" + a.HTTPAddr(),421 "-token=root",422 "-type=testing",423 "-name", name,424 "-config=" + `{"SessionID":"foo"}`,425 }426 code := cmd.Run(args)427 require.Equal(t, 0, code)428 require.Empty(t, ui.ErrorWriter.String())429 checkMethod(t, name)430 })431}432func getTestMethod(t *testing.T, client *api.Client, methodName string) *api.ACLAuthMethod {433 t.Helper()434 method, _, err := client.ACL().AuthMethodRead(435 methodName,436 &api.QueryOptions{Token: "root"},437 )438 require.NoError(t, err)439 require.NotNil(t, method)440 // zero these out since we don't really care...
catalog_list_nodes_test.go
Source:catalog_list_nodes_test.go
...7 "github.com/mitchellh/cli"8)9func TestCatalogListNodesCommand_noTabs(t *testing.T) {10 t.Parallel()11 if strings.ContainsRune(New(nil).Help(), '\t') {12 t.Fatal("help has tabs")13 }14}15func TestCatalogListNodesCommand_Validation(t *testing.T) {16 t.Parallel()17 ui := cli.NewMockUi()18 c := New(ui)19 code := c.Run([]string{"foo"})20 if code == 0 {21 t.Fatal("expected non-zero exit")22 }23 if got, want := ui.ErrorWriter.String(), "Too many arguments"; !strings.Contains(got, want) {24 t.Fatalf("expected %q to contain %q", got, want)25 }26}27func TestCatalogListNodesCommand(t *testing.T) {28 t.Parallel()29 a := agent.NewTestAgent(t, ``)30 defer a.Shutdown()31 testrpc.WaitForTestAgent(t, a.RPC, "dc1")32 t.Run("simple", func(t *testing.T) {33 ui := cli.NewMockUi()34 c := New(ui)35 args := []string{36 "-http-addr=" + a.HTTPAddr(),37 }38 code := c.Run(args)39 if code != 0 {40 t.Fatalf("bad exit code %d: %s", code, ui.ErrorWriter.String())41 }42 output := ui.OutputWriter.String()43 for _, s := range []string{"Node", "ID", "Address", "DC"} {44 if !strings.Contains(output, s) {45 t.Errorf("expected %q to contain %q", output, s)46 }47 }48 for _, s := range []string{"TaggedAddresses", "Meta"} {49 if strings.Contains(output, s) {50 t.Errorf("expected %q to NOT contain %q", output, s)51 }52 }53 })54 t.Run("detailed", func(t *testing.T) {55 ui := cli.NewMockUi()56 c := New(ui)57 args := []string{58 "-http-addr=" + a.HTTPAddr(),59 "-detailed",60 }61 code := c.Run(args)62 if code != 0 {63 t.Fatalf("bad exit code %d: %s", code, ui.ErrorWriter.String())64 }65 output := ui.OutputWriter.String()66 for _, s := range []string{"Node", "ID", "Address", "DC", "TaggedAddresses", "Meta"} {67 if !strings.Contains(output, s) {68 t.Errorf("expected %q to contain %q", output, s)69 }70 }71 })72 t.Run("node-meta", func(t *testing.T) {73 ui := cli.NewMockUi()74 c := New(ui)75 args := []string{76 "-http-addr=" + a.HTTPAddr(),77 "-node-meta", "foo=bar",78 }79 code := c.Run(args)80 if code != 0 {81 t.Fatalf("bad exit code %d: %s", code, ui.ErrorWriter.String())82 }83 output := ui.ErrorWriter.String()84 if expected := "No nodes match the given query"; !strings.Contains(output, expected) {85 t.Errorf("expected %q to contain %q", output, expected)86 }87 })88 t.Run("filter", func(t *testing.T) {89 ui := cli.NewMockUi()90 c := New(ui)91 args := []string{92 "-http-addr=" + a.HTTPAddr(),93 "-filter", "Meta.foo == bar",94 }95 code := c.Run(args)96 if code != 0 {97 t.Fatalf("bad exit code %d: %s", code, ui.ErrorWriter.String())98 }99 output := ui.ErrorWriter.String()100 if expected := "No nodes match the given query"; !strings.Contains(output, expected) {101 t.Errorf("expected %q to contain %q", output, expected)102 }103 })104 t.Run("near", func(t *testing.T) {105 ui := cli.NewMockUi()106 c := New(ui)107 args := []string{108 "-http-addr=" + a.HTTPAddr(),109 "-near", "_agent",110 }111 code := c.Run(args)112 if code != 0 {113 t.Fatalf("bad exit code %d: %s", code, ui.ErrorWriter.String())114 }115 output := ui.OutputWriter.String()116 if expected := "127.0.0.1"; !strings.Contains(output, expected) {117 t.Errorf("expected %q to contain %q", output, expected)118 }119 })120 t.Run("service_present", func(t *testing.T) {121 ui := cli.NewMockUi()122 c := New(ui)123 args := []string{124 "-http-addr=" + a.HTTPAddr(),125 "-service", "consul",126 }127 code := c.Run(args)128 if code != 0 {129 t.Fatalf("bad exit code %d: %s", code, ui.ErrorWriter.String())130 }131 output := ui.OutputWriter.String()132 if expected := "127.0.0.1"; !strings.Contains(output, expected) {133 t.Errorf("expected %q to contain %q", output, expected)134 }135 })136 t.Run("service_missing", func(t *testing.T) {137 ui := cli.NewMockUi()138 c := New(ui)139 args := []string{140 "-http-addr=" + a.HTTPAddr(),141 "-service", "this-service-will-literally-never-exist",142 }143 code := c.Run(args)144 if code != 0 {145 t.Fatalf("bad exit code %d: %s", code, ui.ErrorWriter.String())146 }147 output := ui.ErrorWriter.String()148 if expected := "No nodes match the given query"; !strings.Contains(output, expected) {149 t.Errorf("expected %q to contain %q", output, expected)150 }151 })152}153func TestCatalogListNodesCommand_verticalBar(t *testing.T) {154 t.Parallel()155 nodeName := "name|with|bars"156 a := agent.NewTestAgent(t, `node_name = "`+nodeName+`"`)157 defer a.Shutdown()158 testrpc.WaitForTestAgent(t, a.RPC, "dc1")159 ui := cli.NewMockUi()160 c := New(ui)161 c.flags.SetOutput(ui.ErrorWriter)162 args := []string{163 "-http-addr=" + a.HTTPAddr(),164 }165 code := c.Run(args)166 if code != 0 {167 t.Fatalf("bad exit code: %d. %q", code, ui.ErrorWriter.String())168 }169 // Check for nodeName presense because it should not be parsed by columnize170 if !strings.Contains(ui.OutputWriter.String(), nodeName) {171 t.Fatalf("expected %q to contain %q", ui.OutputWriter.String(), nodeName)172 }173}...
Run
Using AI Code Generation
1import (2func main() {3 err := ui.Main(func() {4 name := ui.NewEntry()5 button := ui.NewButton("Greet")6 greeting := ui.NewLabel("")7 box := ui.NewVerticalBox()8 box.Append(ui.NewLabel("Enter your name:"), false)9 box.Append(name, false)10 box.Append(button, false)11 box.Append(greeting, false)12 window := ui.NewWindow("Hello", 200, 100, false)13 window.SetMargined(true)14 window.SetChild(box)15 window.OnClosing(func(*ui.Window) bool {16 ui.Quit()17 })18 button.OnClicked(func(*ui.Button) {19 greeting.SetText("Hello, " + name.Text() + "!")20 })21 window.Show()22 })23 if err != nil {24 panic(err)25 }26}27import (28func main() {29 err := ui.Main(func() {30 name := ui.NewEntry()31 button := ui.NewButton("Greet")32 greeting := ui.NewLabel("")33 box := ui.NewVerticalBox()34 box.Append(ui.NewLabel("Enter your name:"), false)35 box.Append(name, false)36 box.Append(button, false)37 box.Append(greeting, false)38 window := ui.NewWindow("Hello", 200, 100, false)39 window.SetMargined(true)40 window.SetChild(box)41 window.OnClosing(func(*ui.Window) bool {42 ui.Quit()43 })44 button.OnClicked(func(*ui.Button) {45 greeting.SetText("Hello, " + name.Text() + "!")46 })47 window.Show()48 })49 if err != nil {50 panic(err)51 }52}53import (54func main() {55 err := ui.Main(func() {56 name := ui.NewEntry()57 button := ui.NewButton("Greet")
Run
Using AI Code Generation
1import (2func main() {3 err := ui.Main(func() {4 name := ui.NewEntry()5 button := ui.NewButton("Greet")6 greeting := ui.NewLabel("")7 box := ui.NewVerticalBox()8 box.Append(ui.NewLabel("Enter your name:"), false)9 box.Append(name, false)10 box.Append(button, false)11 box.Append(greeting, false)12 window := ui.NewWindow("Hello", 200, 100, false)13 window.SetMargined(true)14 window.SetChild(box)15 button.OnClicked(func(*ui.Button) {16 greeting.SetText("Hello, " + name.Text() + "!")17 })18 window.OnClosing(func(*ui.Window) bool {19 ui.Quit()20 })21 window.Show()22 })23 if err != nil {24 panic(err)25 }26}27import (28func main() {29 err := ui.Main(func() {30 name := ui.NewEntry()31 button := ui.NewButton("Greet")32 greeting := ui.NewLabel("")33 box := ui.NewVerticalBox()34 box.Append(ui.NewLabel("Enter your name:"), false)35 box.Append(name, false)36 box.Append(button, false)37 box.Append(greeting, false)38 window := ui.NewWindow("Hello", 200, 100, false)39 window.SetMargined(true)40 window.SetChild(box)41 button.OnClicked(func(*ui.Button) {42 greeting.SetText("Hello, " + name.Text() + "!")43 })44 window.OnClosing(func(*ui.Window) bool {45 ui.Quit()46 })47 window.Show()48 })49 if err != nil {50 panic(err)51 }52}53import (54func main() {55 err := ui.Main(func() {56 name := ui.NewEntry()57 button := ui.NewButton("Greet")58 greeting := ui.NewLabel("")59 box := ui.NewVerticalBox()60 box.Append(ui.NewLabel("Enter your name:"), false)61 box.Append(name, false)
Run
Using AI Code Generation
1import (2func main() {3 err := ui.Main(func() {4 name := ui.NewEntry()5 button := ui.NewButton("Hello")6 greeting := ui.NewLabel("")7 box := ui.NewVerticalBox()8 box.Append(ui.NewLabel("Enter your name:"), false)9 box.Append(name, false)10 box.Append(button, false)11 box.Append(greeting, false)12 window := ui.NewWindow("Hello", 200, 100, false)13 window.SetMargined(true)14 window.SetChild(box)15 button.OnClicked(func(*ui.Button) {16 greeting.SetText("Hello, " + name.Text() + "!")17 })18 window.OnClosing(func(*ui.Window) bool {19 ui.Quit()20 })21 window.Show()22 })23 if err != nil {24 panic(err)25 }26}27import (28func main() {29 err := ui.Main(func() {30 name := ui.NewEntry()31 button := ui.NewButton("Hello")32 greeting := ui.NewLabel("")33 box := ui.NewVerticalBox()34 box.Append(ui.NewLabel("Enter your name:"), false)35 box.Append(name, false)36 box.Append(button, false)37 box.Append(greeting, false)38 window := ui.NewWindow("Hello", 200, 100, false)39 window.SetMargined(true)40 window.SetChild(box)41 button.OnClicked(func(*ui.Button) {42 greeting.SetText("Hello, " + name.Text() + "!")43 })44 window.OnClosing(func(*ui.Window) bool {45 ui.Quit()46 })47 window.Show()48 })49 if err != nil {50 panic(err)51 }52}53import (54func main() {55 err := ui.Main(func() {56 name := ui.NewEntry()57 button := ui.NewButton("Hello")58 greeting := ui.NewLabel("")59 box := ui.NewVerticalBox()60 box.Append(ui.NewLabel("Enter your name:"), false)61 box.Append(name, false)62 box.Append(button
Run
Using AI Code Generation
1import (2func main() {3 err := ui.Main(func() {4 name := ui.NewEntry()5 button := ui.NewButton("Greet")6 greeting := ui.NewLabel("")7 box := ui.NewVerticalBox()8 box.Append(ui.NewLabel("Enter your name:"), false)9 box.Append(name, false)10 box.Append(button, false)11 box.Append(greeting, false)12 window := ui.NewWindow("Hello", 200, 100, false)13 window.SetChild(box)14 button.OnClicked(func(*ui.Button) {15 greeting.SetText("Hello, " + name.Text() + "!")16 })17 window.OnClosing(func(*ui.Window) bool {18 ui.Quit()19 })20 window.Show()21 })22 if err != nil {23 panic(err)24 }25}26import (27func main() {28 err := ui.Main(func() {29 name := ui.NewEntry()30 button := ui.NewButton("Greet")31 greeting := ui.NewLabel("")32 box := ui.NewVerticalBox()33 box.Append(ui.NewLabel("Enter your name:"), false)34 box.Append(name, false)35 box.Append(button, false)36 box.Append(greeting, false)37 window := ui.NewWindow("Hello", 200, 100, false)38 window.SetChild(box)39 button.OnClicked(func(*ui.Button) {40 greeting.SetText("Hello, " + name.Text() + "!")41 })42 window.OnClosing(func(*ui.Window) bool {43 ui.Quit()44 })45 window.Show()46 })47 if err != nil {48 panic(err)49 }50}51import (52func main() {53 err := ui.Main(func() {54 name := ui.NewEntry()55 button := ui.NewButton("Greet")56 greeting := ui.NewLabel("")57 box := ui.NewVerticalBox()58 box.Append(ui.NewLabel("Enter your name:"), false)59 box.Append(name, false)60 box.Append(button, false
Run
Using AI Code Generation
1import (2func main() {3 err := ui.Go(ui.Run)4 if err != nil {5 fmt.Println(err)6 }7}8import (9func main() {10 err := ui.Go(func() error {11 window := ui.NewWindow("Hello", 200, 200, false)12 window.Show()13 ui.Main()14 })15 if err != nil {16 fmt.Println(err)17 }18}
Run
Using AI Code Generation
1import (2func main() {3 ui := ui.New()4 ui.Run()5}6import (7type Ui struct {8}9func New() *Ui {10 return &Ui{}11}12func (ui *Ui) Run() {13 fmt.Println("Hello World!")14}15import (16func TestRun(t *testing.T) {17 ui := New()18 ui.Run()19}
Run
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello, playground")4 ui.Run()5}6import (7func main() {8 fmt.Println("Hello, playground")9 ui.Run()10}11import (12func main() {13 fmt.Println("Hello, playground")14 ui.Run()15}16import (17func main() {18 fmt.Println("Hello, playground")19 ui.Run()20}21import (22func main() {23 fmt.Println("Hello, playground")24 ui.Run()25}26import (27func main() {28 fmt.Println("Hello, playground")29 ui.Run()30}31import (32func main() {33 fmt.Println("Hello, playground")34 ui.Run()35}36import (37func main() {38 fmt.Println("Hello, playground")39 ui.Run()40}41import (42func main() {43 fmt.Println("Hello, playground")44 ui.Run()45}46import (47func main() {48 fmt.Println("Hello, playground")49 ui.Run()50}51import (52func main() {
Run
Using AI Code Generation
1import "fmt"2type ui struct {3}4func (ui) Run() {5fmt.Println("Running")6}7func main() {8u.Run()9}10import "fmt"11type ui struct {12}13func (ui) Run() {14fmt.Println("Running")15}16func main() {17u.Run()18}19import "fmt"20type ui struct {21}22func (ui) Run() {23fmt.Println("Running")24}25func main() {26u.Run()27}28import "fmt"29type ui struct {30}31func (ui) Run() {32fmt.Println("Running")33}34func main() {35u.Run()36}37import "fmt"38type ui struct {39}40func (ui) Run() {41fmt.Println("Running")42}43func main() {44u.Run()45}46import "fmt"47type ui struct {48}49func (ui) Run() {50fmt.Println("Running")51}52func main() {53u.Run()54}55import "fmt"56type ui struct {57}58func (ui) Run() {59fmt.Println("Running")60}61func main() {62u.Run()63}64import "fmt"65type ui struct {66}67func (ui)
Run
Using AI Code Generation
1import (2func main() {3 ui.Main(func() {4 ui.Run(func() {5 })6 })7}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!