MCPcopy Create free account
hub / github.com/coder/coder / TestAIGatewayCompatibilityAliases

Function TestAIGatewayCompatibilityAliases

codersdk/deployment_test.go:574–720  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

572}
573
574func TestAIGatewayCompatibilityAliases(t *testing.T) {
575 t.Parallel()
576
577 options := (&codersdk.DeploymentValues{}).Options()
578 byFlag := map[string]serpent.Option{}
579 for _, opt := range options {
580 if opt.Flag != "" {
581 byFlag[opt.Flag] = opt
582 }
583 }
584
585 type alias struct {
586 old serpent.Option
587 new serpent.Option
588 }
589 var aliases []alias
590 for _, opt := range options {
591 if !strings.HasPrefix(opt.Flag, "aibridge-") {
592 continue
593 }
594 require.True(t, strings.HasPrefix(opt.Description, "Deprecated:"), "aibridge option %s should have a 'Deprecated:' description", opt.Flag)
595 require.Len(t, opt.UseInstead, 1, "aibridge option %s should point to a single replacement", opt.Flag)
596
597 newOpt, ok := byFlag[opt.UseInstead[0].Flag]
598 require.True(t, ok, "aibridge option %s points to unknown flag %s", opt.Flag, opt.UseInstead[0].Flag)
599 require.NotEqual(t, opt.Flag, newOpt.Flag, "flag %s shares its flag with the new alias option", opt.Flag)
600 require.NotEqual(t, opt.Env, newOpt.Env, "flag %s shares its env with the new alias option", opt.Flag)
601 if oldYAML := opt.YAMLPath(); oldYAML != "" {
602 require.NotEqual(t, oldYAML, newOpt.YAMLPath(), "flag %s shares its YAML path with the new alias option", opt.Flag)
603 } else {
604 require.Empty(t, newOpt.YAMLPath(), "flag %s has no YAML path but the new alias option %s does", opt.Flag, newOpt.Flag)
605 }
606 aliases = append(aliases, alias{old: opt, new: newOpt})
607 }
608 // Update this count when adding or removing aibridge alias options.
609 require.Len(t, aliases, 34, "unexpected number of aibridge alias options")
610
611 sampleVal := func(opt serpent.Option) any {
612 switch opt.Value.Type() {
613 case "bool":
614 return opt.Default != "true"
615 case "int":
616 return 7
617 case "duration":
618 return "2h"
619 case "string-array":
620 return []string{"10.0.0.0/8", "172.16.0.0/12"}
621 default:
622 return "alias-value"
623 }
624 }
625 sampleArg := func(opt serpent.Option) string {
626 v := sampleVal(opt)
627 if arr, ok := v.([]string); ok {
628 return strings.Join(arr, ",")
629 }
630 return fmt.Sprint(v)
631 }

Callers

nothing calls this directly

Calls 12

OptionsMethod · 0.95
setPathFunction · 0.85
NotEmptyMethod · 0.80
EncodeMethod · 0.80
TypeMethod · 0.65
HelperMethod · 0.65
RunMethod · 0.65
ParseMethod · 0.65
parseFunction · 0.50
LenMethod · 0.45
EmptyMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected