@@ -19,6 +19,7 @@ import (
1919 "github.com/acorn-io/runtime/pkg/appdefinition"
2020 "github.com/acorn-io/runtime/pkg/client"
2121 "github.com/acorn-io/runtime/pkg/config"
22+ "github.com/acorn-io/runtime/pkg/imagesource"
2223 kclient "github.com/acorn-io/runtime/pkg/k8sclient"
2324 "github.com/acorn-io/runtime/pkg/labels"
2425 "github.com/acorn-io/runtime/pkg/run"
@@ -1698,3 +1699,55 @@ func TestAutoUpgradeImageValidation(t *testing.T) {
16981699 }
16991700 assert .ErrorContains (t , err , "could not find local image for myimage:latest - if you are trying to use a remote image, specify the full registry" )
17001701}
1702+
1703+ func TestAutoUpgradeLocalImage (t * testing.T ) {
1704+ ctx := helper .GetCTX (t )
1705+
1706+ helper .StartController (t )
1707+ restConfig , err := restconfig .New (scheme .Scheme )
1708+ if err != nil {
1709+ t .Fatal ("error while getting rest config:" , err )
1710+ }
1711+ kclient := helper .MustReturn (kclient .Default )
1712+ project := helper .TempProject (t , kclient )
1713+
1714+ c , err := client .New (restConfig , project .Name , project .Name )
1715+ if err != nil {
1716+ t .Fatal (err )
1717+ }
1718+
1719+ // Attempt to run an auto-upgrade app with a non-existent local image. Should get an error.
1720+ _ , err = c .AppRun (ctx , "mylocalimage" , & client.AppRunOptions {
1721+ AutoUpgrade : & []bool {true }[0 ],
1722+ })
1723+ if err == nil {
1724+ t .Fatalf ("expected to get a not found error, instead got %v" , err )
1725+ }
1726+ assert .ErrorContains (t , err , "could not find local image for mylocalimage - if you are trying to use a remote image, specify the full registry" )
1727+
1728+ // Next, build the local image
1729+ image , err := c .AcornImageBuild (ctx , "./testdata/named/Acornfile" , & client.AcornImageBuildOptions {})
1730+ if err != nil {
1731+ t .Fatal (err )
1732+ }
1733+
1734+ // Tag the image
1735+ err = c .ImageTag (ctx , image .ID , "mylocalimage" )
1736+ if err != nil {
1737+ t .Fatal (err )
1738+ }
1739+
1740+ // Deploy the app
1741+ imageSource := imagesource .NewImageSource ("" , []string {"mylocalimage" }, []string {}, nil , true )
1742+ appImage , _ , err := imageSource .GetImageAndDeployArgs (ctx , c )
1743+ if err != nil {
1744+ t .Fatal (err )
1745+ }
1746+
1747+ _ , err = c .AppRun (ctx , appImage , & client.AppRunOptions {
1748+ AutoUpgrade : & []bool {true }[0 ],
1749+ })
1750+ if err != nil {
1751+ t .Fatal (err )
1752+ }
1753+ }
0 commit comments