Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
Ijaz Ahmad
ksonnet
Commits
af245809
Unverified
Commit
af245809
authored
Aug 06, 2018
by
Bryan Liles
Committed by
GitHub
Aug 06, 2018
Browse files
Merge pull request #818 from bryanl/746-ks-env-current-requires-valid-env
require env to exist before making it current
parents
c15cffba
f78b9cb5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
9 deletions
+48
-9
pkg/app/base_app.go
pkg/app/base_app.go
+15
-0
pkg/app/base_app_test.go
pkg/app/base_app_test.go
+33
-9
No files found.
pkg/app/base_app.go
View file @
af245809
...
@@ -20,6 +20,7 @@ import (
...
@@ -20,6 +20,7 @@ import (
"sync"
"sync"
"github.com/ghodss/yaml"
"github.com/ghodss/yaml"
stringutils
"github.com/ksonnet/ksonnet/pkg/util/strings"
"github.com/pkg/errors"
"github.com/pkg/errors"
log
"github.com/sirupsen/logrus"
log
"github.com/sirupsen/logrus"
"github.com/spf13/afero"
"github.com/spf13/afero"
...
@@ -62,6 +63,20 @@ func (ba *baseApp) CurrentEnvironment() string {
...
@@ -62,6 +63,20 @@ func (ba *baseApp) CurrentEnvironment() string {
}
}
func
(
ba
*
baseApp
)
SetCurrentEnvironment
(
name
string
)
error
{
func
(
ba
*
baseApp
)
SetCurrentEnvironment
(
name
string
)
error
{
envs
,
err
:=
ba
.
Environments
()
if
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"loading environments"
)
}
var
envNames
[]
string
for
_
,
env
:=
range
envs
{
envNames
=
append
(
envNames
,
env
.
Name
)
}
if
!
stringutils
.
InSlice
(
name
,
envNames
)
{
return
errors
.
Errorf
(
"environment %q does not exist"
,
name
)
}
currentPath
:=
filepath
.
Join
(
ba
.
root
,
currentEnvName
)
currentPath
:=
filepath
.
Join
(
ba
.
root
,
currentEnvName
)
return
afero
.
WriteFile
(
ba
.
fs
,
currentPath
,
[]
byte
(
name
),
DefaultFilePermissions
)
return
afero
.
WriteFile
(
ba
.
fs
,
currentPath
,
[]
byte
(
name
),
DefaultFilePermissions
)
}
}
...
...
pkg/app/base_app_test.go
View file @
af245809
...
@@ -60,15 +60,41 @@ func Test_baseapp_CurrentEnvironment(t *testing.T) {
...
@@ -60,15 +60,41 @@ func Test_baseapp_CurrentEnvironment(t *testing.T) {
}
}
func
Test_baseapp_SetCurrentEnvironment
(
t
*
testing
.
T
)
{
func
Test_baseapp_SetCurrentEnvironment
(
t
*
testing
.
T
)
{
cases
:=
[]
struct
{
name
string
envName
string
isErr
bool
}{
{
name
:
"environment exists"
,
envName
:
"default"
,
},
{
name
:
"environment does not exist"
,
envName
:
"invalid"
,
isErr
:
true
,
},
}
for
_
,
tc
:=
range
cases
{
t
.
Run
(
tc
.
name
,
func
(
t
*
testing
.
T
)
{
fs
:=
afero
.
NewMemMapFs
()
fs
:=
afero
.
NewMemMapFs
()
stageFile
(
t
,
fs
,
"app010_app.yaml"
,
"/app.yaml"
)
stageFile
(
t
,
fs
,
"app010_app.yaml"
,
"/app.yaml"
)
ba
:=
newBaseApp
(
fs
,
"/"
)
ba
:=
newBaseApp
(
fs
,
"/"
)
err
:=
ba
.
SetCurrentEnvironment
(
"default"
)
err
:=
ba
.
SetCurrentEnvironment
(
tc
.
envName
)
if
tc
.
isErr
{
require
.
Error
(
t
,
err
)
return
}
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
current
:=
ba
.
CurrentEnvironment
()
current
:=
ba
.
CurrentEnvironment
()
assert
.
Equal
(
t
,
"default"
,
current
)
assert
.
Equal
(
t
,
tc
.
envName
,
current
)
})
}
}
}
func
Test_baseApp_AddRegistry
(
t
*
testing
.
T
)
{
func
Test_baseApp_AddRegistry
(
t
*
testing
.
T
)
{
...
@@ -164,8 +190,6 @@ func Test_baseApp_UpdateRegistry(t *testing.T) {
...
@@ -164,8 +190,6 @@ func Test_baseApp_UpdateRegistry(t *testing.T) {
}
}
func
Test_baseApp_UpdateLibrary
(
t
*
testing
.
T
)
{
func
Test_baseApp_UpdateLibrary
(
t
*
testing
.
T
)
{
//func (ba *baseApp) UpdateLib(name string, env string, libSpec *LibraryConfig) error
tests
:=
[]
struct
{
tests
:=
[]
struct
{
name
string
name
string
libCfg
LibraryConfig
libCfg
LibraryConfig
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment