MCPcopy
hub / github.com/grpc/grpc-go / createTmpConfigInFileSystem

Function createTmpConfigInFileSystem

gcp/observability/observability_test.go:236–251  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

234// also sets the environment variable GRPC_CONFIG_OBSERVABILITY_JSON to point to
235// this created config.
236func 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

Callers 3

TestJSONEnvVarSetMethod · 0.85

Calls 4

ErrorfMethod · 0.65
NameMethod · 0.65
WriteMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected