| 29 | ) |
| 30 | |
| 31 | func TestCoreOptions_Flags(t *testing.T) { |
| 32 | fs := pflag.NewFlagSet("test", pflag.ContinueOnError) |
| 33 | opt := &CoreOptions{ |
| 34 | ControllerArgs: &oamcontroller.Args{}, |
| 35 | } |
| 36 | |
| 37 | for _, f := range opt.Flags().FlagSets { |
| 38 | fs.AddFlagSet(f) |
| 39 | } |
| 40 | |
| 41 | args := []string{ |
| 42 | "--application-re-sync-period=5s", |
| 43 | "--cluster-metrics-interval=5s", |
| 44 | "--enable-cluster-gateway=true", |
| 45 | "--enable-cluster-metrics=true", |
| 46 | "--enable-leader-election=true", |
| 47 | "--health-addr=/healthz", |
| 48 | "--informer-sync-period=3s", |
| 49 | "--kube-api-burst=500", |
| 50 | "--kube-api-qps=200", |
| 51 | "--leader-election-lease-duration=3s", |
| 52 | "--leader-election-namespace=test-namespace", |
| 53 | "--leader-election-renew-deadline=5s", |
| 54 | "--leader-election-retry-period=3s", |
| 55 | "--log-debug=true", |
| 56 | "--log-file-max-size=50", |
| 57 | "--log-file-path=/path/to/log", |
| 58 | "--max-dispatch-concurrent=5", |
| 59 | "--max-workflow-failed-backoff-time=30", |
| 60 | "--max-workflow-step-error-retry-times=5", |
| 61 | "--max-workflow-wait-backoff-time=5", |
| 62 | "--metrics-addr=/metrics", |
| 63 | "--perf-enabled=true", |
| 64 | "--use-webhook=true", |
| 65 | "--webhook-cert-dir=/path/to/cert", |
| 66 | "--webhook-port=8080", |
| 67 | } |
| 68 | |
| 69 | if err := fs.Parse(args); err != nil { |
| 70 | t.Errorf("Failed to parse args: %v", err) |
| 71 | } |
| 72 | |
| 73 | expected := &CoreOptions{ |
| 74 | UseWebhook: true, |
| 75 | CertDir: "/path/to/cert", |
| 76 | WebhookPort: 8080, |
| 77 | MetricsAddr: "/metrics", |
| 78 | EnableLeaderElection: true, |
| 79 | LeaderElectionNamespace: "test-namespace", |
| 80 | LogFilePath: "/path/to/log", |
| 81 | LogFileMaxSize: 50, |
| 82 | LogDebug: true, |
| 83 | ControllerArgs: &oamcontroller.Args{}, |
| 84 | HealthAddr: "/healthz", |
| 85 | StorageDriver: "", |
| 86 | InformerSyncPeriod: 3 * time.Second, |
| 87 | QPS: 200, |
| 88 | Burst: 500, |