MCPcopy Index your code
hub / github.com/cli/cli / TestMigrationErrorWritesNoFiles

Function TestMigrationErrorWritesNoFiles

internal/config/migrate_test.go:153–174  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

151}
152
153func TestMigrationErrorWritesNoFiles(t *testing.T) {
154 tempDir := t.TempDir()
155 t.Setenv("GH_CONFIG_DIR", tempDir)
156
157 // Given we have a migrator that errors
158 c := ghConfig.ReadFromString(testFullConfig())
159 migration := mockMigration(func(config *ghConfig.Config) error {
160 return errors.New("failed to migrate in test")
161 })
162
163 // When we run the migration
164 conf := cfg{c}
165 err := conf.Migrate(migration)
166
167 // Then the error is wrapped and bubbled
168 require.EqualError(t, err, "failed to migrate config: failed to migrate in test")
169
170 // And no files are written to disk
171 files, err := os.ReadDir(tempDir)
172 require.NoError(t, err)
173 require.Len(t, files, 0)
174}
175
176func TestMigrationWriteErrors(t *testing.T) {
177 tests := []struct {

Callers

nothing calls this directly

Calls 4

MigrateMethod · 0.95
testFullConfigFunction · 0.85
mockMigrationFunction · 0.85
LenMethod · 0.65

Tested by

no test coverage detected