Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Ijaz Ahmad
ksonnet
Commits
f78b9cb5
Unverified
Commit
f78b9cb5
authored
Aug 06, 2018
by
bryanl
Browse files
require env to exist before making it current
Signed-off-by:
bryanl
<
bryanliles@gmail.com
>
parent
c15cffba
Changes
2
Hide 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 @
f78b9cb5
...
...
@@ -20,6 +20,7 @@ import (
"sync"
"github.com/ghodss/yaml"
stringutils
"github.com/ksonnet/ksonnet/pkg/util/strings"
"github.com/pkg/errors"
log
"github.com/sirupsen/logrus"
"github.com/spf13/afero"
...
...
@@ -62,6 +63,20 @@ func (ba *baseApp) CurrentEnvironment() string {
}
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
)
return
afero
.
WriteFile
(
ba
.
fs
,
currentPath
,
[]
byte
(
name
),
DefaultFilePermissions
)
}
...
...
pkg/app/base_app_test.go
View file @
f78b9cb5
...
...
@@ -60,15 +60,41 @@ func Test_baseapp_CurrentEnvironment(t *testing.T) {
}
func
Test_baseapp_SetCurrentEnvironment
(
t
*
testing
.
T
)
{
fs
:=
afero
.
NewMemMapFs
()
stageFile
(
t
,
fs
,
"app010_app.yaml"
,
"/app.yaml"
)
ba
:=
newBaseApp
(
fs
,
"/"
)
cases
:=
[]
struct
{
name
string
envName
string
isErr
bool
}{
{
name
:
"environment exists"
,
envName
:
"default"
,
},
{
name
:
"environment does not exist"
,
envName
:
"invalid"
,
isErr
:
true
,
},
}
err
:=
ba
.
SetCurrentEnvironment
(
"default"
)
require
.
NoError
(
t
,
err
)
for
_
,
tc
:=
range
cases
{
t
.
Run
(
tc
.
name
,
func
(
t
*
testing
.
T
)
{
fs
:=
afero
.
NewMemMapFs
()
stageFile
(
t
,
fs
,
"app010_app.yaml"
,
"/app.yaml"
)
ba
:=
newBaseApp
(
fs
,
"/"
)
err
:=
ba
.
SetCurrentEnvironment
(
tc
.
envName
)
if
tc
.
isErr
{
require
.
Error
(
t
,
err
)
return
}
require
.
NoError
(
t
,
err
)
current
:=
ba
.
CurrentEnvironment
()
assert
.
Equal
(
t
,
tc
.
envName
,
current
)
})
}
current
:=
ba
.
CurrentEnvironment
()
assert
.
Equal
(
t
,
"default"
,
current
)
}
func
Test_baseApp_AddRegistry
(
t
*
testing
.
T
)
{
...
...
@@ -164,8 +190,6 @@ func Test_baseApp_UpdateRegistry(t *testing.T) {
}
func
Test_baseApp_UpdateLibrary
(
t
*
testing
.
T
)
{
//func (ba *baseApp) UpdateLib(name string, env string, libSpec *LibraryConfig) error
tests
:=
[]
struct
{
name
string
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