-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
add: Support multiple version numbers pattern #11
- Loading branch information
Showing
5 changed files
with
178 additions
and
97 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package docker | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/joho/godotenv" | ||
) | ||
|
||
type testEcrEnv struct { | ||
host string | ||
image string | ||
tag string | ||
} | ||
|
||
var ecrenv = testEcrEnv{} | ||
|
||
func init() { | ||
if err := godotenv.Load("../../.env"); err != nil { | ||
fmt.Printf("error loading .env file - %s", err) | ||
} | ||
|
||
ecrenv.host = os.Getenv("TEST_DOCKER_ECR_HOST") | ||
ecrenv.image = os.Getenv("TEST_DOCKER_ECR_IMAGE") | ||
ecrenv.tag = os.Getenv("TEST_DOCKER_ECR_TAG") | ||
} | ||
|
||
func TestGetImageFromECR(t *testing.T) { | ||
|
||
if os.Getenv("TEST_DOCKER_ECR_SKIP") != "" { | ||
t.Log("skipping test") | ||
return | ||
} | ||
|
||
r := NewRemoteRegistry() | ||
|
||
if ecrenv.host == "" || ecrenv.image == "" || ecrenv.tag == "" { | ||
t.Fatalf("env not set") | ||
} | ||
|
||
if s, err := r.GetImageString(ecrenv.host+"/"+ecrenv.image, ecrenv.tag, "linux/amd64"); err != nil { | ||
t.Fatalf("err: %v, %+v", err, ecrenv) | ||
} else { | ||
t.Logf("success: %s", s) | ||
} | ||
} |
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,61 @@ | ||
package docker | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/google/go-containerregistry/pkg/authn" | ||
"github.com/joho/godotenv" | ||
) | ||
|
||
type testPrivateEnv struct { | ||
host string | ||
image string | ||
tag string | ||
auth string | ||
username string | ||
password string | ||
} | ||
|
||
var privateenv = testPrivateEnv{} | ||
|
||
func init() { | ||
if err := godotenv.Load("../../.env"); err != nil { | ||
fmt.Printf("error loading .env file - %s", err) | ||
} | ||
|
||
privateenv.host = os.Getenv("TEST_DOCKER_PRIVATE_HOST") | ||
privateenv.image = os.Getenv("TEST_DOCKER_PRIVATE_IMAGE") | ||
privateenv.tag = os.Getenv("TEST_DOCKER_PRIVATE_TAG") | ||
privateenv.auth = os.Getenv("TEST_DOCKER_PRIVATE_AUTH") | ||
privateenv.username = os.Getenv("TEST_DOCKER_PRIVATE_USERNAME") | ||
privateenv.password = os.Getenv("TEST_DOCKER_PRIVATE_PASSWORD") | ||
} | ||
|
||
func TestGetImageFromPrivateRegistry(t *testing.T) { | ||
if os.Getenv("TEST_DOCKER_PRIVATE_SKIP") != "" { | ||
t.Log("skipping test") | ||
return | ||
} | ||
|
||
r := NewRemoteRegistry() | ||
|
||
if privateenv.auth != "" { | ||
r.WithImageAuthMap(map[string]authn.Authenticator{ | ||
privateenv.host: NewPrivateAuthenticatorWithAuth(privateenv.host, privateenv.auth), | ||
}) | ||
} else if privateenv.username != "" && privateenv.password != "" { | ||
r.WithImageAuthMap(map[string]authn.Authenticator{ | ||
privateenv.host: NewPrivateAuthenticator(privateenv.host, privateenv.username, privateenv.password), | ||
}) | ||
} else { | ||
t.Fatalf("env not set") | ||
} | ||
|
||
if s, err := r.GetImageString(privateenv.host+"/"+privateenv.image, privateenv.tag, "linux/amd64"); err != nil { | ||
t.Fatalf("err: %v", err) | ||
} else { | ||
t.Logf("success: %s", s) | ||
} | ||
} |
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,39 @@ | ||
package util | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
var versions []string = []string{"v1.0.0", "v1.0.1", "v1.0.2", "v1.0.9", "v1.0.10", "v1.0.11", "v2.0.99", "v2.0.9", "v3.1.999", "v3.1.998", "v4.0.999", "v4.1.0", "v5.0.0", "v6.0.0", "v6.0.1.0"} | ||
|
||
func TestGetHighestVersionWithFilter(t *testing.T) { | ||
if highestVersion, _ := GetHighestVersionWithFilter(versions, "v1.0.*"); highestVersion != "v1.0.11" { | ||
t.Errorf("Expected: v1.0.11, Got: %s", highestVersion) | ||
} | ||
|
||
if highestVersion, _ := GetHighestVersionWithFilter(versions, "v2.0.*"); highestVersion != "v2.0.99" { | ||
t.Errorf("Expected: v2.0.99, Got: %s", highestVersion) | ||
} | ||
|
||
if highestVersion, _ := GetHighestVersionWithFilter(versions, "v3.1.*"); highestVersion != "v3.1.999" { | ||
t.Errorf("Expected: v3.1.999, Got: %s", highestVersion) | ||
} | ||
} | ||
|
||
func TestGetHighestVersionWithFilterSingleVersion(t *testing.T) { | ||
if highestVersion, _ := GetHighestVersionWithFilter(versions, "v5.*.*"); highestVersion != "v5.0.0" { | ||
t.Errorf("Expected: v5.0.0, Got: %s", highestVersion) | ||
} | ||
} | ||
|
||
func TestGetHighestVersionWithFilterMultipleAsterisk(t *testing.T) { | ||
if highestVersion, _ := GetHighestVersionWithFilter(versions, "v4.*.*"); highestVersion != "v4.1.0" { | ||
t.Errorf("Expected: v4.1.0, Got: %s", highestVersion) | ||
} | ||
} | ||
|
||
func TestGetHighestVersionWithFilterAsteriskNotMatch(t *testing.T) { | ||
if highestVersion, _ := GetHighestVersionWithFilter(versions, "v6.*.*"); highestVersion != "v6.0.0" { | ||
t.Errorf("Expected: v6.0.0, Got: %s", highestVersion) | ||
} | ||
} |