How to use GetConfig method of client Package

Best Testkube code snippet using client.GetConfig

manager_test.go

Source:manager_test.go Github

copy

Full Screen

...199 t.Fatalf("Config(%v): Expected config to be created but error was thrown:"+200 " %s",201 c.request, err.Error())202 }203 if cfg.GetConfig().BearerToken != c.expected {204 t.Fatalf("Config(%v): Expected token to be %s but got %s",205 c.request, c.expected, cfg.GetConfig().BearerToken)206 }207 }208}209func TestClientCmdConfig(t *testing.T) {210 args.GetHolderBuilder().SetEnableSkipLogin(true)211 cases := []struct {212 request *restful.Request213 expected string214 }{215 {216 &restful.Request{217 Request: &http.Request{218 Header: http.Header(map[string][]string{219 "Authorization": {"Bearer test-token"},220 }),221 TLS: &tls.ConnectionState{},222 },223 },224 "test-token",225 },226 }227 for _, c := range cases {228 manager := NewClientManager("", "https://localhost:8080")229 cmdCfg, err := manager.ClientCmdConfig(c.request)230 if err != nil {231 t.Fatalf("Config(%v): Expected client config to be created but error was thrown:"+232 " %s",233 c.request, err.Error())234 }235 var bearerToken string236 if cmdCfg != nil {237 cfg, err := cmdCfg.ClientConfig()238 if err != nil {239 t.Fatalf("Config(%v): Expected config to be created but error was thrown:"+240 " %s",241 c.request, err.Error())242 }243 bearerToken = cfg.GetConfig().BearerToken244 }245 if bearerToken != c.expected {246 t.Fatalf("Config(%v): Expected token to be %s but got %s",247 c.request, c.expected, bearerToken)248 }249 }250}251func TestVerberClient(t *testing.T) {252 manager := NewClientManager("", "http://localhost:8080")253 _, err := manager.VerberClient(&restful.Request{Request: &http.Request{TLS: &tls.ConnectionState{}}}, &rest.Config{})254 if err != nil {255 t.Fatalf("VerberClient(): Expected verber client to be created but got error: %s",256 err.Error())257 }258}259func TestClientManager_InsecureClients(t *testing.T) {260 manager := NewClientManager("", "http://localhost:8080")261 if manager.InsecureClient() == nil {262 t.Fatalf("InsecureClient(): Expected insecure client not to be nil")263 }264}265func TestClientManager_InsecureAPIExtensionsClient(t *testing.T) {266 manager := NewClientManager("", "http://localhost:8080")267 if manager.InsecureAPIExtensionsClient() == nil {268 t.Fatalf("InsecureClient(): Expected insecure client not to be nil")269 }270}271func TestImpersonationUserClient(t *testing.T) {272 args.GetHolderBuilder().SetEnableSkipLogin(true)273 cases := []struct {274 request *restful.Request275 expected string276 expectedImpersonationUser string277 }{278 {279 &restful.Request{280 Request: &http.Request{281 Header: http.Header(map[string][]string{282 "Authorization": {"Bearer test-token"},283 "Impersonate-User": {"impersonatedUser"},284 }),285 TLS: &tls.ConnectionState{},286 },287 },288 "test-token",289 "impersonatedUser",290 },291 }292 for _, c := range cases {293 manager := NewClientManager("", "https://localhost:8080")294 cfg, err := manager.Config(c.request)295 //authInfo := manager.extractAuthInfo(c.request)296 if err != nil {297 t.Fatalf("Config(%v): Expected config to be created but error was thrown:"+298 " %s",299 c.request, err.Error())300 }301 if cfg.GetConfig().BearerToken != c.expected {302 t.Fatalf("Config(%v): Expected token to be %s but got %s",303 c.request, c.expected, cfg.GetConfig().BearerToken)304 }305 if cfg.GetConfig().Impersonate.UserName != c.expectedImpersonationUser {306 t.Fatalf("Config(%v): Expected impersonated user to be %s but got %s",307 c.request, c.expectedImpersonationUser, cfg.GetConfig().Impersonate.UserName)308 }309 }310}311func TestNoImpersonationUserWithNoBearerClient(t *testing.T) {312 args.GetHolderBuilder().SetEnableSkipLogin(true)313 cases := []struct {314 request *restful.Request315 }{316 {317 &restful.Request{318 Request: &http.Request{319 Header: http.Header(map[string][]string{}),320 TLS: &tls.ConnectionState{},321 },322 },323 },324 }325 for _, c := range cases {326 manager := NewClientManager("", "https://localhost:8080")327 cfg, err := manager.Config(c.request)328 //authInfo := manager.extractAuthInfo(c.request)329 if err != nil {330 t.Fatalf("Config(%v): Expected config to be created but error was thrown:"+331 " %s",332 c.request, err.Error())333 }334 if len(cfg.GetConfig().BearerToken) > 0 {335 t.Fatalf("Config(%v): Expected no token but got %s",336 c.request, cfg.GetConfig().BearerToken)337 }338 if len(cfg.GetConfig().Impersonate.UserName) > 0 {339 t.Fatalf("Config(%v): Expected no impersonated user but got %s",340 c.request, cfg.GetConfig().Impersonate.UserName)341 }342 }343}344func TestImpersonationOneGroupClient(t *testing.T) {345 args.GetHolderBuilder().SetEnableSkipLogin(true)346 cases := []struct {347 request *restful.Request348 expected string349 expectedImpersonationUser string350 expectedImpersonationGroups []string351 }{352 {353 &restful.Request{354 Request: &http.Request{355 Header: http.Header(map[string][]string{356 "Authorization": {"Bearer test-token"},357 "Impersonate-User": {"impersonatedUser"},358 "Impersonate-Group": {"group1"},359 }),360 TLS: &tls.ConnectionState{},361 },362 },363 "test-token",364 "impersonatedUser",365 []string{"group1"},366 },367 }368 for _, c := range cases {369 manager := NewClientManager("", "https://localhost:8080")370 cfg, err := manager.Config(c.request)371 //authInfo := manager.extractAuthInfo(c.request)372 if err != nil {373 t.Fatalf("Config(%v): Expected config to be created but error was thrown:"+374 " %s",375 c.request, err.Error())376 }377 if cfg.GetConfig().BearerToken != c.expected {378 t.Fatalf("Config(%v): Expected token to be %s but got %s",379 c.request, c.expected, cfg.GetConfig().BearerToken)380 }381 if cfg.GetConfig().Impersonate.UserName != c.expectedImpersonationUser {382 t.Fatalf("Config(%v): Expected impersonated user to be %s but got %s",383 c.request, c.expectedImpersonationUser, cfg.GetConfig().Impersonate.UserName)384 }385 if len(cfg.GetConfig().Impersonate.Groups) != 1 {386 t.Fatalf("Config(%v): Expected one impersonated group but got %d",387 c.request, len(cfg.GetConfig().Impersonate.Groups))388 }389 if cfg.GetConfig().Impersonate.Groups[0] != c.expectedImpersonationGroups[0] {390 t.Fatalf("Config(%v): Expected impersonated group to be %s but got %s",391 c.request, cfg.GetConfig().Impersonate.Groups[0], c.expectedImpersonationGroups[0])392 }393 }394}395func TestImpersonationTwoGroupClient(t *testing.T) {396 args.GetHolderBuilder().SetEnableSkipLogin(true)397 cases := []struct {398 request *restful.Request399 expected string400 expectedImpersonationUser string401 expectedImpersonationGroups []string402 }{403 {404 &restful.Request{405 Request: &http.Request{406 Header: http.Header(map[string][]string{407 "Authorization": {"Bearer test-token"},408 "Impersonate-User": {"impersonatedUser"},409 "Impersonate-Group": {"group1", "groups2"},410 }),411 TLS: &tls.ConnectionState{},412 },413 },414 "test-token",415 "impersonatedUser",416 []string{"group1", "groups2"},417 },418 }419 for _, c := range cases {420 manager := NewClientManager("", "https://localhost:8080")421 cfg, err := manager.Config(c.request)422 //authInfo := manager.extractAuthInfo(c.request)423 if err != nil {424 t.Fatalf("Config(%v): Expected config to be created but error was thrown:"+425 " %s",426 c.request, err.Error())427 }428 if cfg.GetConfig().BearerToken != c.expected {429 t.Fatalf("Config(%v): Expected token to be %s but got %s",430 c.request, c.expected, cfg.GetConfig().BearerToken)431 }432 if cfg.GetConfig().Impersonate.UserName != c.expectedImpersonationUser {433 t.Fatalf("Config(%v): Expected impersonated user to be %s but got %s",434 c.request, c.expectedImpersonationUser, cfg.GetConfig().Impersonate.UserName)435 }436 if len(cfg.GetConfig().Impersonate.Groups) != 2 {437 t.Fatalf("Config(%v): Expected two impersonated group but got %d",438 c.request, len(cfg.GetConfig().Impersonate.Groups))439 }440 if cfg.GetConfig().Impersonate.Groups[0] != c.expectedImpersonationGroups[0] {441 t.Fatalf("Config(%v): Expected impersonated group to be %s but got %s",442 c.request, cfg.GetConfig().Impersonate.Groups[0], c.expectedImpersonationGroups[0])443 }444 if cfg.GetConfig().Impersonate.Groups[1] != c.expectedImpersonationGroups[1] {445 t.Fatalf("Config(%v): Expected impersonated group to be %s but got %s",446 c.request, cfg.GetConfig().Impersonate.Groups[1], c.expectedImpersonationGroups[1])447 }448 }449}450func TestImpersonationExtrasClient(t *testing.T) {451 args.GetHolderBuilder().SetEnableSkipLogin(true)452 cases := []struct {453 request *restful.Request454 expected string455 expectedImpersonationUser string456 expectedImpersonationExtra map[string][]string457 }{458 {459 &restful.Request{460 Request: &http.Request{461 Header: http.Header(map[string][]string{462 "Authorization": {"Bearer test-token"},463 "Impersonate-User": {"impersonatedUser"},464 "Impersonate-Extra-scope": {"views", "writes"},465 "Impersonate-Extra-service": {"iguess"},466 }),467 TLS: &tls.ConnectionState{},468 },469 },470 "test-token",471 "impersonatedUser",472 map[string][]string{"scope": {"views", "writes"},473 "service": {"iguess"}},474 },475 }476 for _, c := range cases {477 manager := NewClientManager("", "https://localhost:8080")478 cfg, err := manager.Config(c.request)479 //authInfo := manager.extractAuthInfo(c.request)480 if err != nil {481 t.Fatalf("Config(%v): Expected config to be created but error was thrown:"+482 " %s",483 c.request, err.Error())484 }485 if cfg.GetConfig().BearerToken != c.expected {486 t.Fatalf("Config(%v): Expected token to be %s but got %s",487 c.request, c.expected, cfg.GetConfig().BearerToken)488 }489 if cfg.GetConfig().Impersonate.UserName != c.expectedImpersonationUser {490 t.Fatalf("Config(%v): Expected impersonated user to be %s but got %s",491 c.request, c.expectedImpersonationUser, cfg.GetConfig().Impersonate.UserName)492 }493 if len(cfg.GetConfig().Impersonate.Extra) != 2 {494 t.Fatalf("Config(%v): Expected two impersonated extra but got %d",495 c.request, len(cfg.GetConfig().Impersonate.Extra))496 }497 if cfg.GetConfig().Impersonate.Extra["service"][0] != c.expectedImpersonationExtra["service"][0] {498 t.Fatalf("Config(%v): Expected service extra to be %s but got %s",499 c.request, cfg.GetConfig().Impersonate.Extra["service"][0], c.expectedImpersonationExtra["service"][0])500 }501 //check multi value scope502 if len(cfg.GetConfig().Impersonate.Extra["scope"]) != 2 {503 t.Fatalf("Config(%v): Expected two scope impersonated extra but got %d",504 c.request, len(cfg.GetConfig().Impersonate.Extra["scope"]))505 }506 if cfg.GetConfig().Impersonate.Extra["scope"][0] != c.expectedImpersonationExtra["scope"][0] {507 t.Fatalf("Config(%v): Expected scope extra to be %s but got %s",508 c.request, c.expectedImpersonationExtra["scope"][0], cfg.GetConfig().Impersonate.Extra["scope"][0])509 }510 if cfg.GetConfig().Impersonate.Extra["scope"][1] != c.expectedImpersonationExtra["scope"][1] {511 t.Fatalf("Config(%v): Expected scope extra to be %s but got %s",512 c.request, c.expectedImpersonationExtra["scope"][1], cfg.GetConfig().Impersonate.Extra["scope"][1])513 }514 if len(cfg.GetConfig().Impersonate.Extra["scope"]) != 2 {515 t.Fatalf("Config(%v): Expected two scope impersonated extra but got %d",516 c.request, len(cfg.GetConfig().Impersonate.Extra["scope"]))517 }518 }519}...

Full Screen

Full Screen

master.go

Source:master.go Github

copy

Full Screen

...20 return memberMaster21}22// 与主节点通信23func (m *MemberMaster) masterHandle() {24 addr := common.GetConfig().Member.MasterAddr25 if addr == "" {26 return27 }28 // 与主节点建立连接29 cli, err := core.NewTcpClient(addr)30 if err != nil {31 logger.Error("MASTER DISCONNECT:", err)32 m.MasterClient = nil33 time.Sleep(common.DelayDuration)34 m.masterHandle()35 return36 }37 defer cli.Close()38 cli.SetHandleFunc(func(h *core.TcpHandle, m *deal.Msg) {39 ss := session.GetBaseSession(h)40 if err := ss.HandleRoute(router.GetMemberRouter(), m); err != nil {41 logger.Error(err.Error())42 }43 })44 cli.SetCloseFunc(func(h *core.TcpHandle) {45 logger.Error("MASTER DISCONNECT:", err)46 m.MasterClient = nil47 time.Sleep(common.DelayDuration)48 m.masterHandle()49 return50 })51 m.MasterClient = cli52 // 发起Start通信53 m.memberStart()54 // 启动心跳55 for {56 m.memberHeart()57 time.Sleep(common.TcpHeartDuration)58 }59}60// notice master member start61func (m *MemberMaster) memberStart() {62 if m.MasterClient == nil {63 return64 }65 memberAddr, err := common.ParseAddr(common.GetConfig().Member.TcpAddr)66 if err != nil {67 logger.Fatal(err)68 }69 innerAddr, err := common.ParseAddr(common.GetConfig().Member.InnerAddr)70 if err != nil {71 logger.Fatal(err)72 }73 input := &deal.MemberStartRequest{74 Version: common.GetConfig().Base.Version,75 Port: memberAddr.Port,76 InnerPort: innerAddr.Port,77 }78 inputBys, err := common.MsgMarsh(common.GetConfig().Base.TcpDeal, input)79 if err != nil {80 logger.Error(err)81 return82 }83 msg := &deal.Msg{84 Route: "MemberStart",85 Sid: 0,86 Mid: m.MasterClient.GetMid(),87 MsgType: common.MsgTypeRequest,88 Deal: common.GetConfig().Base.TcpDeal,89 Data: inputBys,90 Version: common.GetConfig().Base.Version,91 }92 m.MasterClient.Send(msg)93}94// notice master member close95func (m *MemberMaster) memberClose() {96 if m.MasterClient == nil {97 return98 }99 input := &deal.MemberStopNotice{}100 inputBys, err := common.MsgMarsh(common.GetConfig().Base.TcpDeal, input)101 if err != nil {102 logger.Error(err)103 return104 }105 msg := &deal.Msg{106 Route: "MemberStop",107 Sid: 0,108 Mid: m.MasterClient.GetMid(),109 MsgType: common.MsgTypeNotice,110 Deal: common.GetConfig().Base.TcpDeal,111 Data: inputBys,112 Version: common.GetConfig().Base.Version,113 }114 m.MasterClient.Send(msg)115}116// heart master117func (m *MemberMaster) memberHeart() {118 if m.MasterClient == nil {119 return120 }121 input := &deal.Ping{122 Psutil: common.GetPsutil(),123 }124 inputBys, err := common.MsgMarsh(common.GetConfig().Base.TcpDeal, input)125 if err != nil {126 logger.Error(err)127 return128 }129 msg := &deal.Msg{130 Route: "MemberHeart",131 Sid: 0,132 Mid: m.MasterClient.GetMid(),133 MsgType: common.MsgTypeRequest,134 Deal: common.GetConfig().Base.TcpDeal,135 Data: inputBys,136 Version: common.GetConfig().Base.Version,137 }138 m.MasterClient.Send(msg)139 // 每次心跳是上报140 GetMemberMaster().memberInfo()141}142// 同步session143func (m *MemberMaster) memberInfo() {144 if m.MasterClient == nil {145 return146 }147 input := &deal.MemberInfoNotice{148 SessionCount: uint64(session.GetMember().SessionCount()),149 }150 inputBys, err := common.MsgMarsh(common.GetConfig().Base.TcpDeal, input)151 if err != nil {152 logger.Error(err)153 return154 }155 msg := &deal.Msg{156 Route: "MemberInfo",157 Sid: 0,158 Mid: m.MasterClient.GetMid(),159 MsgType: common.MsgTypeNotice,160 Deal: common.GetConfig().Base.TcpDeal,161 Data: inputBys,162 Version: common.GetConfig().Base.Version,163 }164 m.MasterClient.Send(msg)165}...

Full Screen

Full Screen

GetConfig

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 c, err := config.ReadDefault("config.ini")4 if err != nil {5 log.Fatal(err)6 }7 port, err := c.Int("server", "port")8 if err != nil {9 log.Fatal(err)10 }11 host, err := c.String("server", "host")12 if err != nil {13 log.Fatal(err)14 }15 fmt.Println("Host:", host)16 fmt.Println("Port:", port)17}

Full Screen

Full Screen

GetConfig

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 cli, err := clientv3.New(clientv3.Config{4 Endpoints: []string{"localhost:2379"},5 })6 if err != nil {7 panic(err)8 }9 defer cli.Close()10 ctx, cancel := context.WithTimeout(context.Background(), time.Second)11 resp, err := cli.Get(ctx, "key")12 cancel()13 if err != nil {14 panic(err)15 }16 for _, ev := range resp.Kvs {17 fmt.Printf("%s : %s18 }19}

Full Screen

Full Screen

GetConfig

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 obj := client.Client{}4 obj.GetConfig()5}6import (7type Client struct {8}9func (c Client) GetConfig() {10 fmt.Println("GetConfig method of client class")11}

Full Screen

Full Screen

GetConfig

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 client := config.Client{}4 config := client.GetConfig()5 fmt.Println("config:", config)6}7import (8func main() {9 client := config.Client{}10 config := client.GetConfig()11 fmt.Println("config:", config)12}13import (14func main() {15 client := config.Client{}16 config := client.GetConfig()17 fmt.Println("config:", config)18}19import (20func main() {21 client := config.Client{}22 config := client.GetConfig()23 fmt.Println("config:", config)24}25import (26func main() {27 client := config.Client{}28 config := client.GetConfig()29 fmt.Println("config:", config)30}31import (32func main() {33 client := config.Client{}34 config := client.GetConfig()35 fmt.Println("config:", config)36}37import (38func main() {39 client := config.Client{}40 config := client.GetConfig()41 fmt.Println("config:", config)42}43import (44func main() {45 client := config.Client{}46 config := client.GetConfig()47 fmt.Println("config:", config)48}49import (50func main() {51 client := config.Client{}52 config := client.GetConfig()

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testkube automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful