Skip to content

Commit 7a55d35

Browse files
authored
Merge pull request #126 from unsignedapps/keith/fvd-safety
Remove dangerous FlagValueDictionary functionality
2 parents d0caf39 + 55fa5de commit 7a55d35

File tree

5 files changed

+27
-88
lines changed

5 files changed

+27
-88
lines changed

Sources/Vexil/Sources/FlagValueDictionary+Collection.swift

Lines changed: 0 additions & 67 deletions
This file was deleted.

Sources/Vexil/Sources/FlagValueDictionary.swift

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ public final class FlagValueDictionary: Identifiable, ExpressibleByDictionaryLit
7070
})
7171
}
7272

73+
// MARK: - Dictionary Access
74+
75+
/// Returns a copy of the current values in this source
76+
var allValues: DictionaryType {
77+
storage.withLock { $0 }
78+
}
79+
7380
// MARK: - Codable Support
7481

7582
enum CodingKeys: String, CodingKey {
@@ -90,13 +97,3 @@ public final class FlagValueDictionary: Identifiable, ExpressibleByDictionaryLit
9097
}
9198

9299
}
93-
94-
// MARK: - Equatable Support
95-
96-
extension FlagValueDictionary: Equatable {
97-
public static func == (lhs: FlagValueDictionary, rhs: FlagValueDictionary) -> Bool {
98-
let left = lhs.storage.withLock { $0 }
99-
let right = rhs.storage.withLock { $0 }
100-
return lhs.id == rhs.id && left == right
101-
}
102-
}

Sources/Vexil/Vexil.docc/Sources.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The Vexil `FlagPole` supports multiple backend flag sources, and ships with the
1010
|------|-------------|
1111
| `UserDefaults` | Any `UserDefaults` instance automatically conforms to ``FlagValueSource`` |
1212
| `NSUbiquitousKeyValueStore` | Any `NSUbiquitousKeyValueStore` instance automatically conforms to ``FlagValueSource`` |
13-
| ``FlagValueDictionary`` | A dictionary-style type that conforms to `Collection` that is great for testing or other integrations. |
13+
| ``FlagValueDictionary`` | A wrapper for a simple dictionary that is great for testing or other integrations. |
1414
| ``Snapshot`` | All snapshots taken of a FlagPole can be used as a source. |
1515

1616
## Initialisation

Tests/VexilTests/FlagValueDictionaryTests.swift

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ struct FlagValueDictionaryTests {
5656
snapshot.oneFlagGroup.secondLevelFlag = false
5757
try flagPole.save(snapshot: snapshot, to: source)
5858

59-
#expect(source["top-level-flag"] == .bool(true))
60-
#expect(source["one-flag-group.second-level-flag"] == .bool(false))
59+
let allValues = source.allValues
60+
#expect(allValues["top-level-flag"] == .bool(true))
61+
#expect(allValues["one-flag-group.second-level-flag"] == .bool(false))
6162
}
6263

6364
// MARK: - Equatable Tests
@@ -94,9 +95,14 @@ struct FlagValueDictionaryTests {
9495
]
9596
)
9697

97-
#expect(original == same)
98-
#expect(original != differentContent)
99-
#expect(original != differentIdentifier)
98+
let originalValues = original.allValues
99+
let sameValues = same.allValues
100+
let differentContentValues = differentContent.allValues
101+
let differentIdentifierValues = differentIdentifier.allValues
102+
#expect(originalValues == sameValues)
103+
#expect(originalValues != differentContentValues)
104+
#expect(originalValues == differentIdentifierValues)
105+
#expect(original.id != differentIdentifier.id)
100106

101107
}
102108

@@ -114,7 +120,8 @@ struct FlagValueDictionaryTests {
114120
let encoded = try JSONEncoder().encode(source)
115121
let decoded = try JSONDecoder().decode(FlagValueDictionary.self, from: encoded)
116122

117-
#expect(source == decoded)
123+
#expect(source.allValues == decoded.allValues)
124+
#expect(source.id == decoded.id)
118125
}
119126

120127

Tests/VexilTests/FlagValueSourceTests.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,10 @@ struct FlagValueSourceTests {
9696
try pole.copyFlagValues(from: source, to: destination)
9797

9898
// THEN we expect those two dictionaries to match
99-
#expect(destination.count == 2)
100-
#expect(destination["test-flag"] == .bool(true))
101-
#expect(destination["subgroup.test-flag"] == .bool(true))
99+
let destinationValues = destination.allValues
100+
#expect(destinationValues.count == 2)
101+
#expect(destinationValues["test-flag"] == .bool(true))
102+
#expect(destinationValues["subgroup.test-flag"] == .bool(true))
102103

103104
}
104105

@@ -116,7 +117,8 @@ struct FlagValueSourceTests {
116117
try pole.removeFlagValues(in: source)
117118

118119
// THEN the source should now be empty
119-
#expect(source.isEmpty)
120+
let sourceValues = source.allValues
121+
#expect(sourceValues.isEmpty)
120122

121123
}
122124

0 commit comments

Comments
 (0)