(t *testing.T)
| 53 | } |
| 54 | |
| 55 | func TestMigrationAppliedBumpsVersion(t *testing.T) { |
| 56 | readConfig := StubWriteConfig(t) |
| 57 | |
| 58 | // Given we have a migration with a pre version that matches |
| 59 | // the version in the config |
| 60 | c := ghConfig.ReadFromString(testFullConfig()) |
| 61 | c.Set([]string{versionKey}, "expected-pre-version") |
| 62 | topLevelKey := []string{"toplevelkey"} |
| 63 | |
| 64 | migration := &ghmock.MigrationMock{ |
| 65 | DoFunc: func(config *ghConfig.Config) error { |
| 66 | config.Set(topLevelKey, "toplevelvalue") |
| 67 | return nil |
| 68 | }, |
| 69 | PreVersionFunc: func() string { |
| 70 | return "expected-pre-version" |
| 71 | }, |
| 72 | PostVersionFunc: func() string { |
| 73 | return "expected-post-version" |
| 74 | }, |
| 75 | } |
| 76 | |
| 77 | // When we migrate |
| 78 | conf := cfg{c} |
| 79 | require.NoError(t, conf.Migrate(migration)) |
| 80 | |
| 81 | // Then our original config is updated with the migration applied |
| 82 | requireKeyWithValue(t, c, topLevelKey, "toplevelvalue") |
| 83 | requireKeyWithValue(t, c, []string{versionKey}, "expected-post-version") |
| 84 | |
| 85 | // And our config / hosts changes are persisted to their relevant files |
| 86 | var configBuf bytes.Buffer |
| 87 | readConfig(&configBuf, io.Discard) |
| 88 | persistedCfg := ghConfig.ReadFromString(configBuf.String()) |
| 89 | |
| 90 | requireKeyWithValue(t, persistedCfg, topLevelKey, "toplevelvalue") |
| 91 | requireKeyWithValue(t, persistedCfg, []string{versionKey}, "expected-post-version") |
| 92 | } |
| 93 | |
| 94 | func TestMigrationIsNoopWhenAlreadyApplied(t *testing.T) { |
| 95 | // Given we have a migration with a post version that matches |
nothing calls this directly
no test coverage detected