(t *testing.T)
| 119 | } |
| 120 | |
| 121 | func TestMigrationErrorsWhenPreVersionMismatch(t *testing.T) { |
| 122 | StubWriteConfig(t) |
| 123 | |
| 124 | // Given we have a migration with a pre version that does not match |
| 125 | // the version in the config |
| 126 | c := ghConfig.ReadFromString(testFullConfig()) |
| 127 | c.Set([]string{versionKey}, "not-expected-pre-version") |
| 128 | topLevelKey := []string{"toplevelkey"} |
| 129 | |
| 130 | migration := &ghmock.MigrationMock{ |
| 131 | DoFunc: func(config *ghConfig.Config) error { |
| 132 | config.Set(topLevelKey, "toplevelvalue") |
| 133 | return nil |
| 134 | }, |
| 135 | PreVersionFunc: func() string { |
| 136 | return "expected-pre-version" |
| 137 | }, |
| 138 | PostVersionFunc: func() string { |
| 139 | return "not-expected" |
| 140 | }, |
| 141 | } |
| 142 | |
| 143 | // When we run Migrate |
| 144 | conf := cfg{c} |
| 145 | err := conf.Migrate(migration) |
| 146 | |
| 147 | // Then there is an error the migration is not applied and the version is not modified |
| 148 | require.ErrorContains(t, err, `failed to migrate as "expected-pre-version" pre migration version did not match config version "not-expected-pre-version"`) |
| 149 | requireNoKey(t, c, topLevelKey) |
| 150 | requireKeyWithValue(t, c, []string{versionKey}, "not-expected-pre-version") |
| 151 | } |
| 152 | |
| 153 | func TestMigrationErrorWritesNoFiles(t *testing.T) { |
| 154 | tempDir := t.TempDir() |
nothing calls this directly
no test coverage detected