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

Function TestMigrationAppliedBumpsVersion

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

Source from the content-addressed store, hash-verified

53}
54
55func 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
94func TestMigrationIsNoopWhenAlreadyApplied(t *testing.T) {
95 // Given we have a migration with a post version that matches

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected