Skip to content

Commit

Permalink
fix go vet 'composite literals with unkeyed fields'
Browse files Browse the repository at this point in the history
Fix go vet 'composite literals with unkeyed fields' issue
by applying `gopls fix -a -w <file.go>` and some reformatting
the structure initialization to be multiline with multiple fields.
Part of the fix for #3481.

Reference: golang/go#53062
Signed-off-by: Dmitry S <[email protected]>
  • Loading branch information
dmitris committed Feb 15, 2024
1 parent 902d262 commit 5f05f8b
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 36 deletions.
4 changes: 2 additions & 2 deletions amp/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func ReadPolicy(ampParams Params, pbsConfigGDPREnabled bool) (privacy.PolicyWrit
warningMsg = validateTCf2ConsentString(ampParams.Consent)
}
case ConsentUSPrivacy:
rv = ccpa.ConsentWriter{ampParams.Consent}
rv = ccpa.ConsentWriter{Consent: ampParams.Consent}
if ccpa.ValidateConsent(ampParams.Consent) {
if parseGdprApplies(ampParams.GdprApplies) == 1 {
// Log warning because AMP request comes with both a valid CCPA string and gdpr_applies set to true
Expand All @@ -85,7 +85,7 @@ func ReadPolicy(ampParams Params, pbsConfigGDPREnabled bool) (privacy.PolicyWrit
}
default:
if ccpa.ValidateConsent(ampParams.Consent) {
rv = ccpa.ConsentWriter{ampParams.Consent}
rv = ccpa.ConsentWriter{Consent: ampParams.Consent}
if parseGdprApplies(ampParams.GdprApplies) == 1 {
warningMsg = "AMP request gdpr_applies value was ignored because provided consent string is a CCPA consent string"
}
Expand Down
124 changes: 90 additions & 34 deletions amp/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func TestPrivacyReader(t *testing.T) {
ampParams: Params{Consent: "1YYY"},
},
expected: expectedResults{
policyWriter: ccpa.ConsentWriter{"1YYY"},
policyWriter: ccpa.ConsentWriter{Consent: "1YYY"},
warning: nil,
},
},
Expand All @@ -294,7 +294,7 @@ func TestPrivacyReader(t *testing.T) {
ampParams: Params{Consent: "1YYY", GdprApplies: &boolTrue},
},
expected: expectedResults{
policyWriter: ccpa.ConsentWriter{"1YYY"},
policyWriter: ccpa.ConsentWriter{Consent: "1YYY"},
warning: &errortypes.Warning{Message: "AMP request gdpr_applies value was ignored because provided consent string is a CCPA consent string", WarningCode: errortypes.InvalidPrivacyConsentWarningCode},
},
},
Expand All @@ -304,8 +304,11 @@ func TestPrivacyReader(t *testing.T) {
ampParams: Params{Consent: "CPdiPIJPdiPIJACABBENAzCv_____3___wAAAQNd_X9cAAAAAAAA"},
},
expected: expectedResults{
policyWriter: gdpr.ConsentWriter{"CPdiPIJPdiPIJACABBENAzCv_____3___wAAAQNd_X9cAAAAAAAA", &int8One},
warning: nil,
policyWriter: gdpr.ConsentWriter{
Consent: "CPdiPIJPdiPIJACABBENAzCv_____3___wAAAQNd_X9cAAAAAAAA",
RegExtGDPR: &int8One,
},
warning: nil,
},
},
},
Expand All @@ -329,7 +332,7 @@ func TestPrivacyReader(t *testing.T) {
ampParams: Params{ConsentType: 101, Consent: "1YYY"},
},
expected: expectedResults{
policyWriter: ccpa.ConsentWriter{"1YYY"},
policyWriter: ccpa.ConsentWriter{Consent: "1YYY"},
warning: nil,
},
},
Expand All @@ -339,7 +342,7 @@ func TestPrivacyReader(t *testing.T) {
ampParams: Params{ConsentType: 101, Consent: "1YYY", GdprApplies: &boolTrue},
},
expected: expectedResults{
policyWriter: ccpa.ConsentWriter{"1YYY"},
policyWriter: ccpa.ConsentWriter{Consent: "1YYY"},
warning: &errortypes.Warning{Message: "AMP request gdpr_applies value was ignored because provided consent string is a CCPA consent string", WarningCode: errortypes.InvalidPrivacyConsentWarningCode},
},
},
Expand All @@ -349,8 +352,11 @@ func TestPrivacyReader(t *testing.T) {
ampParams: Params{ConsentType: 101, Consent: "CPdiPIJPdiPIJACABBENAzCv_____3___wAAAQNd_X9cAAAAAAAA"},
},
expected: expectedResults{
policyWriter: gdpr.ConsentWriter{"CPdiPIJPdiPIJACABBENAzCv_____3___wAAAQNd_X9cAAAAAAAA", &int8One},
warning: nil,
policyWriter: gdpr.ConsentWriter{
Consent: "CPdiPIJPdiPIJACABBENAzCv_____3___wAAAQNd_X9cAAAAAAAA",
RegExtGDPR: &int8One,
},
warning: nil,
},
},
},
Expand All @@ -364,48 +370,83 @@ func TestPrivacyReader(t *testing.T) {
ampParams: Params{Consent: "INVALID_GDPR", ConsentType: ConsentTCF2, GdprApplies: nil},
},
expected: expectedResults{
policyWriter: gdpr.ConsentWriter{"INVALID_GDPR", &int8One},
warning: &errortypes.Warning{Message: "Consent string 'INVALID_GDPR' is not a valid TCF2 consent string.", WarningCode: errortypes.InvalidPrivacyConsentWarningCode},
policyWriter: gdpr.ConsentWriter{
Consent: "INVALID_GDPR",
RegExtGDPR: &int8One,
},
warning: &errortypes.Warning{
Message: "Consent string 'INVALID_GDPR' is not a valid TCF2 consent string.",
WarningCode: errortypes.InvalidPrivacyConsentWarningCode,
},
},
},
{
desc: "GDPR consent string is invalid, consent type is TCF2, gdpr_applies is set to true: return a valid GDPR writer and warn about the GDPR string being invalid",
in: testInput{
ampParams: Params{Consent: "INVALID_GDPR", ConsentType: ConsentTCF2, GdprApplies: &boolFalse},
ampParams: Params{
Consent: "INVALID_GDPR",
ConsentType: ConsentTCF2,
GdprApplies: &boolFalse,
},
},
expected: expectedResults{
policyWriter: gdpr.ConsentWriter{"INVALID_GDPR", &int8Zero},
warning: &errortypes.Warning{Message: "Consent string 'INVALID_GDPR' is not a valid TCF2 consent string.", WarningCode: errortypes.InvalidPrivacyConsentWarningCode},
policyWriter: gdpr.ConsentWriter{
Consent: "INVALID_GDPR",
RegExtGDPR: &int8Zero,
},
warning: &errortypes.Warning{
Message: "Consent string 'INVALID_GDPR' is not a valid TCF2 consent string.",
WarningCode: errortypes.InvalidPrivacyConsentWarningCode,
},
},
},
{
desc: "Valid GDPR consent string, gdpr_applies is set to false, return a valid GDPR writer, no warning",
in: testInput{
ampParams: Params{Consent: "CPdiPIJPdiPIJACABBENAzCv_____3___wAAAQNd_X9cAAAAAAAA", ConsentType: ConsentTCF2, GdprApplies: &boolFalse},
ampParams: Params{
Consent: "CPdiPIJPdiPIJACABBENAzCv_____3___wAAAQNd_X9cAAAAAAAA",
ConsentType: ConsentTCF2, GdprApplies: &boolFalse,
},
},
expected: expectedResults{
policyWriter: gdpr.ConsentWriter{"CPdiPIJPdiPIJACABBENAzCv_____3___wAAAQNd_X9cAAAAAAAA", &int8Zero},
warning: nil,
policyWriter: gdpr.ConsentWriter{
Consent: "CPdiPIJPdiPIJACABBENAzCv_____3___wAAAQNd_X9cAAAAAAAA",
RegExtGDPR: &int8Zero,
},
warning: nil,
},
},
{
desc: "Valid GDPR consent string, gdpr_applies is set to true, return a valid GDPR writer and no warning",
in: testInput{
ampParams: Params{Consent: "CPdiPIJPdiPIJACABBENAzCv_____3___wAAAQNd_X9cAAAAAAAA", ConsentType: ConsentTCF2, GdprApplies: &boolTrue},
ampParams: Params{
Consent: "CPdiPIJPdiPIJACABBENAzCv_____3___wAAAQNd_X9cAAAAAAAA",
ConsentType: ConsentTCF2,
GdprApplies: &boolTrue,
},
},
expected: expectedResults{
policyWriter: gdpr.ConsentWriter{"CPdiPIJPdiPIJACABBENAzCv_____3___wAAAQNd_X9cAAAAAAAA", &int8One},
warning: nil,
policyWriter: gdpr.ConsentWriter{
Consent: "CPdiPIJPdiPIJACABBENAzCv_____3___wAAAQNd_X9cAAAAAAAA",
RegExtGDPR: &int8One,
},
warning: nil,
},
},
{
desc: "Valid GDPR consent string, return a valid GDPR writer and no warning",
in: testInput{
ampParams: Params{Consent: "CPdiPIJPdiPIJACABBENAzCv_____3___wAAAQNd_X9cAAAAAAAA", ConsentType: ConsentTCF2},
ampParams: Params{
Consent: "CPdiPIJPdiPIJACABBENAzCv_____3___wAAAQNd_X9cAAAAAAAA",
ConsentType: ConsentTCF2,
},
},
expected: expectedResults{
policyWriter: gdpr.ConsentWriter{"CPdiPIJPdiPIJACABBENAzCv_____3___wAAAQNd_X9cAAAAAAAA", &int8One},
warning: nil,
policyWriter: gdpr.ConsentWriter{
Consent: "CPdiPIJPdiPIJACABBENAzCv_____3___wAAAQNd_X9cAAAAAAAA",
RegExtGDPR: &int8One,
},
warning: nil,
},
},
},
Expand All @@ -419,7 +460,7 @@ func TestPrivacyReader(t *testing.T) {
ampParams: Params{Consent: "XXXX", ConsentType: ConsentUSPrivacy},
},
expected: expectedResults{
policyWriter: ccpa.ConsentWriter{"XXXX"},
policyWriter: ccpa.ConsentWriter{Consent: "XXXX"},
warning: &errortypes.Warning{Message: "Consent string 'XXXX' is not a valid CCPA consent string.", WarningCode: errortypes.InvalidPrivacyConsentWarningCode},
},
},
Expand All @@ -429,7 +470,7 @@ func TestPrivacyReader(t *testing.T) {
ampParams: Params{Consent: "1YYY", ConsentType: ConsentUSPrivacy, GdprApplies: &boolTrue},
},
expected: expectedResults{
policyWriter: ccpa.ConsentWriter{"1YYY"},
policyWriter: ccpa.ConsentWriter{Consent: "1YYY"},
warning: &errortypes.Warning{Message: "AMP request gdpr_applies value was ignored because provided consent string is a CCPA consent string", WarningCode: errortypes.InvalidPrivacyConsentWarningCode},
},
},
Expand All @@ -439,7 +480,7 @@ func TestPrivacyReader(t *testing.T) {
ampParams: Params{Consent: "1YYY", ConsentType: ConsentUSPrivacy},
},
expected: expectedResults{
policyWriter: ccpa.ConsentWriter{"1YYY"},
policyWriter: ccpa.ConsentWriter{Consent: "1YYY"},
warning: nil,
},
},
Expand Down Expand Up @@ -469,19 +510,34 @@ func TestBuildGdprTCF2ConsentWriter(t *testing.T) {
expectedWriter gdpr.ConsentWriter
}{
{
desc: "gdpr_applies not set",
inParams: Params{Consent: consentString},
expectedWriter: gdpr.ConsentWriter{consentString, &int8One},
desc: "gdpr_applies not set",
inParams: Params{Consent: consentString},
expectedWriter: gdpr.ConsentWriter{
Consent: consentString,
RegExtGDPR: &int8One,
},
},
{
desc: "gdpr_applies set to false",
inParams: Params{Consent: consentString, GdprApplies: &boolFalse},
expectedWriter: gdpr.ConsentWriter{consentString, &int8Zero},
desc: "gdpr_applies set to false",
inParams: Params{
Consent: consentString,
GdprApplies: &boolFalse,
},
expectedWriter: gdpr.ConsentWriter{
Consent: consentString,
RegExtGDPR: &int8Zero,
},
},
{
desc: "gdpr_applies set to true",
inParams: Params{Consent: consentString, GdprApplies: &boolTrue},
expectedWriter: gdpr.ConsentWriter{consentString, &int8One},
desc: "gdpr_applies set to true",
inParams: Params{
Consent: consentString,
GdprApplies: &boolTrue,
},
expectedWriter: gdpr.ConsentWriter{
Consent: consentString,
RegExtGDPR: &int8One,
},
},
}
for _, tc := range testCases {
Expand Down

0 comments on commit 5f05f8b

Please sign in to comment.