MCPcopy Index your code
hub / github.com/coder/coder / TestChecksumFileCRC32

Function TestChecksumFileCRC32

provisioner/terraform/executor_internal_test.go:177–218  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

175}
176
177func TestChecksumFileCRC32(t *testing.T) {
178 t.Parallel()
179
180 t.Run("file exists", func(t *testing.T) {
181 t.Parallel()
182
183 ctx := testutil.Context(t, testutil.WaitShort)
184 logger := testutil.Logger(t)
185
186 tmpfile, err := os.CreateTemp("", "lockfile-*.hcl")
187 require.NoError(t, err)
188 defer os.Remove(tmpfile.Name())
189
190 content := []byte("provider \"aws\" { version = \"5.0.0\" }")
191 _, err = tmpfile.Write(content)
192 require.NoError(t, err)
193 tmpfile.Close()
194
195 // Calculate checksum - expected value for this specific content
196 expectedChecksum := uint32(0x08f39f51)
197 checksum := checksumFileCRC32(ctx, logger, tmpfile.Name())
198 require.Equal(t, expectedChecksum, checksum)
199
200 // Modify file
201 err = os.WriteFile(tmpfile.Name(), []byte("modified content"), 0o600)
202 require.NoError(t, err)
203
204 // Checksum should be different
205 modifiedChecksum := checksumFileCRC32(ctx, logger, tmpfile.Name())
206 require.NotEqual(t, expectedChecksum, modifiedChecksum)
207 })
208
209 t.Run("file does not exist", func(t *testing.T) {
210 t.Parallel()
211
212 ctx := testutil.Context(t, testutil.WaitShort)
213 logger := testutil.Logger(t)
214
215 checksum := checksumFileCRC32(ctx, logger, "/nonexistent/file.hcl")
216 require.Zero(t, checksum)
217 })
218}

Callers

nothing calls this directly

Calls 10

ContextFunction · 0.92
LoggerFunction · 0.92
checksumFileCRC32Function · 0.85
RunMethod · 0.65
RemoveMethod · 0.65
NameMethod · 0.65
WriteMethod · 0.65
CloseMethod · 0.65
WriteFileMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected