Best Rod code snippet using launcher.NewManager
start_test.go
Source:start_test.go
...174 "The config should have been created at '%s'",175 path,176 )177 defaultConf := config.Default()178 mgr := config.NewManager(fs)179 conf, err := mgr.Read(path)180 require.NoError(st, err)181 require.Exactly(st, defaultConf, conf)182 },183 }, {184 name: "it should write the given config file path",185 args: []string{186 "--config", "/arbitrary/path/redpanda.yaml",187 "--install-dir", "/var/lib/redpanda",188 },189 before: func(fs afero.Fs) error {190 return fs.MkdirAll("/arbitrary/path", 0755)191 },192 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {193 path := "/arbitrary/path/redpanda.yaml"194 mgr := config.NewManager(fs)195 conf, err := mgr.Read(path)196 require.NoError(st, err)197 require.Exactly(st, path, conf.ConfigFile)198 },199 }, {200 name: "it should allow passing arbitrary config values and write them to the config file",201 args: []string{202 "--config", "/arbitrary/path/redpanda.yaml",203 "--install-dir", "/var/lib/redpanda",204 },205 before: func(fs afero.Fs) error {206 // --set flags are parsed "outside" of Cobra, directly from207 // os.Args, due to Cobra (or especifically, pflag) parsing208 // list flags (flags that can be passed multiple times) with209 // a CSV parser. Since JSON-formatted values contain commas,210 // the parser doesn't support them.211 os.Args = append(212 os.Args,213 // A single int value214 "--set", "redpanda.node_id=39",215 // A single bool value216 "--set", "rpk.enable_usage_stats=true",217 // A single string value218 "--set", "node_uuid=helloimauuid1337",219 // A JSON object220 "--set", `redpanda.admin=[{"address": "192.168.54.2","port": 9643}]`,221 // A YAML object222 "--set", `redpanda.kafka_api=- name: external223 address: 192.168.73.45224 port: 9092225- name: internal226 address: 10.21.34.58227 port: 9092228`,229 )230 return fs.MkdirAll("/arbitrary/path", 0755)231 },232 after: func() {233 for i, a := range os.Args {234 if a == "--set" {235 os.Args = os.Args[:i]236 return237 }238 }239 },240 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {241 path := "/arbitrary/path/redpanda.yaml"242 mgr := config.NewManager(fs)243 conf, err := mgr.Read(path)244 require.NoError(st, err)245 expectedAdmin := []config.NamedSocketAddress{{246 SocketAddress: config.SocketAddress{247 Address: "192.168.54.2",248 Port: 9643,249 },250 }}251 expectedKafkaApi := []config.NamedSocketAddress{{252 Name: "external",253 SocketAddress: config.SocketAddress{254 Address: "192.168.73.45",255 Port: 9092,256 },257 }, {258 Name: "internal",259 SocketAddress: config.SocketAddress{260 Address: "10.21.34.58",261 Port: 9092,262 },263 }}264 require.Exactly(st, 39, conf.Redpanda.Id)265 require.Exactly(st, expectedAdmin, conf.Redpanda.AdminApi)266 require.Exactly(st, expectedKafkaApi, conf.Redpanda.KafkaApi)267 },268 }, {269 name: "it should still save values passed through field-specific flags, and prioritize them if they overlap with values set with --set",270 args: []string{271 "--config", "/arbitrary/path/redpanda.yaml",272 "--install-dir", "/var/lib/redpanda",273 // Field-specific flags274 "--advertise-kafka-addr", "plaintext://192.168.34.32:9092",275 "--node-id", "42",276 },277 before: func(fs afero.Fs) error {278 // --set flags are parsed "outside" of Cobra, directly from279 // os.Args, due to Cobra (or especifically, pflag) parsing280 // list flags (flags that can be passed multiple times) with281 // a CSV parser. Since JSON-formatted values contain commas,282 // the parser doesn't support them.283 os.Args = append(284 os.Args,285 // A single int value286 "--set", "redpanda.node_id=39",287 // A single bool value288 "--set", "rpk.enable_usage_stats=true",289 // A single string value290 "--set", "node_uuid=helloimauuid1337",291 // A JSON object292 "--set", `redpanda.admin=[{"address": "192.168.54.2","port": 9643}]`,293 // A YAML object294 "--set", `redpanda.kafka_api=- name: external295 address: 192.168.73.45296 port: 9092297- name: internal298 address: 10.21.34.58299 port: 9092300`,301 )302 return fs.MkdirAll("/arbitrary/path", 0755)303 },304 after: func() {305 for i, a := range os.Args {306 if a == "--set" {307 os.Args = os.Args[:i]308 return309 }310 }311 },312 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {313 path := "/arbitrary/path/redpanda.yaml"314 mgr := config.NewManager(fs)315 conf, err := mgr.Read(path)316 require.NoError(st, err)317 expectedAdmin := []config.NamedSocketAddress{{318 SocketAddress: config.SocketAddress{319 Address: "192.168.54.2",320 Port: 9643,321 },322 }}323 expectedKafkaApi := []config.NamedSocketAddress{{324 Name: "external",325 SocketAddress: config.SocketAddress{326 Address: "192.168.73.45",327 Port: 9092,328 },329 }, {330 Name: "internal",331 SocketAddress: config.SocketAddress{332 Address: "10.21.34.58",333 Port: 9092,334 },335 }}336 expectedAdvKafkaApi := []config.NamedSocketAddress{{337 Name: "plaintext",338 SocketAddress: config.SocketAddress{339 Address: "192.168.34.32",340 Port: 9092,341 },342 }}343 // The value set with --node-id should have been prioritized344 require.Exactly(st, 42, conf.Redpanda.Id)345 require.Exactly(st, expectedAdmin, conf.Redpanda.AdminApi)346 require.Exactly(st, expectedKafkaApi, conf.Redpanda.KafkaApi)347 require.Exactly(st, expectedAdvKafkaApi, conf.Redpanda.AdvertisedKafkaApi)348 },349 }, {350 name: "it should evaluate config sources in this order: 1. config file, 2. key-value pairs passed with --set, 3. env vars, 4. specific flags",351 args: []string{352 "--config", "/arbitrary/path/redpanda.yaml",353 "--install-dir", "/var/lib/redpanda",354 "--kafka-addr", "flag://192.168.34.3:9093",355 },356 before: func(fs afero.Fs) error {357 os.Args = append(358 os.Args,359 "--set", `redpanda.kafka_api=- name: set360 address: 192.168.34.2361 port: 9092362`,363 )364 return os.Setenv("REDPANDA_KAFKA_ADDRESS", "env://192.168.34.1:9091")365 },366 after: func() {367 for i, a := range os.Args {368 if a == "--set" {369 os.Args = os.Args[:i]370 return371 }372 }373 },374 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {375 path := "/arbitrary/path/redpanda.yaml"376 mgr := config.NewManager(fs)377 conf, err := mgr.Read(path)378 require.NoError(st, err)379 // The value set through the --kafka-addr flag should380 // have been picked.381 expectedKafkaApi := []config.NamedSocketAddress{{382 Name: "flag",383 SocketAddress: config.SocketAddress{384 Address: "192.168.34.3",385 Port: 9093,386 },387 }}388 // The value set with --kafka-addr should have been prioritized389 require.Exactly(st, expectedKafkaApi, conf.Redpanda.KafkaApi)390 },391 }, {392 name: "it should write the default config file path if --config" +393 " isn't passed and the config file doesn't exist",394 args: []string{395 "--install-dir", "/var/lib/redpanda",396 },397 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {398 path := config.Default().ConfigFile399 mgr := config.NewManager(fs)400 conf, err := mgr.Read(path)401 require.NoError(st, err)402 require.Exactly(st, config.Default().ConfigFile, conf.ConfigFile)403 },404 }, {405 name: "it should leave config_file untouched if --config wasn't passed",406 args: []string{407 "--install-dir", "/var/lib/redpanda",408 },409 before: func(fs afero.Fs) error {410 mgr := config.NewManager(fs)411 conf := config.Default()412 return mgr.Write(conf)413 },414 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {415 mgr := config.NewManager(fs)416 conf, err := mgr.Read(config.Default().ConfigFile)417 require.NoError(st, err)418 require.Exactly(st, config.Default().ConfigFile, conf.ConfigFile)419 },420 }, {421 name: "it should write the given node ID",422 args: []string{423 "--node-id", "34",424 "--config", config.Default().ConfigFile,425 "--install-dir", "/var/lib/redpanda",426 },427 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {428 path := config.Default().ConfigFile429 mgr := config.NewManager(fs)430 conf, err := mgr.Read(path)431 require.NoError(st, err)432 require.Exactly(st, 34, conf.Redpanda.Id)433 },434 }, {435 name: "it should write the default node ID if --node-id isn't passed and the config file doesn't exist",436 args: []string{437 "--config", config.Default().ConfigFile,438 "--install-dir", "/var/lib/redpanda",439 },440 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {441 path := config.Default().ConfigFile442 mgr := config.NewManager(fs)443 conf, err := mgr.Read(path)444 require.NoError(st, err)445 // Check that the generated config is as expected.446 require.Exactly(st, config.Default().Redpanda.Id, conf.Redpanda.Id)447 },448 }, {449 name: "it should leave redpanda.node_id untouched if --node-id wasn't passed",450 args: []string{451 "--install-dir", "/var/lib/redpanda",452 },453 before: func(fs afero.Fs) error {454 mgr := config.NewManager(fs)455 conf := config.Default()456 conf.Redpanda.Id = 98457 return mgr.Write(conf)458 },459 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {460 mgr := config.NewManager(fs)461 conf, err := mgr.Read(config.Default().ConfigFile)462 require.NoError(st, err)463 require.Exactly(464 st,465 98,466 conf.Redpanda.Id,467 )468 },469 }, {470 name: "--well-known-io should override rpk.well_known_io",471 args: []string{472 "--well-known-io", "aws:i3xlarge:default",473 "--config", config.Default().ConfigFile,474 "--install-dir", "/var/lib/redpanda",475 },476 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {477 path := config.Default().ConfigFile478 mgr := config.NewManager(fs)479 conf, err := mgr.Read(path)480 require.NoError(st, err)481 require.Exactly(st, "aws:i3xlarge:default", conf.Rpk.WellKnownIo)482 },483 }, {484 name: "it should leave rpk.well_known_io untouched if --well-known-io" +485 " wasn't passed",486 args: []string{487 "--install-dir", "/var/lib/redpanda",488 },489 before: func(fs afero.Fs) error {490 mgr := config.NewManager(fs)491 conf := config.Default()492 conf.Rpk.WellKnownIo = "gcp:n2standard:ssd"493 return mgr.Write(conf)494 },495 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {496 mgr := config.NewManager(fs)497 conf, err := mgr.Read(config.Default().ConfigFile)498 require.NoError(st, err)499 require.Exactly(500 st,501 "gcp:n2standard:ssd",502 conf.Rpk.WellKnownIo,503 )504 },505 }, {506 name: "--overprovisioned should override the default value for rpk.overprovisioned",507 args: []string{508 // Bool flags will be true by just being present. Therefore, to509 // change their value, <flag>=<value> needs to be used510 "--overprovisioned=false",511 "--config", config.Default().ConfigFile,512 "--install-dir", "/var/lib/redpanda",513 },514 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {515 path := config.Default().ConfigFile516 mgr := config.NewManager(fs)517 conf, err := mgr.Read(path)518 require.NoError(st, err)519 // Check that the generated config is as expected.520 require.Exactly(st, false, conf.Rpk.Overprovisioned)521 },522 }, {523 name: "it should leave rpk.overprovisioned untouched if --overprovisioned wasn't passed",524 args: []string{525 "--install-dir", "/var/lib/redpanda",526 },527 before: func(fs afero.Fs) error {528 mgr := config.NewManager(fs)529 conf := config.Default()530 return mgr.Write(conf)531 },532 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {533 mgr := config.NewManager(fs)534 conf, err := mgr.Read(config.Default().ConfigFile)535 require.NoError(st, err)536 // Check that the generated config is as expected.537 require.Exactly(538 st,539 config.Default().Rpk.Overprovisioned,540 conf.Rpk.Overprovisioned,541 )542 },543 }, {544 name: "--lock-memory should override the default value for rpk.enable_memory_locking",545 args: []string{546 "--lock-memory",547 "--config", config.Default().ConfigFile,548 "--install-dir", "/var/lib/redpanda",549 },550 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {551 path := config.Default().ConfigFile552 mgr := config.NewManager(fs)553 conf, err := mgr.Read(path)554 require.NoError(st, err)555 // Check that the generated config is as expected.556 require.Exactly(st, true, conf.Rpk.EnableMemoryLocking)557 },558 }, {559 name: "it should leave rpk.enable_memory_locking untouched if" +560 " --lock-memory wasn't passed",561 args: []string{562 "--install-dir", "/var/lib/redpanda",563 },564 before: func(fs afero.Fs) error {565 mgr := config.NewManager(fs)566 conf := config.Default()567 conf.Rpk.EnableMemoryLocking = true568 return mgr.Write(conf)569 },570 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {571 mgr := config.NewManager(fs)572 conf, err := mgr.Read(config.Default().ConfigFile)573 require.NoError(st, err)574 // Check that the generated config is as expected.575 require.Exactly(576 st,577 true,578 conf.Rpk.EnableMemoryLocking,579 )580 },581 }, {582 name: "it should parse the --seeds and persist them",583 args: []string{584 "--install-dir", "/var/lib/redpanda",585 "--seeds", "192.168.34.32:33145,somehost:54321,justahostnoport",586 },587 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {588 mgr := config.NewManager(fs)589 conf, err := mgr.Read(config.Default().ConfigFile)590 require.NoError(st, err)591 expectedSeeds := []config.SeedServer{{592 Host: config.SocketAddress{593 Address: "192.168.34.32",594 Port: 33145,595 },596 }, {597 Host: config.SocketAddress{598 Address: "somehost",599 Port: 54321,600 },601 }, {602 Host: config.SocketAddress{603 Address: "justahostnoport",604 Port: 33145,605 },606 }}607 // Check that the generated config is as expected.608 require.Exactly(609 st,610 expectedSeeds,611 conf.Redpanda.SeedServers,612 )613 },614 }, {615 name: "it should parse the --seeds and persist them (shorthand)",616 args: []string{617 "--install-dir", "/var/lib/redpanda",618 "-s", "192.168.3.32:33145",619 "-s", "192.168.123.32:33146,host",620 },621 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {622 mgr := config.NewManager(fs)623 conf, err := mgr.Read(config.Default().ConfigFile)624 require.NoError(st, err)625 expectedSeeds := []config.SeedServer{{626 Host: config.SocketAddress{627 Address: "192.168.3.32",628 Port: 33145,629 },630 }, {631 Host: config.SocketAddress{632 Address: "192.168.123.32",633 Port: 33146,634 },635 }, {636 Host: config.SocketAddress{637 Address: "host",638 Port: 33145,639 },640 }}641 // Check that the generated config is as expected.642 require.Exactly(643 st,644 expectedSeeds,645 conf.Redpanda.SeedServers,646 )647 },648 }, {649 name: "if --seeds wasn't passed, it should fall back to REDPANDA_SEEDS and persist it",650 args: []string{651 "--install-dir", "/var/lib/redpanda",652 },653 before: func(_ afero.Fs) error {654 os.Setenv("REDPANDA_SEEDS", "10.23.12.5:33146,host")655 return nil656 },657 after: func() {658 os.Unsetenv("REDPANDA_SEEDS")659 },660 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {661 mgr := config.NewManager(fs)662 conf, err := mgr.Read(config.Default().ConfigFile)663 require.NoError(st, err)664 expectedSeeds := []config.SeedServer{{665 Host: config.SocketAddress{666 Address: "10.23.12.5",667 Port: 33146,668 },669 }, {670 Host: config.SocketAddress{671 Address: "host",672 Port: 33145,673 },674 }}675 // Check that the generated config is as expected.676 require.Exactly(677 st,678 expectedSeeds,679 conf.Redpanda.SeedServers,680 )681 },682 }, {683 name: "it should leave existing seeds untouched if --seeds or REDPANDA_SEEDS aren't set",684 args: []string{685 "--install-dir", "/var/lib/redpanda",686 },687 before: func(fs afero.Fs) error {688 mgr := config.NewManager(fs)689 conf := config.Default()690 conf.Redpanda.SeedServers = []config.SeedServer{{691 Host: config.SocketAddress{692 Address: "10.23.12.5",693 Port: 33146,694 },695 }}696 return mgr.Write(conf)697 },698 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {699 mgr := config.NewManager(fs)700 conf, err := mgr.Read(config.Default().ConfigFile)701 require.NoError(st, err)702 expectedSeeds := []config.SeedServer{{703 Host: config.SocketAddress{704 Address: "10.23.12.5",705 Port: 33146,706 },707 }}708 // Check that the generated config is as expected.709 require.Exactly(710 st,711 expectedSeeds,712 conf.Redpanda.SeedServers,713 )714 },715 }, {716 name: "it should fail if the host is missing in the given seed",717 args: []string{718 "-s", "goodhost.com:54897,:33145",719 },720 expectedErrMsg: "Couldn't parse seed ':33145': invalid host \":33145\" does not match \"host\", nor \"host:port\", nor \"scheme://host:port\"",721 }, {722 name: "it should fail if the port isnt an int",723 args: []string{724 "-s", "host:port",725 },726 expectedErrMsg: "Couldn't parse seed 'host:port': invalid host \"host:port\" does not match \"host\", nor \"host:port\", nor \"scheme://host:port\"",727 }, {728 name: "it should parse the --rpc-addr and persist it",729 args: []string{730 "--install-dir", "/var/lib/redpanda",731 "--rpc-addr", "192.168.34.32:33145",732 },733 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {734 mgr := config.NewManager(fs)735 conf, err := mgr.Read(config.Default().ConfigFile)736 require.NoError(st, err)737 expectedAddr := config.SocketAddress{738 Address: "192.168.34.32",739 Port: 33145,740 }741 // Check that the generated config is as expected.742 require.Exactly(743 st,744 expectedAddr,745 conf.Redpanda.RPCServer,746 )747 },748 }, {749 name: "it should parse the --rpc-addr and persist it (no port)",750 args: []string{751 "--install-dir", "/var/lib/redpanda",752 "--rpc-addr", "192.168.34.32",753 },754 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {755 mgr := config.NewManager(fs)756 conf, err := mgr.Read(config.Default().ConfigFile)757 require.NoError(st, err)758 expectedAddr := config.SocketAddress{759 Address: "192.168.34.32",760 Port: 33145,761 }762 // Check that the generated config is as expected.763 require.Exactly(764 st,765 expectedAddr,766 conf.Redpanda.RPCServer,767 )768 },769 }, {770 name: "it should fail if --rpc-addr is invalid",771 args: []string{772 "--install-dir", "/var/lib/redpanda",773 "--rpc-addr", "host:nonnumericport",774 },775 expectedErrMsg: "invalid host \"host:nonnumericport\" does not match \"host\", nor \"host:port\", nor \"scheme://host:port\"",776 }, {777 name: "if --rpc-addr wasn't passed, it should fall back to REDPANDA_RPC_ADDRESS and persist it",778 args: []string{779 "--install-dir", "/var/lib/redpanda",780 },781 before: func(_ afero.Fs) error {782 os.Setenv("REDPANDA_RPC_ADDRESS", "host:3123")783 return nil784 },785 after: func() {786 os.Unsetenv("REDPANDA_RPC_ADDRESS")787 },788 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {789 mgr := config.NewManager(fs)790 conf, err := mgr.Read(config.Default().ConfigFile)791 require.NoError(st, err)792 expectedAddr := config.SocketAddress{793 Address: "host",794 Port: 3123,795 }796 // Check that the generated config is as expected.797 require.Exactly(798 st,799 expectedAddr,800 conf.Redpanda.RPCServer,801 )802 },803 }, {804 name: "it should leave the RPC addr untouched if the env var & flag weren't set",805 args: []string{806 "--install-dir", "/var/lib/redpanda",807 },808 before: func(fs afero.Fs) error {809 mgr := config.NewManager(fs)810 conf := config.Default()811 conf.Redpanda.RPCServer = config.SocketAddress{812 Address: "192.168.33.33",813 Port: 9892,814 }815 return mgr.Write(conf)816 },817 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {818 mgr := config.NewManager(fs)819 conf, err := mgr.Read(config.Default().ConfigFile)820 require.NoError(st, err)821 expectedAddr := config.SocketAddress{822 Address: "192.168.33.33",823 Port: 9892,824 }825 // Check that the generated config is as expected.826 require.Exactly(827 st,828 expectedAddr,829 conf.Redpanda.RPCServer,830 )831 },832 }, {833 name: "it should parse the --kafka-addr and persist it",834 args: []string{835 "--install-dir", "/var/lib/redpanda",836 "--kafka-addr", "192.168.34.32:33145",837 },838 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {839 mgr := config.NewManager(fs)840 conf, err := mgr.Read(config.Default().ConfigFile)841 require.NoError(st, err)842 expectedAddr := []config.NamedSocketAddress{{843 SocketAddress: config.SocketAddress{844 Address: "192.168.34.32",845 Port: 33145,846 },847 }}848 // Check that the generated config is as expected.849 require.Exactly(850 st,851 expectedAddr,852 conf.Redpanda.KafkaApi,853 )854 },855 }, {856 name: "it should parse the --kafka-addr and persist it (no port)",857 args: []string{858 "--install-dir", "/var/lib/redpanda",859 "--kafka-addr", "192.168.34.32",860 },861 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {862 mgr := config.NewManager(fs)863 conf, err := mgr.Read(config.Default().ConfigFile)864 require.NoError(st, err)865 expectedAddr := []config.NamedSocketAddress{{866 SocketAddress: config.SocketAddress{867 Address: "192.168.34.32",868 Port: 9092,869 },870 }}871 // Check that the generated config is as expected.872 require.Exactly(873 st,874 expectedAddr,875 conf.Redpanda.KafkaApi,876 )877 },878 }, {879 name: "it should parse the --kafka-addr and persist it (named)",880 args: []string{881 "--install-dir", "/var/lib/redpanda",882 "--kafka-addr", "nondefaultname://192.168.34.32",883 },884 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {885 mgr := config.NewManager(fs)886 conf, err := mgr.Read(config.Default().ConfigFile)887 require.NoError(st, err)888 expectedAddr := []config.NamedSocketAddress{{889 Name: "nondefaultname",890 SocketAddress: config.SocketAddress{891 Address: "192.168.34.32",892 Port: 9092,893 },894 }}895 // Check that the generated config is as expected.896 require.Exactly(897 st,898 expectedAddr,899 conf.Redpanda.KafkaApi,900 )901 },902 }, {903 name: "it should parse the --kafka-addr and persist it (list)",904 args: []string{905 "--install-dir", "/var/lib/redpanda",906 "--kafka-addr", "nondefaultname://192.168.34.32,host:9092",907 },908 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {909 mgr := config.NewManager(fs)910 conf, err := mgr.Read(config.Default().ConfigFile)911 require.NoError(st, err)912 expectedAddr := []config.NamedSocketAddress{{913 Name: "nondefaultname",914 SocketAddress: config.SocketAddress{915 Address: "192.168.34.32",916 Port: 9092,917 },918 }, {919 SocketAddress: config.SocketAddress{920 Address: "host",921 Port: 9092,922 },923 }}924 // Check that the generated config is as expected.925 require.Exactly(926 st,927 expectedAddr,928 conf.Redpanda.KafkaApi,929 )930 },931 }, {932 name: "it should fail if --kafka-addr is invalid",933 args: []string{934 "--install-dir", "/var/lib/redpanda",935 "--kafka-addr", "host:nonnumericport",936 },937 expectedErrMsg: "invalid host \"host:nonnumericport\" does not match \"host\", nor \"host:port\", nor \"scheme://host:port\"",938 }, {939 name: "if --kafka-addr wasn't passed, it should fall back to REDPANDA_KAFKA_ADDRESS and persist it",940 args: []string{941 "--install-dir", "/var/lib/redpanda",942 },943 before: func(_ afero.Fs) error {944 os.Setenv("REDPANDA_KAFKA_ADDRESS", "host:3123")945 return nil946 },947 after: func() {948 os.Unsetenv("REDPANDA_KAFKA_ADDRESS")949 },950 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {951 mgr := config.NewManager(fs)952 conf, err := mgr.Read(config.Default().ConfigFile)953 require.NoError(st, err)954 expectedAddr := []config.NamedSocketAddress{{955 SocketAddress: config.SocketAddress{956 Address: "host",957 Port: 3123,958 },959 }}960 // Check that the generated config is as expected.961 require.Exactly(962 st,963 expectedAddr,964 conf.Redpanda.KafkaApi,965 )966 },967 }, {968 name: "it should leave the Kafka addr untouched if the env var & flag weren't set",969 args: []string{970 "--install-dir", "/var/lib/redpanda",971 },972 before: func(fs afero.Fs) error {973 mgr := config.NewManager(fs)974 conf := config.Default()975 conf.Redpanda.KafkaApi = []config.NamedSocketAddress{{976 SocketAddress: config.SocketAddress{977 Address: "192.168.33.33",978 Port: 9892,979 },980 }}981 return mgr.Write(conf)982 },983 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {984 mgr := config.NewManager(fs)985 conf, err := mgr.Read(config.Default().ConfigFile)986 require.NoError(st, err)987 expectedAddr := []config.NamedSocketAddress{{988 SocketAddress: config.SocketAddress{989 Address: "192.168.33.33",990 Port: 9892,991 },992 }}993 // Check that the generated config is as expected.994 require.Exactly(995 st,996 expectedAddr,997 conf.Redpanda.KafkaApi,998 )999 },1000 }, {1001 name: "it should parse the --advertise-kafka-addr and persist it",1002 args: []string{1003 "--install-dir", "/var/lib/redpanda",1004 "--advertise-kafka-addr", "192.168.34.32:33145",1005 },1006 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {1007 mgr := config.NewManager(fs)1008 conf, err := mgr.Read(config.Default().ConfigFile)1009 require.NoError(st, err)1010 expectedAddr := []config.NamedSocketAddress{{1011 SocketAddress: config.SocketAddress{1012 Address: "192.168.34.32",1013 Port: 33145,1014 },1015 }}1016 // Check that the generated config is as expected.1017 require.Exactly(1018 st,1019 expectedAddr,1020 conf.Redpanda.AdvertisedKafkaApi,1021 )1022 },1023 }, {1024 name: "it should parse the --advertise-kafka-addr and persist it (no port)",1025 args: []string{1026 "--install-dir", "/var/lib/redpanda",1027 "--advertise-kafka-addr", "192.168.34.32",1028 },1029 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {1030 mgr := config.NewManager(fs)1031 conf, err := mgr.Read(config.Default().ConfigFile)1032 require.NoError(st, err)1033 expectedAddr := []config.NamedSocketAddress{{1034 SocketAddress: config.SocketAddress{1035 Address: "192.168.34.32",1036 Port: 9092,1037 },1038 }}1039 // Check that the generated config is as expected.1040 require.Exactly(1041 st,1042 expectedAddr,1043 conf.Redpanda.AdvertisedKafkaApi,1044 )1045 },1046 }, {1047 name: "it should fail if --advertise-kafka-addr is invalid",1048 args: []string{1049 "--install-dir", "/var/lib/redpanda",1050 "--advertise-kafka-addr", "host:nonnumericport",1051 },1052 expectedErrMsg: "invalid host \"host:nonnumericport\" does not match \"host\", nor \"host:port\", nor \"scheme://host:port\"",1053 }, {1054 name: "if --advertise-kafka-addr, it should fall back to REDPANDA_ADVERTISE_KAFKA_ADDRESS and persist it",1055 args: []string{1056 "--install-dir", "/var/lib/redpanda",1057 },1058 before: func(_ afero.Fs) error {1059 os.Setenv("REDPANDA_ADVERTISE_KAFKA_ADDRESS", "host:3123")1060 return nil1061 },1062 after: func() {1063 os.Unsetenv("REDPANDA_ADVERTISE_KAFKA_ADDRESS")1064 },1065 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {1066 mgr := config.NewManager(fs)1067 conf, err := mgr.Read(config.Default().ConfigFile)1068 require.NoError(st, err)1069 expectedAddr := []config.NamedSocketAddress{{1070 SocketAddress: config.SocketAddress{1071 Address: "host",1072 Port: 3123,1073 },1074 }}1075 // Check that the generated config is as expected.1076 require.Exactly(1077 st,1078 expectedAddr,1079 conf.Redpanda.AdvertisedKafkaApi,1080 )1081 },1082 }, {1083 name: "it should leave the adv. Kafka addr untouched if the env var & flag weren't set",1084 args: []string{1085 "--install-dir", "/var/lib/redpanda",1086 },1087 before: func(fs afero.Fs) error {1088 mgr := config.NewManager(fs)1089 conf := config.Default()1090 conf.Redpanda.AdvertisedKafkaApi = []config.NamedSocketAddress{{1091 SocketAddress: config.SocketAddress{1092 Address: "192.168.33.33",1093 Port: 9892,1094 },1095 }}1096 return mgr.Write(conf)1097 },1098 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {1099 mgr := config.NewManager(fs)1100 conf, err := mgr.Read(config.Default().ConfigFile)1101 require.NoError(st, err)1102 expectedAddr := []config.NamedSocketAddress{{1103 SocketAddress: config.SocketAddress{1104 Address: "192.168.33.33",1105 Port: 9892,1106 },1107 }}1108 // Check that the generated config is as expected.1109 require.Exactly(1110 st,1111 expectedAddr,1112 conf.Redpanda.AdvertisedKafkaApi,1113 )1114 },1115 }, {1116 name: "it should parse the --advertise-pandaproxy-addr and persist it",1117 args: []string{1118 "--install-dir", "/var/lib/redpanda",1119 "--advertise-pandaproxy-addr", "192.168.34.32:8083",1120 },1121 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {1122 mgr := config.NewManager(fs)1123 conf, err := mgr.Read(config.Default().ConfigFile)1124 require.NoError(st, err)1125 expectedAddr := []config.NamedSocketAddress{{1126 SocketAddress: config.SocketAddress{1127 Address: "192.168.34.32",1128 Port: 8083,1129 },1130 }}1131 // Check that the generated config is as expected.1132 require.Exactly(1133 st,1134 expectedAddr,1135 conf.Pandaproxy.AdvertisedPandaproxyAPI,1136 )1137 },1138 }, {1139 name: "if --advertise-pandaproxy-addr, it should fall back to REDPANDA_ADVERTISE_PANDAPROXY_ADDRESS and persist it",1140 args: []string{1141 "--install-dir", "/var/lib/redpanda",1142 },1143 before: func(_ afero.Fs) error {1144 os.Setenv("REDPANDA_ADVERTISE_PANDAPROXY_ADDRESS", "host:3123")1145 return nil1146 },1147 after: func() {1148 os.Unsetenv("REDPANDA_ADVERTISE_PANDAPROXY_ADDRESS")1149 },1150 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {1151 mgr := config.NewManager(fs)1152 conf, err := mgr.Read(config.Default().ConfigFile)1153 require.NoError(st, err)1154 expectedAddr := []config.NamedSocketAddress{{1155 SocketAddress: config.SocketAddress{1156 Address: "host",1157 Port: 3123,1158 },1159 }}1160 // Check that the generated config is as expected.1161 require.Exactly(1162 st,1163 expectedAddr,1164 conf.Pandaproxy.AdvertisedPandaproxyAPI,1165 )1166 },1167 }, {1168 name: "it should parse the --advertise-rpc-addr and persist it",1169 args: []string{1170 "--install-dir", "/var/lib/redpanda",1171 "--advertise-rpc-addr", "192.168.34.32:33145",1172 },1173 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {1174 mgr := config.NewManager(fs)1175 conf, err := mgr.Read(config.Default().ConfigFile)1176 require.NoError(st, err)1177 expectedAddr := &config.SocketAddress{1178 Address: "192.168.34.32",1179 Port: 33145,1180 }1181 // Check that the generated config is as expected.1182 require.Exactly(1183 st,1184 expectedAddr,1185 conf.Redpanda.AdvertisedRPCAPI,1186 )1187 },1188 }, {1189 name: "it should parse the --advertise-rpc-addr and persist it (no port)",1190 args: []string{1191 "--install-dir", "/var/lib/redpanda",1192 "--advertise-rpc-addr", "192.168.34.32",1193 },1194 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {1195 mgr := config.NewManager(fs)1196 conf, err := mgr.Read(config.Default().ConfigFile)1197 require.NoError(st, err)1198 expectedAddr := &config.SocketAddress{1199 Address: "192.168.34.32",1200 Port: 33145,1201 }1202 // Check that the generated config is as expected.1203 require.Exactly(1204 st,1205 expectedAddr,1206 conf.Redpanda.AdvertisedRPCAPI,1207 )1208 },1209 }, {1210 name: "it should fail if --advertise-rpc-addr is invalid",1211 args: []string{1212 "--install-dir", "/var/lib/redpanda",1213 "--advertise-rpc-addr", "host:nonnumericport",1214 },1215 expectedErrMsg: "invalid host \"host:nonnumericport\" does not match \"host\", nor \"host:port\", nor \"scheme://host:port\"",1216 }, {1217 name: "if --advertise-rpc-addr wasn't passed, it should fall back to REDPANDA_ADVERTISE_RPC_ADDRESS and persist it",1218 args: []string{1219 "--install-dir", "/var/lib/redpanda",1220 },1221 before: func(_ afero.Fs) error {1222 os.Setenv("REDPANDA_ADVERTISE_RPC_ADDRESS", "host:3123")1223 return nil1224 },1225 after: func() {1226 os.Unsetenv("REDPANDA_ADVERTISE_RPC_ADDRESS")1227 },1228 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {1229 mgr := config.NewManager(fs)1230 conf, err := mgr.Read(config.Default().ConfigFile)1231 require.NoError(st, err)1232 expectedAddr := &config.SocketAddress{1233 Address: "host",1234 Port: 3123,1235 }1236 // Check that the generated config is as expected.1237 require.Exactly(1238 st,1239 expectedAddr,1240 conf.Redpanda.AdvertisedRPCAPI,1241 )1242 },1243 }, {1244 name: "it should leave the adv. RPC addr untouched if the env var & flag weren't set",1245 args: []string{1246 "--install-dir", "/var/lib/redpanda",1247 },1248 before: func(fs afero.Fs) error {1249 mgr := config.NewManager(fs)1250 conf := config.Default()1251 conf.Redpanda.AdvertisedRPCAPI = &config.SocketAddress{1252 Address: "192.168.33.33",1253 Port: 9892,1254 }1255 return mgr.Write(conf)1256 },1257 postCheck: func(fs afero.Fs, _ *rp.RedpandaArgs, st *testing.T) {1258 mgr := config.NewManager(fs)1259 conf, err := mgr.Read(config.Default().ConfigFile)1260 require.NoError(st, err)1261 expectedAddr := &config.SocketAddress{1262 Address: "192.168.33.33",1263 Port: 9892,1264 }1265 // Check that the generated config is as expected.1266 require.Exactly(1267 st,1268 expectedAddr,1269 conf.Redpanda.AdvertisedRPCAPI,1270 )1271 },1272 }, {1273 name: "it should fail if --overprovisioned is set in the config file too",1274 args: []string{1275 "--install-dir", "/var/lib/redpanda", "--overprovisioned",1276 },1277 before: func(fs afero.Fs) error {1278 mgr := config.NewManager(fs)1279 conf := config.Default()1280 conf.Rpk.AdditionalStartFlags = []string{"--overprovisioned"}1281 return mgr.Write(conf)1282 },1283 expectedErrMsg: "Configuration conflict. Flag '--overprovisioned' is also present in 'rpk.additional_start_flags' in configuration file '/etc/redpanda/redpanda.yaml'. Please remove it and pass '--overprovisioned' directly to `rpk start`.",1284 }, {1285 name: "it should fail if --smp is set in the config file too",1286 args: []string{1287 "--install-dir", "/var/lib/redpanda", "--smp", "1",1288 },1289 before: func(fs afero.Fs) error {1290 mgr := config.NewManager(fs)1291 conf := config.Default()1292 conf.Rpk.AdditionalStartFlags = []string{"--smp=1"}1293 return mgr.Write(conf)1294 },1295 expectedErrMsg: "Configuration conflict. Flag '--smp' is also present in 'rpk.additional_start_flags' in configuration file '/etc/redpanda/redpanda.yaml'. Please remove it and pass '--smp' directly to `rpk start`.",1296 }, {1297 name: "it should fail if --memory is set in the config file too",1298 args: []string{1299 "--install-dir", "/var/lib/redpanda", "--memory", "2G",1300 },1301 before: func(fs afero.Fs) error {1302 mgr := config.NewManager(fs)1303 conf := config.Default()1304 conf.Rpk.AdditionalStartFlags = []string{"--memory=1G"}1305 return mgr.Write(conf)1306 },1307 expectedErrMsg: "Configuration conflict. Flag '--memory' is also present in 'rpk.additional_start_flags' in configuration file '/etc/redpanda/redpanda.yaml'. Please remove it and pass '--memory' directly to `rpk start`.",1308 }, {1309 name: "it should pass the last instance of a duplicate flag set in rpk.additional_start_flags",1310 args: []string{1311 "--install-dir", "/var/lib/redpanda",1312 },1313 before: func(fs afero.Fs) error {1314 mgr := config.NewManager(fs)1315 conf := config.Default()1316 conf.Rpk.AdditionalStartFlags = []string{1317 "--smp=3", "--smp=55",1318 }1319 return mgr.Write(conf)1320 },1321 postCheck: func(1322 _ afero.Fs,1323 rpArgs *rp.RedpandaArgs,1324 st *testing.T,1325 ) {1326 require.Equal(st, "55", rpArgs.SeastarFlags["smp"])1327 },1328 }, {1329 name: "it should allow setting flags with multiple key=values in rpk.additional_start_flags",1330 args: []string{1331 "--install-dir", "/var/lib/redpanda",1332 },1333 before: func(fs afero.Fs) error {1334 mgr := config.NewManager(fs)1335 conf := config.Default()1336 conf.Rpk.AdditionalStartFlags = []string{1337 "--logger-log-level=archival=debug:cloud_storage=debug",1338 }1339 return mgr.Write(conf)1340 },1341 postCheck: func(1342 _ afero.Fs,1343 rpArgs *rp.RedpandaArgs,1344 st *testing.T,1345 ) {1346 require.Equal(st, "archival=debug:cloud_storage=debug", rpArgs.SeastarFlags["logger-log-level"])1347 },1348 }, {1349 name: "it should pass the last instance of a duplicate flag passed to rpk start",1350 args: []string{1351 "--install-dir", "/var/lib/redpanda",1352 "--memory", "1G", "--memory", "4G",1353 },1354 postCheck: func(1355 _ afero.Fs,1356 rpArgs *rp.RedpandaArgs,1357 st *testing.T,1358 ) {1359 require.Equal(st, "4G", rpArgs.SeastarFlags["memory"])1360 },1361 }, {1362 name: "it should allow arbitrary flags",1363 args: []string{1364 "--install-dir", "/var/lib/redpanda",1365 "--this-flag-is-definitely-not-known", "right",1366 "--kernel-page-cache", "1",1367 "--another-arbitrary-seastar-flag", "",1368 },1369 }, {1370 name: "it should allow arbitrary flags after '--'",1371 args: []string{1372 "--install-dir", "/var/lib/redpanda",1373 "--",1374 "--i-just-made-this-on-the-spot", "nice",1375 },1376 postCheck: func(1377 _ afero.Fs,1378 rpArgs *rp.RedpandaArgs,1379 st *testing.T,1380 ) {1381 expected := []string{1382 "--i-just-made-this-on-the-spot", "nice",1383 }1384 require.Equal(st, expected, rpArgs.ExtraArgs)1385 },1386 }}1387 for _, tt := range tests {1388 t.Run(tt.name, func(st *testing.T) {1389 if tt.after != nil {1390 defer tt.after()1391 }1392 fs := afero.NewMemMapFs()1393 mgr := config.NewManager(fs)1394 var launcher rp.Launcher = &noopLauncher{}1395 if tt.launcher != nil {1396 launcher = tt.launcher1397 }1398 if tt.before != nil {1399 require.NoError(st, tt.before(fs))1400 }1401 var out bytes.Buffer1402 logrus.SetOutput(&out)1403 c := NewStartCommand(fs, mgr, launcher)1404 c.SetArgs(tt.args)1405 err := c.Execute()1406 if tt.expectedErrMsg != "" {1407 require.EqualError(st, err, tt.expectedErrMsg)...
manager.go
Source:manager.go
...74// pass to the browser when launch it remotely.75// The work flow looks like:76//77// | Machine X | Machine Y |78// | NewManaged("a.com") -|-> http.ListenAndServe("a.com", launcher.NewManager()) --> launch browser |79//80// 1. X send a http request to Y, Y respond default Launcher settings based the OS of Y.81// 2. X start a websocket connect to Y with the Launcher settings82// 3. Y launches a browser with the Launcher settings X83// 4. Y transparently proxy the websocket connect between X and the launched browser84//85type Manager struct {86 // Logger for key events87 Logger utils.Logger88 // Defaults should return the default Launcher settings89 Defaults func(http.ResponseWriter, *http.Request) *Launcher90 // BeforeLaunch hook is called right before the launching with the Launcher instance that will be used91 // to launch the browser.92 // Such as use it to filter malicious values of Launcher.UserDataDir, Launcher.Bin, or Launcher.WorkingDir.93 BeforeLaunch func(*Launcher, http.ResponseWriter, *http.Request)94}95// NewManager instance96func NewManager() *Manager {97 allowedPath := map[flags.Flag]string{98 flags.Bin: DefaultBrowserDir,99 flags.WorkingDir: func() string {100 p, _ := os.Getwd()101 return p102 }(),103 flags.UserDataDir: DefaultUserDataDirPrefix,104 }105 return &Manager{106 Logger: utils.LoggerQuiet,107 Defaults: func(_ http.ResponseWriter, _ *http.Request) *Launcher { return New() },108 BeforeLaunch: func(l *Launcher, w http.ResponseWriter, r *http.Request) {109 for f, allowed := range allowedPath {110 p := l.Get(f)...
NewManager
Using AI Code Generation
1import (2func main() {3 kb, err := keybd_event.NewKeyBonding()4 if err != nil {5 panic(err)6 }7 kb.SetKeys(keybd_event.VK_H, keybd_event.VK_E, keybd_event.VK_L, keybd_event.VK_L, keybd_event.VK_O, keybd_event.VK_SPACE, keybd_event.VK_W, keybd_event.VK_O, keybd_event.VK_R, keybd_event.VK_L, keybd_event.VK_D)8 err = kb.Launching()9 if err != nil {10 panic(err)11 }12 kb.HasALT(true)13 kb.SetKeys(keybd_event.VK_H, keybd_event.VK_E, keybd_event.VK_L, keybd_event.VK_L, keybd_event.VK_O, keybd_event.VK_SPACE, keybd_event.VK_W, keybd_event.VK_O, keybd_event.VK_R, keybd_event.VK_L, keybd_event.VK_D)14 err = kb.Launching()15 if err != nil {16 panic(err)17 }18 time.Sleep(time.Second * 3)19 err = kb.Launching()20 if err != nil {21 panic(err)22 }23 kb.HasCTRL(true)24 kb.SetKeys(keybd_event.VK_H, keybd_event.VK_E, keybd_event.VK_L, keybd_event.VK_L, keybd_event.VK_O, keybd_event.VK_SPACE, keybd_event.VK_W, keybd_event.VK_O, keybd_event.VK_R, keybd_event.VK_L, keybd_event.VK_D)25 err = kb.Launching()26 if err != nil {27 panic(err)28 }29 time.Sleep(time.Second * 3)30 err = kb.Launching()31 if err != nil {32 panic(err)33 }34 kb.HasSHIFT(true)35 kb.SetKeys(keybd_event.VK_H, keybd_event.VK_E, keybd_event.VK_L, keybd_event.VK_L, keybd_event.VK_O, keybd_event.VK_SPACE, keybd_event.VK_W, key
NewManager
Using AI Code Generation
1import (2type Manager struct {3}4func NewManager(name string, age int) *Manager {5 return &Manager{6 }7}8func main() {9 v := reflect.ValueOf(NewManager("Bob", 42))10 m := v.MethodByName("String")11 ret := m.Call(nil)12 fmt.Println(ret[0].Interface().(string))13}
NewManager
Using AI Code Generation
1import (2func main() {3 runtime.GOMAXPROCS(runtime.NumCPU())4 launcher.NewManager()5 fmt.Println("Hello, playground")6}7import (8type Manager struct {9}10func NewManager() *Manager {11 m := &Manager{12 messages: make(chan string),13 quit: make(chan bool),14 }15 go m.run()16}17func (m *Manager) run() {18 for {19 select {20 fmt.Println(msg)21 fmt.Println("Quit")22 }23 }24}25func (m *Manager) SendMessage(msg string) {26}27func (m *Manager) Close() {28}29func main() {30 runtime.GOMAXPROCS(runtime.NumCPU())31 launcher.NewManager()32 fmt.Println("Hello, playground")33}
NewManager
Using AI Code Generation
1import "fmt"2import "launcher"3func main() {4 obj := launcher.NewManager()5 obj.Start()6}7import "fmt"8type Manager struct {}9func NewManager() *Manager {10 return &Manager{}11}12func (m *Manager) Start() {13 fmt.Println("Starting launcher")14}15import "testing"16func TestNewManager(t *testing.T) {17 obj := NewManager()18 if obj == nil {19 t.Errorf("NewManager() = %v; want non-nil", obj)20 }21}22imports launcher23imports launcher: cannot find package "launcher" in any of:24 /usr/local/go/src/launcher (from $GOROOT)25 /home/kunal/go/src/launcher (from $GOPATH)26import "testing"27func TestNewManager(t *testing.T) {28 obj := launcher.NewManager()29 if obj == nil {30 t.Errorf("NewManager() = %v; want non-nil", obj)31 }32}
NewManager
Using AI Code Generation
1func NewManager() Manager {2 return &manager{}3}4func NewManager() Manager {5 return &manager{}6}7func NewManager() Manager {8 return &manager{}9}10func NewManager() Manager {11 return &manager{}12}13func NewManager() Manager {14 return &manager{}15}16func NewManager() Manager {17 return &manager{}18}19func NewManager() Manager {20 return &manager{}21}22func NewManager() Manager {23 return &manager{}24}25func NewManager() Manager {26 return &manager{}27}28func NewManager() Manager {29 return &manager{}30}31func NewManager() Manager {32 return &manager{}33}
NewManager
Using AI Code Generation
1import (2func main() {3 m := launcher.NewManager()4 l := launcher.Launcher{5 }6 m.Add(l)7 fmt.Println(m.Launchers[0].Name)8}9import (10func main() {11 m := launcher.NewManager()12 l := launcher.Launcher{13 }14 m.Add(l)15 fmt.Println(m.Launchers[0].Name)16 m.Remove(l)17 fmt.Println(len(m.Launchers))18}19import (20func main() {21 m := launcher.NewManager()22 l := launcher.Launcher{23 }24 m.Add(l)25 fmt.Println(m.Launchers[0].Name)26 m.Remove(l)27 fmt.Println(len(m.Launchers))28 m.Add(l)29 fmt.Println(len(m.Launchers))30 fmt.Println(m.Launchers[0].Name)31}
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!!