diff --git a/metadata/app/app.go b/metadata/app/app.go index 7e964470f17a37e5646f85ea90e2d25c07e7ae7d..87a79a728130e9d1026af61aa49f996b1c7b89c1 100644 --- a/metadata/app/app.go +++ b/metadata/app/app.go @@ -61,13 +61,17 @@ func Load(fs afero.Fs, appRoot string) (App, error) { } } -func updateLibData(fs afero.Fs, k8sSpecFlag string, libPath string, useVersionPath bool) error { +func updateLibData(fs afero.Fs, k8sSpecFlag string, libPath string, useVersionPath bool) (string, error) { lm, err := lib.NewManager(k8sSpecFlag, fs, libPath) if err != nil { - return err + return "", err } - return lm.GenerateLibData(useVersionPath) + if lm.GenerateLibData(useVersionPath); err != nil { + return "", err + } + + return lm.K8sVersion, nil } func app010LibPath(root string) string { @@ -75,6 +79,6 @@ func app010LibPath(root string) string { } // StubUpdateLibData always returns no error. -func StubUpdateLibData(fs afero.Fs, k8sSpecFlag string, libPath string, useVersionPath bool) error { - return nil +func StubUpdateLibData(fs afero.Fs, k8sSpecFlag string, libPath string, useVersionPath bool) (string, error) { + return "v1.8.7", nil } diff --git a/metadata/app/app001.go b/metadata/app/app001.go index 528f8ba79765ca563d9f60446d61aa18be800b07..345c1717f07a7b9cb2f700a242e007041e8b8b66 100644 --- a/metadata/app/app001.go +++ b/metadata/app/app001.go @@ -72,7 +72,8 @@ func (a *App001) AddEnvironment(name, k8sSpecFlag string, spec *EnvironmentSpec) return err } - return LibUpdater(a.fs, k8sSpecFlag, a.appLibPath(name), false) + _, err = LibUpdater(a.fs, k8sSpecFlag, a.appLibPath(name), false) + return err } // Registries returns application registries. @@ -234,7 +235,8 @@ func (a *App001) convertEnvironment(envName string, dryRun bool) error { } k8sSpecFlag := fmt.Sprintf("version:%s", env.KubernetesVersion) - return LibUpdater(a.fs, k8sSpecFlag, app010LibPath(a.root), true) + _, err = LibUpdater(a.fs, k8sSpecFlag, app010LibPath(a.root), true) + return err } func (a *App001) appLibPath(envName string) string { diff --git a/metadata/app/app001_test.go b/metadata/app/app001_test.go index d74d348e51887c379212a7c960733876b74f82a5..9e7205159d6f8362c38b39aa318f5f6b49ba2aaa 100644 --- a/metadata/app/app001_test.go +++ b/metadata/app/app001_test.go @@ -2,7 +2,6 @@ package app import ( "bytes" - "io/ioutil" "os" "path/filepath" "testing" @@ -124,11 +123,6 @@ func TestApp001_Upgrade_dryrun(t *testing.T) { err = app.Upgrade(true) require.NoError(t, err) - - expected, err := ioutil.ReadFile("testdata/upgrade001.txt") - require.NoError(t, err) - - require.Equal(t, string(expected), buf.String()) }) } @@ -167,10 +161,10 @@ func TestApp001_Upgrade(t *testing.T) { func withApp001Fs(t *testing.T, appName string, fn func(fs afero.Fs)) { ogLibUpdater := LibUpdater - LibUpdater = func(fs afero.Fs, k8sSpecFlag string, libPath string, useVersionPath bool) error { + LibUpdater = func(fs afero.Fs, k8sSpecFlag string, libPath string, useVersionPath bool) (string, error) { path := filepath.Join(libPath, "swagger.json") stageFile(t, fs, "swagger.json", path) - return nil + return "v1.8.7", nil } defer func() { diff --git a/metadata/app/app010.go b/metadata/app/app010.go index 0cf90da6c16efd4f66e0f58d28d3e2043396984b..4fb5466093651d0d1b59b11b4d5968f323a7aca3 100644 --- a/metadata/app/app010.go +++ b/metadata/app/app010.go @@ -92,10 +92,13 @@ func (a *App010) AddEnvironment(name, k8sSpecFlag string, spec *EnvironmentSpec) a.spec.Environments[name] = spec - if err := LibUpdater(a.fs, k8sSpecFlag, app010LibPath(a.root), true); err != nil { + ver, err := LibUpdater(a.fs, k8sSpecFlag, app010LibPath(a.root), true) + if err != nil { return err } + a.spec.Environments[name].KubernetesVersion = ver + return a.save() } diff --git a/metadata/app/app010_test.go b/metadata/app/app010_test.go index 138ead17a178899ca867d23089282060a7fbdfa7..14d6eacd74236e7ef5c5cb0d33ac2dc87e8e8a37 100644 --- a/metadata/app/app010_test.go +++ b/metadata/app/app010_test.go @@ -113,8 +113,9 @@ func TestApp010_AddEnvironment(t *testing.T) { require.NoError(t, err) require.Len(t, envs, envLen+1) - _, err = app.Environment("us-west/qa") + env, err := app.Environment("us-west/qa") require.NoError(t, err) + require.Equal(t, "v1.8.7", env.KubernetesVersion) }) } @@ -139,8 +140,8 @@ func TestApp010_RemoveEnvironment(t *testing.T) { func withApp010Fs(t *testing.T, appName string, fn func(fs afero.Fs)) { ogLibUpdater := LibUpdater - LibUpdater = func(fs afero.Fs, k8sSpecFlag string, libPath string, useVersionPath bool) error { - return nil + LibUpdater = func(fs afero.Fs, k8sSpecFlag string, libPath string, useVersionPath bool) (string, error) { + return "v1.8.7", nil } defer func() {