TestRefreshStopTimeBehavior tests that the refreshStopTime flag controls stop time preservation
(t *testing.T)
| 164 | |
| 165 | // TestRefreshStopTimeBehavior tests that the refreshStopTime flag controls stop time preservation |
| 166 | func TestRefreshStopTimeBehavior(t *testing.T) { |
| 167 | // Create a temporary directory for test files |
| 168 | tmpDir, err := os.MkdirTemp("", "refresh-stop-time-test") |
| 169 | if err != nil { |
| 170 | t.Fatalf("Failed to create temp dir: %v", err) |
| 171 | } |
| 172 | defer os.RemoveAll(tmpDir) |
| 173 | |
| 174 | // Create a markdown workflow file with stop-after |
| 175 | mdFile := filepath.Join(tmpDir, "test.md") |
| 176 | lockFile := filepath.Join(tmpDir, "test.lock.yml") |
| 177 | |
| 178 | // Create a lock file with existing stop time |
| 179 | existingStopTime := "2025-12-31 23:59:59" |
| 180 | lockContent := fmt.Sprintf(`name: Test Workflow |
| 181 | on: |
| 182 | workflow_dispatch: |
| 183 | jobs: |
| 184 | stop_time_check: |
| 185 | runs-on: ubuntu-latest |
| 186 | steps: |
| 187 | - uses: actions/github-script`+"@v8\n"+` env: |
| 188 | GH_AW_STOP_TIME: %s |
| 189 | GH_AW_WORKFLOW_NAME: "Test Workflow" |
| 190 | `, existingStopTime) |
| 191 | err = os.WriteFile(lockFile, []byte(lockContent), 0644) |
| 192 | if err != nil { |
| 193 | t.Fatalf("Failed to create lock file: %v", err) |
| 194 | } |
| 195 | |
| 196 | // Test 1: Default behavior should preserve existing stop time |
| 197 | t.Run("default behavior preserves stop time", func(t *testing.T) { |
| 198 | compiler := NewCompiler() |
| 199 | compiler.SetRefreshStopTime(false) |
| 200 | |
| 201 | frontmatter := map[string]any{ |
| 202 | "on": map[string]any{ |
| 203 | "workflow_dispatch": nil, |
| 204 | "stop-after": "+48h", |
| 205 | }, |
| 206 | } |
| 207 | |
| 208 | workflowData := &WorkflowData{} |
| 209 | err := compiler.processStopAfterConfiguration(frontmatter, workflowData, mdFile) |
| 210 | if err != nil { |
| 211 | t.Fatalf("processStopAfterConfiguration failed: %v", err) |
| 212 | } |
| 213 | |
| 214 | if workflowData.StopTime != existingStopTime { |
| 215 | t.Errorf("Expected stop time to be preserved as %q, got %q", existingStopTime, workflowData.StopTime) |
| 216 | } |
| 217 | }) |
| 218 | |
| 219 | // Test 2: With refresh flag, should generate new stop time |
| 220 | t.Run("refresh flag generates new stop time", func(t *testing.T) { |
| 221 | compiler := NewCompiler() |
| 222 | compiler.SetRefreshStopTime(true) |
| 223 |
nothing calls this directly
no test coverage detected