(t *testing.T)
| 543 | } |
| 544 | |
| 545 | func TestSingleOriginServices(t *testing.T) { |
| 546 | host := "://localhost:8080" |
| 547 | httpURL := urlMustParse("http" + host) |
| 548 | tcpURL := urlMustParse("tcp" + host) |
| 549 | unix := "unix://service" |
| 550 | newCli := func(params ...string) *cli.Context { |
| 551 | flagSet := flag.NewFlagSet(t.Name(), flag.PanicOnError) |
| 552 | flagSet.Bool("hello-world", false, "") |
| 553 | flagSet.Bool("bastion", false, "") |
| 554 | flagSet.String("url", "", "") |
| 555 | flagSet.String("unix-socket", "", "") |
| 556 | cliCtx := cli.NewContext(cli.NewApp(), flagSet, nil) |
| 557 | for i := 0; i < len(params); i += 2 { |
| 558 | cliCtx.Set(params[i], params[i+1]) |
| 559 | } |
| 560 | |
| 561 | return cliCtx |
| 562 | } |
| 563 | |
| 564 | tests := []struct { |
| 565 | name string |
| 566 | cli *cli.Context |
| 567 | expectedService OriginService |
| 568 | err error |
| 569 | }{ |
| 570 | { |
| 571 | name: "Valid hello-world", |
| 572 | cli: newCli("hello-world", "true"), |
| 573 | expectedService: &helloWorld{}, |
| 574 | }, |
| 575 | { |
| 576 | name: "Valid bastion", |
| 577 | cli: newCli("bastion", "true"), |
| 578 | expectedService: newBastionService(), |
| 579 | }, |
| 580 | { |
| 581 | name: "Valid http url", |
| 582 | cli: newCli("url", httpURL.String()), |
| 583 | expectedService: &httpService{url: httpURL}, |
| 584 | }, |
| 585 | { |
| 586 | name: "Valid tcp url", |
| 587 | cli: newCli("url", tcpURL.String()), |
| 588 | expectedService: newTCPOverWSService(tcpURL), |
| 589 | }, |
| 590 | { |
| 591 | name: "Valid unix-socket", |
| 592 | cli: newCli("unix-socket", unix), |
| 593 | expectedService: &unixSocketPath{path: unix, scheme: "http"}, |
| 594 | }, |
| 595 | { |
| 596 | name: "No origins defined", |
| 597 | cli: newCli(), |
| 598 | err: ErrNoIngressRulesCLI, |
| 599 | }, |
| 600 | } |
| 601 | for _, test := range tests { |
| 602 | t.Run(test.name, func(t *testing.T) { |
nothing calls this directly
no test coverage detected