createTmpConfigInFileSystem creates a random observability config at a random place in the temporary portion of the file system dependent on system. It also sets the environment variable GRPC_CONFIG_OBSERVABILITY_JSON to point to this created config.
(rawJSON string)
| 234 | // also sets the environment variable GRPC_CONFIG_OBSERVABILITY_JSON to point to |
| 235 | // this created config. |
| 236 | func createTmpConfigInFileSystem(rawJSON string) (func(), error) { |
| 237 | configJSONFile, err := os.CreateTemp(os.TempDir(), "configJSON-") |
| 238 | if err != nil { |
| 239 | return nil, fmt.Errorf("cannot create file %v: %v", configJSONFile.Name(), err) |
| 240 | } |
| 241 | _, err = configJSONFile.Write(json.RawMessage(rawJSON)) |
| 242 | if err != nil { |
| 243 | return nil, fmt.Errorf("cannot write marshalled JSON: %v", err) |
| 244 | } |
| 245 | oldObservabilityConfigFile := envconfig.ObservabilityConfigFile |
| 246 | envconfig.ObservabilityConfigFile = configJSONFile.Name() |
| 247 | return func() { |
| 248 | configJSONFile.Close() |
| 249 | envconfig.ObservabilityConfigFile = oldObservabilityConfigFile |
| 250 | }, nil |
| 251 | } |
| 252 | |
| 253 | // TestJSONEnvVarSet tests a valid observability configuration specified by the |
| 254 | // GRPC_CONFIG_OBSERVABILITY_JSON environment variable, whose value represents a |
no test coverage detected