-
Notifications
You must be signed in to change notification settings - Fork 589
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- remove rke2/k3s keys so data only has required info for rke1 - decide kdm url based on the tag version
- Loading branch information
1 parent
0ea51f9
commit e1f3686
Showing
3 changed files
with
107 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 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 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,66 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/rancher/rke/metadata" | ||
) | ||
|
||
func TestGetURL(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
envVar string | ||
tag string | ||
expectedURL string | ||
}{ | ||
{ | ||
name: "No Metadata URL and TAG is release version", | ||
envVar: "", | ||
tag: "v1.0.0", | ||
expectedURL: defaultReleaseURL, | ||
}, | ||
{ | ||
name: "No Metadata URL and TAG is pre-release version", | ||
envVar: "", | ||
tag: "v1.0.0-alpha", | ||
expectedURL: defaultDevURL, | ||
}, | ||
{ | ||
name: "Metadata URL set", | ||
envVar: "https://example.com", | ||
tag: "v1.0.0", | ||
expectedURL: "https://example.com", | ||
}, | ||
{ | ||
name: "Invalid TAG", | ||
envVar: "", | ||
tag: "invalid-tag", | ||
expectedURL: defaultDevURL, | ||
}, | ||
{ | ||
name: "No TAG", | ||
envVar: "", | ||
tag: "", | ||
expectedURL: defaultDevURL, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
// Set the environment variables | ||
os.Setenv(metadata.RancherMetadataURLEnv, tt.envVar) | ||
os.Setenv("TAG", tt.tag) | ||
defer func() { | ||
os.Unsetenv(metadata.RancherMetadataURLEnv) | ||
os.Unsetenv("TAG") | ||
}() | ||
|
||
result := getURL() | ||
|
||
if result != tt.expectedURL { | ||
t.Errorf("expected %s, got %s", tt.expectedURL, result) | ||
} | ||
}) | ||
} | ||
} |