(t testing.TB, cfg *Config, pcResources int)
| 880 | } |
| 881 | |
| 882 | func createWebhook(t testing.TB, cfg *Config, pcResources int) *Webhook { |
| 883 | t.Helper() |
| 884 | dir := t.TempDir() |
| 885 | |
| 886 | configBytes, err := yaml.Marshal(cfg) |
| 887 | if err != nil { |
| 888 | t.Fatalf("Could not marshal test injection config: %v", err) |
| 889 | } |
| 890 | _, values, _ := getInjectionSettings(t, nil, "") |
| 891 | var ( |
| 892 | configFile = filepath.Join(dir, "config-file.yaml") |
| 893 | valuesFile = filepath.Join(dir, "values-file.yaml") |
| 894 | port = 0 |
| 895 | ) |
| 896 | |
| 897 | if err := os.WriteFile(configFile, configBytes, 0o644); err != nil { // nolint: vetshadow |
| 898 | t.Fatalf("WriteFile(%v) failed: %v", configFile, err) |
| 899 | } |
| 900 | |
| 901 | if err := os.WriteFile(valuesFile, []byte(values.raw), 0o644); err != nil { // nolint: vetshadow |
| 902 | t.Fatalf("WriteFile(%v) failed: %v", valuesFile, err) |
| 903 | } |
| 904 | |
| 905 | // mesh config |
| 906 | m := mesh.DefaultMeshConfig() |
| 907 | store := model.NewFakeStore() |
| 908 | for i := 0; i < pcResources; i++ { |
| 909 | store.Create(newProxyConfig(fmt.Sprintf("pc-%d", i), "istio-system", &v1beta12.ProxyConfig{ |
| 910 | Concurrency: &wrapperspb.Int32Value{Value: int32(i % 5)}, |
| 911 | EnvironmentVariables: map[string]string{ |
| 912 | fmt.Sprintf("VAR_%d", i): fmt.Sprint(i), |
| 913 | }, |
| 914 | })) |
| 915 | } |
| 916 | pcs := model.GetProxyConfigs(store, m) |
| 917 | env := model.Environment{ |
| 918 | Watcher: meshwatcher.NewTestWatcher(m), |
| 919 | ConfigStore: store, |
| 920 | } |
| 921 | env.SetPushContext(&model.PushContext{ |
| 922 | ProxyConfigs: pcs, |
| 923 | }) |
| 924 | watcher, err := NewFileWatcher(configFile, valuesFile) |
| 925 | if err != nil { |
| 926 | t.Fatalf("NewFileWatcher() failed: %v", err) |
| 927 | } |
| 928 | |
| 929 | wh, err := NewWebhook(WebhookParameters{ |
| 930 | Watcher: watcher, |
| 931 | Port: port, |
| 932 | Env: &env, |
| 933 | Mux: http.NewServeMux(), |
| 934 | MultiCluster: multicluster.NewFakeController(), |
| 935 | }) |
| 936 | if err != nil { |
| 937 | t.Fatalf("NewWebhook() failed: %v", err) |
| 938 | } |
| 939 | return wh |
no test coverage detected
searching dependent graphs…