package cd.casic.server;

import cd.casic.ci.process.engine.executor.PipelineExecutor;
import cd.casic.ci.process.enums.PiplineTriggerModeEnum;
import cd.casic.ci.process.process.service.pipeline.PipelineService;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

@SpringBootTest(classes = {OpsServerApplication.class})
@ActiveProfiles("local")
public class PipelineExecuteTest {
    @Resource
    PipelineExecutor pipelineExecutor;
    @Resource
    PipelineService pipelineService;
    // 执行pipeline
    @Test
    public void executePipeline(){
        pipelineExecutor.execute("716299522803896320", PiplineTriggerModeEnum.HAND,false);
    }
    // 获取pipeline执行状态
    @Test
    public void getRunState(){
        pipelineService.getPipelineRunState("716299522803896320");
    }
    @Test
    public void taskSkipExecute(){
        // 这个流水线包含了故意报错的worker，可以验证跳过效果
        pipelineExecutor.execute("718104543308681216",PiplineTriggerModeEnum.HAND,false);
    }
    @Test
    public void taskSkipGetState(){
        // 这个流水线包含了故意报错的worker，可以验证跳过效果
        pipelineService.getPipelineRunState("718104543308681216");
    }
    @Test
    public void fromError(){
        // 这个流水线包含了故意报错的worker，可以验证跳过效果
        // 传false 就是从头执行，传false就是跳过正确的节点从错误处执行
        pipelineExecutor.execute("718104543308681216",PiplineTriggerModeEnum.HAND,false);
        pipelineExecutor.execute("718104543308681216",PiplineTriggerModeEnum.HAND,true);
    }
}
