@@ -552,6 +552,59 @@ sleep 10
552
552
So (provider .DataSize (), ShouldBeEmpty )
553
553
})
554
554
})
555
+ Convey ("Command Provider with successExitCodes should work" , t , func (ctx C ) {
556
+ tmpDir , err := os .MkdirTemp ("" , "tunasync" )
557
+ defer os .RemoveAll (tmpDir )
558
+ So (err , ShouldBeNil )
559
+ scriptFile := filepath .Join (tmpDir , "cmd.sh" )
560
+ tmpFile := filepath .Join (tmpDir , "log_file" )
561
+
562
+ c := cmdConfig {
563
+ name : "tuna-cmd" ,
564
+ upstreamURL : "http://mirrors.tuna.moe/" ,
565
+ command : "bash " + scriptFile ,
566
+ workingDir : tmpDir ,
567
+ logDir : tmpDir ,
568
+ logFile : tmpFile ,
569
+ interval : 600 * time .Second ,
570
+ }
571
+
572
+ provider , err := newCmdProvider (c )
573
+ provider .SetSuccessExitCodes ([]int {199 , 200 })
574
+ So (err , ShouldBeNil )
575
+
576
+ So (provider .Type (), ShouldEqual , provCommand )
577
+ So (provider .Name (), ShouldEqual , c .name )
578
+ So (provider .WorkingDir (), ShouldEqual , c .workingDir )
579
+ So (provider .LogDir (), ShouldEqual , c .logDir )
580
+ So (provider .LogFile (), ShouldEqual , c .logFile )
581
+ So (provider .Interval (), ShouldEqual , c .interval )
582
+ So (provider .GetSuccessExitCodes (), ShouldResemble , []int {199 , 200 })
583
+
584
+ Convey ("Command exits with configured successExitCodes" , func () {
585
+ scriptContent := `exit 199`
586
+ err = os .WriteFile (scriptFile , []byte (scriptContent ), 0755 )
587
+ So (err , ShouldBeNil )
588
+ readedScriptContent , err := os .ReadFile (scriptFile )
589
+ So (err , ShouldBeNil )
590
+ So (readedScriptContent , ShouldResemble , []byte (scriptContent ))
591
+
592
+ err = provider .Run (make (chan empty , 1 ))
593
+ So (err , ShouldBeNil )
594
+ })
595
+
596
+ Convey ("Command exits with unknown exit code" , func () {
597
+ scriptContent := `exit 201`
598
+ err = os .WriteFile (scriptFile , []byte (scriptContent ), 0755 )
599
+ So (err , ShouldBeNil )
600
+ readedScriptContent , err := os .ReadFile (scriptFile )
601
+ So (err , ShouldBeNil )
602
+ So (readedScriptContent , ShouldResemble , []byte (scriptContent ))
603
+
604
+ err = provider .Run (make (chan empty , 1 ))
605
+ So (err , ShouldNotBeNil )
606
+ })
607
+ })
555
608
}
556
609
557
610
func TestTwoStageRsyncProvider (t * testing.T ) {
0 commit comments