Skip to content

Add version compatibility test #6197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

RanVaknin
Copy link
Contributor

Generating build time testing for internal consumers that might consume mixed versions of sdk-core and services.
The PR has two main additions:

  • an addition of a constant value to every service's package under ServiceVersionInfo.VERSION.
  • a compatibility test that will fail the assertion if there is a difference between sdk-core and the service version.

@RanVaknin RanVaknin requested a review from a team as a code owner June 19, 2025 20:48
@RanVaknin RanVaknin force-pushed the rvaknin/add-version-compatibility-test branch from 1ea5897 to 8093298 Compare June 20, 2025 23:15
@RanVaknin RanVaknin force-pushed the rvaknin/add-version-compatibility-test branch from 8093298 to f90abc1 Compare June 23, 2025 20:22
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
23.6% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think generating a fixture test for a code generated test might be overkill, but for better readability here is what this generated test would look like for SQS:

/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
 * the License. A copy of the License is located at
 * 
 * http://aws.amazon.com/apache2.0
 * 
 * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
 * and limitations under the License.
 */

package software.amazon.awssdk.services.sqs;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.core.util.VersionInfo;
import software.amazon.awssdk.services.sqs.internal.ServiceVersionInfo;

@Generated("software.amazon.awssdk:codegen")
public class VersionCompatibilityTest {
    @Test
    public void checkCompatibility() {
        String coreVersion = VersionInfo.SDK_VERSION;
        String serviceVersion = ServiceVersionInfo.VERSION;
        Assertions
                .assertThat(isVersionCompatible(coreVersion, serviceVersion))
                .withFailMessage("Core version %s must be equal to or newer than service version %s", coreVersion, serviceVersion)
                .isTrue();
    }

    private boolean isVersionCompatible(String coreVersion, String serviceVersion) {
        String normalizedCore = coreVersion.replace("-SNAPSHOT", "");
        String normalizedService = serviceVersion.replace("-SNAPSHOT", "");
        String[] coreParts = normalizedCore.split("\\.");
        String[] serviceParts = normalizedService.split("\\.");

        int coreMajor = Integer.parseInt(coreParts[0]);
        int serviceMajor = Integer.parseInt(serviceParts[0]);
        if (coreMajor != serviceMajor) {
            return coreMajor >= serviceMajor;
        }

        int coreMinor = Integer.parseInt(coreParts[1]);
        int serviceMinor = Integer.parseInt(serviceParts[1]);
        if (coreMinor != serviceMinor) {
            return coreMinor >= serviceMinor;
        }

        int corePatch = Integer.parseInt(coreParts[2]);
        int servicePatch = Integer.parseInt(serviceParts[2]);
        return corePatch >= servicePatch;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant