Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions Runtime/Model/JsonData/Annotations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,18 @@ public class Annotations
/// </summary>
internal static Dictionary<string, string> _environmentVariablesCache;

/// <summary>
/// Determinate if static helper should load environment variables or not.
/// </summary>
internal static bool VariablesLoaded;

/// <summary>
/// Loaded environment variables
/// </summary>
public static Dictionary<string, string> EnvironmentVariablesCache
{
get
{
if (VariablesLoaded == false)
{
_environmentVariablesCache = SetEnvironmentVariables();
VariablesLoaded = true;
}
return _environmentVariablesCache;
}
set
{
_environmentVariablesCache = value;
_environmentVariablesCache = SetEnvironmentVariables(_environmentVariablesCache);
}
}

Expand Down Expand Up @@ -78,10 +68,9 @@ public Annotations(Exception exception, int gameObjectDepth)
Exception = exception;
}

private static Dictionary<string, string> SetEnvironmentVariables()
private static Dictionary<string, string> SetEnvironmentVariables(IDictionary environmentVariables)
{
var result = new Dictionary<string, string>();
var environmentVariables = Environment.GetEnvironmentVariables();
if (environmentVariables == null)
{
return result;
Expand All @@ -104,7 +93,10 @@ private static Dictionary<string, string> SetEnvironmentVariables()
public BacktraceJObject ToJson()
{
var annotations = new BacktraceJObject();
annotations.Add("Environment Variables", new BacktraceJObject(EnvironmentVariables));
if (EnvironmentVariables != null)
{
annotations.Add("Environment Variables", new BacktraceJObject(EnvironmentVariables));
}

if (Exception != null)
{
Expand Down Expand Up @@ -203,4 +195,4 @@ private BacktraceJObject GetJObject(Component gameObject, string parentName = ""
});
}
}
}
}
7 changes: 6 additions & 1 deletion Tests/Runtime/ClientSendTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using NUnit.Framework;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.TestTools;

Expand All @@ -29,7 +31,7 @@ public void Setup()
public void Cleanup()
{
client.RequestHandler = null;
Annotations.VariablesLoaded = false;
Annotations.EnvironmentVariablesCache = null;
}

[UnityTest]
Expand Down Expand Up @@ -108,6 +110,9 @@ public IEnumerator PiiTests_ShouldModifyEnvironmentVariable_IntegrationShouldUse

var environmentVariableKey = "foo";
var expectedValue = "bar";
Annotations.EnvironmentVariablesCache = Environment.GetEnvironmentVariables()
.Cast<DictionaryEntry>()
.ToDictionary(entry => (string)entry.Key, entry => entry.Value as string);
Annotations.EnvironmentVariablesCache[environmentVariableKey] = expectedValue;

client.BeforeSend = (BacktraceData data) =>
Expand Down
Loading