TestWriteWorkflowOutput_ContentUnchanged tests that the file is not rewritten if content hasn't changed
(t *testing.T)
| 821 | |
| 822 | // TestWriteWorkflowOutput_ContentUnchanged tests that the file is not rewritten if content hasn't changed |
| 823 | func TestWriteWorkflowOutput_ContentUnchanged(t *testing.T) { |
| 824 | tmpDir := testutil.TempDir(t, "unchanged-test") |
| 825 | markdownPath := filepath.Join(tmpDir, "test.md") |
| 826 | lockFile := stringutil.MarkdownToLockFile(markdownPath) |
| 827 | |
| 828 | yamlContent := "name: test\non: push\njobs:\n test:\n runs-on: ubuntu-latest\n" |
| 829 | |
| 830 | // Write initial content |
| 831 | require.NoError(t, os.WriteFile(lockFile, []byte(yamlContent), 0644)) |
| 832 | |
| 833 | // Get initial modification time |
| 834 | initialInfo, err := os.Stat(lockFile) |
| 835 | require.NoError(t, err, "Failed to stat lock file before rewrite") |
| 836 | initialModTime := initialInfo.ModTime() |
| 837 | |
| 838 | // Sleep to ensure filesystem mtime resolution is exceeded |
| 839 | // Most filesystems have 1-2 second resolution for mtime |
| 840 | time.Sleep(2 * time.Second) |
| 841 | |
| 842 | // Write same content again |
| 843 | compiler := NewCompiler() |
| 844 | err = compiler.writeWorkflowOutput(lockFile, yamlContent, markdownPath) |
| 845 | require.NoError(t, err, "Writing unchanged content should succeed") |
| 846 | |
| 847 | // Check that modification time hasn't changed (file wasn't rewritten) |
| 848 | finalInfo, err := os.Stat(lockFile) |
| 849 | require.NoError(t, err, "Failed to stat lock file after rewrite") |
| 850 | finalModTime := finalInfo.ModTime() |
| 851 | |
| 852 | assert.Equal(t, initialModTime, finalModTime, "File should not be rewritten if content is unchanged") |
| 853 | } |
| 854 | |
| 855 | // TestCompileWorkflow_ConcurrentCompilation tests thread-safety of concurrent compilations |
| 856 | func TestCompileWorkflow_ConcurrentCompilation(t *testing.T) { |
nothing calls this directly
no test coverage detected