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

Function TestMigrationAppliedSuccessfully

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

Source from the content-addressed store, hash-verified

14)
15
16func 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
55func TestMigrationAppliedBumpsVersion(t *testing.T) {
56 readConfig := StubWriteConfig(t)

Callers

nothing calls this directly

Calls 7

MigrateMethod · 0.95
StubWriteConfigFunction · 0.85
testFullConfigFunction · 0.85
mockMigrationFunction · 0.85
requireKeyWithValueFunction · 0.70
SetMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected