-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: define constants for test images (#7739)
Signed-off-by: knqyf263 <[email protected]> Co-authored-by: DmitriyLewen <[email protected]>
- Loading branch information
1 parent
83e5b83
commit bcfc37b
Showing
9 changed files
with
104 additions
and
30 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,3 @@ | ||
# Configuration file for both shell scripts and Go programs | ||
TEST_IMAGES=ghcr.io/aquasecurity/trivy-test-images | ||
TEST_VM_IMAGES=ghcr.io/aquasecurity/trivy-test-vm-images |
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,67 @@ | ||
package testutil | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
"strings" | ||
) | ||
|
||
var ( | ||
testImages string | ||
testVMImages string | ||
) | ||
|
||
func init() { | ||
_, b, _, _ := runtime.Caller(0) | ||
currentDir := filepath.Dir(b) | ||
f, err := os.Open(filepath.Join(currentDir, "..", "..", "integration", "testimages.ini")) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer f.Close() | ||
|
||
scanner := bufio.NewScanner(f) | ||
for scanner.Scan() { | ||
if strings.HasPrefix(scanner.Text(), "#") { | ||
continue | ||
} | ||
parts := strings.SplitN(scanner.Text(), "=", 2) | ||
if len(parts) == 2 { | ||
key := strings.TrimSpace(parts[0]) | ||
value := strings.TrimSpace(parts[1]) | ||
switch key { | ||
case "TEST_IMAGES": | ||
testImages = value | ||
case "TEST_VM_IMAGES": | ||
testVMImages = value | ||
} | ||
} | ||
} | ||
if err = scanner.Err(); err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func ImageName(subpath, tag, digest string) string { | ||
return imageName(testImages, subpath, tag, digest) | ||
} | ||
|
||
func VMImageName(subpath, tag, digest string) string { | ||
return imageName(testVMImages, subpath, tag, digest) | ||
} | ||
|
||
func imageName(img, subpath, tag, digest string) string { | ||
if subpath != "" { | ||
img = fmt.Sprintf("%s/%s", img, subpath) | ||
} | ||
if tag != "" { | ||
img = fmt.Sprintf("%s:%s", img, tag) | ||
} | ||
if digest != "" { | ||
img = fmt.Sprintf("%s@%s", img, digest) | ||
} | ||
return img | ||
} |
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
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