-
Notifications
You must be signed in to change notification settings - Fork 169
OCPBUGS-109670: Derive documentationBaseURL dynamically from OPERATOR_IMAGE_VERSION #1209
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
platex-rehor-bot
wants to merge
4
commits into
openshift:main
Choose a base branch
from
platex-rehor-bot:bot/OCPBUGS-109670
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f225f44
OCPBUGS-109670: Derive documentationBaseURL dynamically from OPERATOR…
platex-rehor-bot 6c981fb
fix(configmap): validate major.minor are decimal in version parser
platex-rehor-bot 5d79d12
test(configmap): assert exact URL in TestDefaultDocURL
platex-rehor-bot cc9568d
test(configmap): guard TestDefaultDocURL with !ocp build tag
platex-rehor-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package configmap | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strconv" | ||
| "strings" | ||
| ) | ||
|
|
||
| const ocpDocURLFormat = "https://access.redhat.com/documentation/en-us/openshift_container_platform/%s/" | ||
|
|
||
| // formatOCPDocURL returns the OCP documentation base URL for the given version. | ||
| // Extracts major.minor from version (e.g., "5.0.3" → "5.0"). Falls back to | ||
| // "latest" when the version is empty or cannot be parsed. | ||
| func formatOCPDocURL(version string) string { | ||
| return fmt.Sprintf(ocpDocURLFormat, extractMajorMinor(version)) | ||
| } | ||
|
|
||
| // extractMajorMinor extracts the major.minor portion from a version string. | ||
| // Returns "latest" if the version is empty, does not contain a dot separator, | ||
| // or if the major/minor components are not valid decimal numbers. | ||
| func extractMajorMinor(version string) string { | ||
| if version == "" { | ||
| return "latest" | ||
| } | ||
| parts := strings.SplitN(version, ".", 3) | ||
| if len(parts) < 2 { | ||
| return "latest" | ||
| } | ||
| major := parts[0] | ||
| minor := parts[1] | ||
| if _, err := strconv.Atoi(major); err != nil { | ||
| return "latest" | ||
| } | ||
| if _, err := strconv.Atoi(minor); err != nil { | ||
| return "latest" | ||
| } | ||
| return major + "." + minor | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| package configmap | ||
|
|
||
| import "testing" | ||
|
|
||
| func TestFormatOCPDocURL(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| version string | ||
| want string | ||
| }{ | ||
| { | ||
| name: "full release version", | ||
| version: "5.0.3", | ||
| want: "https://access.redhat.com/documentation/en-us/openshift_container_platform/5.0/", | ||
| }, | ||
| { | ||
| name: "two-part version", | ||
| version: "4.21", | ||
| want: "https://access.redhat.com/documentation/en-us/openshift_container_platform/4.21/", | ||
| }, | ||
| { | ||
| name: "nightly pre-release version", | ||
| version: "5.1.0-0.nightly-2026-01-01-000000", | ||
| want: "https://access.redhat.com/documentation/en-us/openshift_container_platform/5.1/", | ||
| }, | ||
| { | ||
| name: "rc version", | ||
| version: "4.19.0-rc.1", | ||
| want: "https://access.redhat.com/documentation/en-us/openshift_container_platform/4.19/", | ||
| }, | ||
| { | ||
| name: "empty version falls back to latest", | ||
| version: "", | ||
| want: "https://access.redhat.com/documentation/en-us/openshift_container_platform/latest/", | ||
| }, | ||
| { | ||
| name: "single number without dot falls back to latest", | ||
| version: "5", | ||
| want: "https://access.redhat.com/documentation/en-us/openshift_container_platform/latest/", | ||
| }, | ||
| { | ||
| name: "non-numeric dotted version falls back to latest", | ||
| version: "invalid.version", | ||
| want: "https://access.redhat.com/documentation/en-us/openshift_container_platform/latest/", | ||
| }, | ||
| { | ||
| name: "trailing dot falls back to latest", | ||
| version: "5.", | ||
| want: "https://access.redhat.com/documentation/en-us/openshift_container_platform/latest/", | ||
| }, | ||
| { | ||
| name: "non-numeric minor falls back to latest", | ||
| version: "5.x", | ||
| want: "https://access.redhat.com/documentation/en-us/openshift_container_platform/latest/", | ||
| }, | ||
| { | ||
| name: "leading dot falls back to latest", | ||
| version: ".5", | ||
| want: "https://access.redhat.com/documentation/en-us/openshift_container_platform/latest/", | ||
| }, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got := formatOCPDocURL(tt.version) | ||
| if got != tt.want { | ||
| t.Errorf("formatOCPDocURL(%q) = %q, want %q", tt.version, got, tt.want) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestExtractMajorMinor(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| version string | ||
| want string | ||
| }{ | ||
| { | ||
| name: "standard three-part version", | ||
| version: "5.0.3", | ||
| want: "5.0", | ||
| }, | ||
| { | ||
| name: "two-part version", | ||
| version: "4.21", | ||
| want: "4.21", | ||
| }, | ||
| { | ||
| name: "nightly build version", | ||
| version: "5.1.0-0.nightly-2026-01-01-000000", | ||
| want: "5.1", | ||
| }, | ||
| { | ||
| name: "release candidate", | ||
| version: "4.19.0-rc.1", | ||
| want: "4.19", | ||
| }, | ||
| { | ||
| name: "empty string", | ||
| version: "", | ||
| want: "latest", | ||
| }, | ||
| { | ||
| name: "single number without dot", | ||
| version: "5", | ||
| want: "latest", | ||
| }, | ||
| { | ||
| name: "non-numeric dotted version", | ||
| version: "invalid.version", | ||
| want: "latest", | ||
| }, | ||
| { | ||
| name: "trailing dot with empty minor", | ||
| version: "5.", | ||
| want: "latest", | ||
| }, | ||
| { | ||
| name: "non-numeric minor component", | ||
| version: "5.x", | ||
| want: "latest", | ||
| }, | ||
| { | ||
| name: "leading dot with empty major", | ||
| version: ".5", | ||
| want: "latest", | ||
| }, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got := extractMajorMinor(tt.version) | ||
| if got != tt.want { | ||
| t.Errorf("extractMajorMinor(%q) = %q, want %q", tt.version, got, tt.want) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestDefaultDocURL(t *testing.T) { | ||
| // Tests run without -tags ocp, so DefaultDocURL uses the OKD | ||
| // implementation which returns the static DEFAULT_DOC_URL constant. | ||
| // The OCP code path (OPERATOR_IMAGE_VERSION → formatOCPDocURL) is | ||
| // covered by TestFormatOCPDocURL and TestExtractMajorMinor above. | ||
| t.Run("returns expected OKD documentation URL", func(t *testing.T) { | ||
| got := DefaultDocURL() | ||
| if got != DEFAULT_DOC_URL { | ||
| t.Errorf("DefaultDocURL() = %q, want %q", got, DEFAULT_DOC_URL) | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| } | ||
| }) | ||
| t.Run("OPERATOR_IMAGE_VERSION does not affect OKD build", func(t *testing.T) { | ||
| t.Setenv("OPERATOR_IMAGE_VERSION", "5.0.3") | ||
| got := DefaultDocURL() | ||
| if got != DEFAULT_DOC_URL { | ||
| t.Errorf("DefaultDocURL() = %q, want %q (env should not affect OKD)", got, DEFAULT_DOC_URL) | ||
| } | ||
| }) | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.