@@ -23,12 +23,14 @@ import (
23
23
"strings"
24
24
"testing"
25
25
26
+ "github.com/pkg/errors"
26
27
v1 "k8s.io/api/core/v1"
27
28
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28
29
"k8s.io/client-go/kubernetes"
29
30
"k8s.io/client-go/kubernetes/fake"
30
31
31
32
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build"
33
+ "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/jib"
32
34
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/filemon"
33
35
pkgkubernetes "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes"
34
36
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
@@ -37,6 +39,7 @@ import (
37
39
)
38
40
39
41
func TestNewSyncItem (t * testing.T ) {
42
+ ctx := context .Background ()
40
43
tests := []struct {
41
44
description string
42
45
artifact * latest.Artifact
@@ -677,14 +680,48 @@ func TestNewSyncItem(t *testing.T) {
677
680
Delete : map [string ][]string {},
678
681
},
679
682
},
683
+
684
+ // Auto with Jib
685
+ {
686
+ description : "auto with jib" ,
687
+ artifact : & latest.Artifact {
688
+ ImageName : "test" ,
689
+ Workspace : "." ,
690
+ Sync : & latest.Sync {
691
+ Auto : & latest.Auto {},
692
+ },
693
+ ArtifactType : latest.ArtifactType {
694
+ JibArtifact : & latest.JibArtifact {},
695
+ },
696
+ },
697
+ evt : filemon.Events {
698
+ Added : []string {"this actually doesn't matter" },
699
+ },
700
+ builds : []build.Artifact {
701
+ {
702
+ ImageName : "test" ,
703
+ Tag : "test:123" ,
704
+ },
705
+ },
706
+ expected : & Item {
707
+ Image : "test:123" ,
708
+ Copy : map [string ][]string {
709
+ "file.class" : {"/some/file.class" },
710
+ },
711
+ Delete : nil ,
712
+ },
713
+ },
680
714
}
681
715
for _ , test := range tests {
682
716
testutil .Run (t , test .description , func (t * testutil.T ) {
683
717
t .Override (& WorkingDir , func (string , map [string ]bool ) (string , error ) { return test .workingDir , nil })
684
718
t .Override (& SyncMap , func (* latest.Artifact , map [string ]bool ) (map [string ][]string , error ) { return test .dependencies , nil })
685
719
t .Override (& Labels , func (string , map [string ]bool ) (map [string ]string , error ) { return test .labels , nil })
720
+ t .Override (& jib .GetSyncDiff , func (context.Context , string , * latest.JibArtifact , filemon.Events ) (map [string ][]string , map [string ][]string , error ) {
721
+ return map [string ][]string {"file.class" : {"/some/file.class" }}, nil , nil
722
+ })
686
723
687
- actual , err := NewItem (test .artifact , test .evt , test .builds , nil )
724
+ actual , err := NewItem (ctx , test .artifact , test .evt , test .builds , nil )
688
725
689
726
t .CheckErrorAndDeepEqual (test .shouldErr , err , test .expected , actual )
690
727
})
@@ -947,3 +984,58 @@ func TestSyncMap(t *testing.T) {
947
984
})
948
985
}
949
986
}
987
+
988
+ func TestInit (t * testing.T ) {
989
+ ctx := context .Background ()
990
+ tests := []struct {
991
+ description string
992
+ artifact * latest.Artifact
993
+ shouldInit bool
994
+ initErrors bool
995
+ }{
996
+ {
997
+ description : "sync off" ,
998
+ artifact : & latest.Artifact {},
999
+ shouldInit : false ,
1000
+ },
1001
+ {
1002
+ description : "sync on, auto off" ,
1003
+ artifact : & latest.Artifact {Sync : & latest.Sync {}},
1004
+ shouldInit : false ,
1005
+ },
1006
+ {
1007
+ description : "sync on, auto on, non-jib" ,
1008
+ artifact : & latest.Artifact {Sync : & latest.Sync {Auto : & latest.Auto {}}},
1009
+ shouldInit : false ,
1010
+ },
1011
+ {
1012
+ description : "sync on, auto on, jib" ,
1013
+ artifact : & latest.Artifact {ArtifactType : latest.ArtifactType {JibArtifact : & latest.JibArtifact {}}, Sync : & latest.Sync {Auto : & latest.Auto {}}},
1014
+ shouldInit : true ,
1015
+ initErrors : false ,
1016
+ },
1017
+ {
1018
+ description : "sync on, auto on, jib, init fails" ,
1019
+ artifact : & latest.Artifact {ArtifactType : latest.ArtifactType {JibArtifact : & latest.JibArtifact {}}, Sync : & latest.Sync {Auto : & latest.Auto {}}},
1020
+ shouldInit : true ,
1021
+ initErrors : true ,
1022
+ },
1023
+ }
1024
+ for _ , test := range tests {
1025
+ testutil .Run (t , test .description , func (t * testutil.T ) {
1026
+ isCalled := false
1027
+ t .Override (& jib .InitSync , func (ctx context.Context , workspace string , a * latest.JibArtifact ) error {
1028
+ isCalled = true
1029
+ if test .initErrors {
1030
+ return errors .New ("intentional test failure" )
1031
+ }
1032
+ return nil
1033
+ })
1034
+
1035
+ artifacts := []* latest.Artifact {test .artifact }
1036
+ err := Init (ctx , artifacts )
1037
+ t .CheckDeepEqual (test .shouldInit , isCalled )
1038
+ t .CheckError (test .initErrors , err )
1039
+ })
1040
+ }
1041
+ }
0 commit comments