@@ -4,9 +4,11 @@ import (
44 "testing"
55
66 "github.com/stretchr/testify/assert"
7+ "k8s.io/utils/ptr"
78
89 "github.com/openmcp-project/bootstrapper/internal/config"
910 "github.com/openmcp-project/bootstrapper/internal/flux_deployer"
11+ ocm_cli "github.com/openmcp-project/bootstrapper/internal/ocm-cli"
1012)
1113
1214func TestNewTemplateInputFromConfig (t * testing.T ) {
@@ -31,3 +33,30 @@ func TestNewTemplateInputFromConfig(t *testing.T) {
3133 assert .Equal (t , "test-branch" , ti ["git" ].(map [string ]interface {})["mainBranch" ], "git mainBranch does not match" )
3234 assert .Equal (t , "test-branch" , ti ["gitRepoEnvBranch" ], "gitRepoEnvBranch does not match" )
3335}
36+
37+ func TestTemplateInput_AddImageResource (t * testing.T ) {
38+ cv := & ocm_cli.ComponentVersion {
39+ Component : ocm_cli.Component {
40+ Resources : []ocm_cli.Resource {
41+ {
42+ Name : "test-resource" ,
43+ Access : ocm_cli.Access {
44+ ImageReference : ptr .To ("test-image:v1.0.0@sha256:123456789abcdef" ),
45+ },
46+ },
47+ },
48+ },
49+ }
50+
51+ ti := flux_deployer.TemplateInput {}
52+ err := ti .AddImageResource (cv , "test-resource" , "testKey" )
53+ assert .NoError (t , err , "Expected no error adding image resource" )
54+ images , ok := ti ["images" ].(map [string ]any )
55+ assert .True (t , ok , "Expected images to be a map" )
56+ imageInfo , ok := images ["testKey" ].(map [string ]any )
57+ assert .True (t , ok , "Expected imageInfo to be a map" )
58+ assert .Equal (t , "test-image" , imageInfo ["image" ], "Image name does not match" )
59+ assert .Equal (t , "v1.0.0" , imageInfo ["tag" ], "Image tag does not match" )
60+ assert .Equal (t , "v1.0.0" , imageInfo ["version" ], "Image version does not match" )
61+ assert .Equal (t , "sha256:123456789abcdef" , imageInfo ["digest" ], "Image digest does not match" )
62+ }
0 commit comments