(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func TestMigrationAppliedSuccessfully(t *testing.T) { |
| 17 | readConfig := StubWriteConfig(t) |
| 18 | |
| 19 | // Given we have a migrator that writes some keys to the top level config |
| 20 | // and hosts key |
| 21 | c := ghConfig.ReadFromString(testFullConfig()) |
| 22 | |
| 23 | topLevelKey := []string{"toplevelkey"} |
| 24 | newHostKey := []string{hostsKey, "newhost"} |
| 25 | |
| 26 | migration := mockMigration(func(config *ghConfig.Config) error { |
| 27 | config.Set(topLevelKey, "toplevelvalue") |
| 28 | config.Set(newHostKey, "newhostvalue") |
| 29 | return nil |
| 30 | }) |
| 31 | |
| 32 | // When we run the migration |
| 33 | conf := cfg{c} |
| 34 | require.NoError(t, conf.Migrate(migration)) |
| 35 | |
| 36 | // Then our original config is updated with the migration applied |
| 37 | requireKeyWithValue(t, c, topLevelKey, "toplevelvalue") |
| 38 | requireKeyWithValue(t, c, newHostKey, "newhostvalue") |
| 39 | |
| 40 | // And our config / hosts changes are persisted to their relevant files |
| 41 | // Note that this is real janky. We have writers that represent the |
| 42 | // top level config and the hosts key but we don't merge them back together |
| 43 | // so when we look into the hosts data, we don't nest the key we're |
| 44 | // looking for under the hosts key ¯\_(ツ)_/¯ |
| 45 | var configBuf bytes.Buffer |
| 46 | var hostsBuf bytes.Buffer |
| 47 | readConfig(&configBuf, &hostsBuf) |
| 48 | persistedCfg := ghConfig.ReadFromString(configBuf.String()) |
| 49 | persistedHosts := ghConfig.ReadFromString(hostsBuf.String()) |
| 50 | |
| 51 | requireKeyWithValue(t, persistedCfg, topLevelKey, "toplevelvalue") |
| 52 | requireKeyWithValue(t, persistedHosts, []string{"newhost"}, "newhostvalue") |
| 53 | } |
| 54 | |
| 55 | func TestMigrationAppliedBumpsVersion(t *testing.T) { |
| 56 | readConfig := StubWriteConfig(t) |
nothing calls this directly
no test coverage detected