@@ -22,6 +22,7 @@ import (
22
22
23
23
"github.com/elastic/elastic-agent-libs/transport/httpcommon"
24
24
"github.com/elastic/elastic-agent-libs/transport/tlscommon"
25
+ "github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
25
26
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/artifact"
26
27
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/details"
27
28
"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
@@ -32,6 +33,7 @@ import (
32
33
"github.com/elastic/elastic-agent/pkg/control/v2/client/mocks"
33
34
"github.com/elastic/elastic-agent/pkg/control/v2/cproto"
34
35
"github.com/elastic/elastic-agent/pkg/core/logger"
36
+ agtversion "github.com/elastic/elastic-agent/pkg/version"
35
37
)
36
38
37
39
func Test_CopyFile (t * testing.T ) {
@@ -693,7 +695,7 @@ func TestIsSameVersion(t *testing.T) {
693
695
manifest : nil ,
694
696
hash : "abcdef" ,
695
697
},
696
- version : "1.2.3-repackaged- SNAPSHOT" ,
698
+ version : "1.2.3-SNAPSHOT.repackaged " ,
697
699
},
698
700
want : want {
699
701
same : false ,
@@ -903,3 +905,80 @@ func writeState(t *testing.T, path string, state details.State) {
903
905
assert .NoError (t , err , "error writing out the test upgrade marker" )
904
906
}
905
907
}
908
+
909
+ func Test_selectWatcherExecutable (t * testing.T ) {
910
+ type args struct {
911
+ previous agentInstall
912
+ current agentInstall
913
+ }
914
+ tests := []struct {
915
+ name string
916
+ args args
917
+ want string
918
+ }{
919
+ {
920
+ name : "Simple upgrade, we should launch the new (current) watcher" ,
921
+ args : args {
922
+ previous : agentInstall {
923
+ parsedVersion : agtversion .NewParsedSemVer (1 , 2 , 3 , "" , "" ),
924
+ versionedHome : filepath .Join ("data" , "elastic-agent-1.2.3-somehash" ),
925
+ },
926
+ current : agentInstall {
927
+ parsedVersion : agtversion .NewParsedSemVer (4 , 5 , 6 , "" , "" ),
928
+ versionedHome : filepath .Join ("data" , "elastic-agent-4.5.6-someotherhash" ),
929
+ },
930
+ },
931
+ want : filepath .Join ("data" , "elastic-agent-4.5.6-someotherhash" ),
932
+ },
933
+ {
934
+ name : "Simple downgrade, we should launch the currently installed (previous) watcher" ,
935
+ args : args {
936
+ previous : agentInstall {
937
+ parsedVersion : agtversion .NewParsedSemVer (4 , 5 , 6 , "" , "" ),
938
+ versionedHome : filepath .Join ("data" , "elastic-agent-4.5.6-someotherhash" ),
939
+ },
940
+ current : agentInstall {
941
+ parsedVersion : agtversion .NewParsedSemVer (1 , 2 , 3 , "" , "" ),
942
+ versionedHome : filepath .Join ("data" , "elastic-agent-1.2.3-somehash" ),
943
+ },
944
+ },
945
+ want : filepath .Join ("data" , "elastic-agent-4.5.6-someotherhash" ),
946
+ },
947
+ {
948
+ name : "Upgrade from snapshot to released version, we should launch the new (current) watcher" ,
949
+ args : args {
950
+ previous : agentInstall {
951
+ parsedVersion : agtversion .NewParsedSemVer (1 , 2 , 3 , "SNAPSHOT" , "" ),
952
+ versionedHome : filepath .Join ("data" , "elastic-agent-1.2.3-SNAPSHOT-somehash" ),
953
+ },
954
+ current : agentInstall {
955
+ parsedVersion : agtversion .NewParsedSemVer (1 , 2 , 3 , "" , "" ),
956
+ versionedHome : filepath .Join ("data" , "elastic-agent-1.2.3-someotherhash" ),
957
+ },
958
+ },
959
+ want : filepath .Join ("data" , "elastic-agent-1.2.3-someotherhash" ),
960
+ },
961
+ {
962
+ name : "Downgrade from released version to SNAPSHOT, we should launch the currently installed (previous) watcher" ,
963
+ args : args {
964
+ previous : agentInstall {
965
+ parsedVersion : agtversion .NewParsedSemVer (1 , 2 , 3 , "" , "" ),
966
+ versionedHome : filepath .Join ("data" , "elastic-agent-1.2.3-somehash" ),
967
+ },
968
+ current : agentInstall {
969
+ parsedVersion : agtversion .NewParsedSemVer (1 , 2 , 3 , "SNAPSHOT" , "" ),
970
+ versionedHome : filepath .Join ("data" , "elastic-agent-1.2.3-SNAPSHOT-someotherhash" ),
971
+ },
972
+ },
973
+
974
+ want : filepath .Join ("data" , "elastic-agent-1.2.3-somehash" ),
975
+ },
976
+ }
977
+ // Just need a top dir path. This test does not make any operation on the filesystem, so a temp dir path is as good as any
978
+ fakeTopDir := filepath .Join (t .TempDir (), "Elastic" , "Agent" )
979
+ for _ , tt := range tests {
980
+ t .Run (tt .name , func (t * testing.T ) {
981
+ assert .Equalf (t , paths .BinaryPath (filepath .Join (fakeTopDir , tt .want ), agentName ), selectWatcherExecutable (fakeTopDir , tt .args .previous , tt .args .current ), "selectWatcherExecutable(%v, %v)" , tt .args .previous , tt .args .current )
982
+ })
983
+ }
984
+ }
0 commit comments