Skip to content

Commit 9046560

Browse files
authored
fix: Fix generation of tags capability tests (#290)
1 parent fdad240 commit 9046560

File tree

3 files changed

+35
-29
lines changed

3 files changed

+35
-29
lines changed

sdktests/common_tests_instance_id.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ func (c CommonInstanceIDTests) Run(t *ldtest.T) {
4242
verifyRequestHeader(t, dataSource.Endpoint())
4343
})
4444

45-
t.Run("poll requests", func(t *ldtest.T) {
46-
t.Capabilities().HasAny(servicedef.CapabilityServerSidePolling, servicedef.CapabilityClientSide)
47-
48-
dataSource := NewSDKDataSource(t, nil, DataSourceOptionPolling())
49-
_ = NewSDKClient(t, c.baseSDKConfigurationPlus(dataSource)...)
50-
verifyRequestHeader(t, dataSource.Endpoint())
51-
})
45+
if t.Capabilities().HasAny(servicedef.CapabilityClientSide, servicedef.CapabilityServerSidePolling) {
46+
t.Run("poll requests", func(t *ldtest.T) {
47+
dataSource := NewSDKDataSource(t, nil, DataSourceOptionPolling())
48+
_ = NewSDKClient(t, c.baseSDKConfigurationPlus(dataSource)...)
49+
verifyRequestHeader(t, dataSource.Endpoint())
50+
})
51+
}
5252

5353
t.Run("event posts", func(t *ldtest.T) {
5454
dataSource := NewSDKDataSource(t, nil)

sdktests/common_tests_tags.go

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,20 @@ func (c CommonTagsTests) Run(t *ldtest.T) {
7272
}
7373
})
7474

75-
t.Run("poll requests", func(t *ldtest.T) {
76-
// Currently server-side SDK test services do not support polling
77-
t.RequireCapability(servicedef.CapabilityClientSide)
78-
79-
for _, p := range c.makeValidTagsTestParams() {
80-
t.Run(p.description, func(t *ldtest.T) {
81-
tags := p.tags
82-
dataSource := NewSDKDataSource(t, nil, DataSourceOptionPolling())
83-
_ = NewSDKClient(t, c.baseSDKConfigurationPlus(
84-
withTagsConfig(tags),
85-
dataSource)...)
86-
verifyRequestHeader(t, p, dataSource.Endpoint())
87-
})
88-
}
89-
})
75+
if t.Capabilities().HasAny(servicedef.CapabilityClientSide, servicedef.CapabilityServerSidePolling) {
76+
t.Run("poll requests", func(t *ldtest.T) {
77+
for _, p := range c.makeValidTagsTestParams() {
78+
t.Run(p.description, func(t *ldtest.T) {
79+
tags := p.tags
80+
dataSource := NewSDKDataSource(t, nil, DataSourceOptionPolling())
81+
_ = NewSDKClient(t, c.baseSDKConfigurationPlus(
82+
withTagsConfig(tags),
83+
dataSource)...)
84+
verifyRequestHeader(t, p, dataSource.Endpoint())
85+
})
86+
}
87+
})
88+
}
9089

9190
t.Run("event posts", func(t *ldtest.T) {
9291
dataSource := NewSDKDataSource(t, nil)
@@ -207,10 +206,20 @@ func (c CommonTagsTests) makeValidTagsTestParams() []tagsTestParams {
207206
o.None[string](),
208207
o.Some(""), // empty string
209208
}
210-
for i := 0; i < len(allAllowedTagChars); i += maxTagValueLength {
211-
j := h.IfElse(i > len(allAllowedTagChars), len(allAllowedTagChars), i)
212-
values = append(values, o.Some(allAllowedTagChars[i:j]))
209+
210+
// Generate test to use all valid characters
211+
batchSize := min(maxTagValueLength, len(allAllowedTagChars))
212+
for i := 0; i < len(allAllowedTagChars)-batchSize; i += batchSize {
213+
if i+batchSize > len(allAllowedTagChars) {
214+
values = append(values, o.Some(allAllowedTagChars[i:]))
215+
} else {
216+
values = append(values, o.Some(allAllowedTagChars[i:i+batchSize]))
217+
}
213218
}
219+
220+
// Ensure we test the maximum length
221+
values = append(values, o.Some(strings.Repeat(allAllowedTagChars[1:2], maxTagValueLength)))
222+
214223
for _, appID := range values {
215224
for _, appVersion := range values {
216225
tags := servicedef.SDKConfigTagsParams{ApplicationID: appID, ApplicationVersion: appVersion}

sdktests/constants.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package sdktests
22

33
const (
4-
// Application tags sent to the cloud are not allowed to have spaces. However, the SDKs
5-
// are sanitizing input, so spaces are allowed in the input. That is why this set
6-
// of characters includes a space.
7-
allAllowedTagChars = " ._-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
4+
allAllowedTagChars = "._-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
85
tagNameAppID = "application-id"
96
tagNameAppVersion = "application-version"
107
)

0 commit comments

Comments
 (0)