Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
beaver
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
orus-io
beaver
Commits
00dd885393fa
Commit
00dd885393fa
authored
2 years ago
by
Florent Aide
Browse files
Options
Downloads
Patches
Plain Diff
runner config now needs a logger
parent
b5b8ec8eea16
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
cmd/build.go
+1
-1
1 addition, 1 deletion
cmd/build.go
runner/config.go
+3
-1
3 additions, 1 deletion
runner/config.go
runner/config_test.go
+3
-1
3 additions, 1 deletion
runner/config_test.go
testutils/logger.go
+53
-0
53 additions, 0 deletions
testutils/logger.go
with
60 additions
and
3 deletions
cmd/build.go
+
1
−
1
View file @
00dd8853
...
...
@@ -19,7 +19,7 @@
// Execute ...
func
(
cmd
*
BuildCmd
)
Execute
([]
string
)
error
{
Logger
.
Info
()
.
Str
(
"namespace"
,
cmd
.
Args
.
Namespace
)
.
Msg
(
"starting beaver"
)
config
,
err
:=
runner
.
NewConfig
(
"."
,
cmd
.
Args
.
Namespace
)
config
,
err
:=
runner
.
NewConfig
(
Logger
,
"."
,
cmd
.
Args
.
Namespace
)
if
err
!=
nil
{
Logger
.
Err
(
err
)
.
Msg
(
"failed to prepare config"
)
}
...
...
This diff is collapsed.
Click to expand it.
runner/config.go
+
3
−
1
View file @
00dd8853
...
...
@@ -5,6 +5,7 @@
"fmt"
"text/template"
"github.com/rs/zerolog"
"github.com/spf13/viper"
yaml
"gopkg.in/yaml.v2"
)
...
...
@@ -39,6 +40,7 @@
Kind
string
`mapstructure:"kind"`
Spec
Spec
`mapstructure:"spec"`
Namespace
string
Logger
zerolog
.
Logger
}
// NewConfig returns a *Config
...
...
@@ -42,7 +44,7 @@
}
// NewConfig returns a *Config
func
NewConfig
(
configDir
string
,
namespace
string
)
(
*
Config
,
error
)
{
func
NewConfig
(
logger
zerolog
.
Logger
,
configDir
string
,
namespace
string
)
(
*
Config
,
error
)
{
// we ONLY search for files named beaver.yml
viper
.
SetConfigName
(
"beaver"
)
viper
.
AddConfigPath
(
configDir
)
...
...
This diff is collapsed.
Click to expand it.
runner/config_test.go
+
3
−
1
View file @
00dd8853
...
...
@@ -5,6 +5,7 @@
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"orus.io/cloudcrane/beaver/testutils"
)
func
TestConfig
(
t
*
testing
.
T
)
{
...
...
@@ -8,4 +9,5 @@
)
func
TestConfig
(
t
*
testing
.
T
)
{
logger
:=
testutils
.
GetLogger
(
t
)
configDir
:=
"fixtures/"
...
...
@@ -11,5 +13,5 @@
configDir
:=
"fixtures/"
config
,
err
:=
NewConfig
(
configDir
,
"ns1"
)
config
,
err
:=
NewConfig
(
logger
,
configDir
,
"ns1"
)
require
.
NoError
(
t
,
err
)
// first config.spec.variables entry name should be VAULT_KV in our test file
assert
.
Equal
(
t
,
"VAULT_KV"
,
config
.
Spec
.
Variables
[
0
]
.
Name
)
...
...
This diff is collapsed.
Click to expand it.
testutils/logger.go
0 → 100644
+
53
−
0
View file @
00dd8853
package
testutils
import
(
"os"
"testing"
"github.com/rs/zerolog"
)
// NewTestLogger creates a TestLogger
func
NewTestLogger
(
tb
testing
.
TB
)
*
TestLogger
{
return
&
TestLogger
{
tb
}
}
// TestLogger logs to a t.Log function
type
TestLogger
struct
{
tb
testing
.
TB
}
// Logger returns a zerolog Logger
func
(
tl
*
TestLogger
)
Logger
()
zerolog
.
Logger
{
level
:=
zerolog
.
DebugLevel
if
os
.
Getenv
(
"TEST_TRACE"
)
!=
""
{
level
=
zerolog
.
TraceLevel
}
if
os
.
Getenv
(
"TEST_QUIET"
)
!=
""
{
level
=
zerolog
.
InfoLevel
}
return
zerolog
.
New
(
zerolog
.
ConsoleWriter
{
Out
:
tl
})
.
With
()
.
Timestamp
()
.
Logger
()
.
Level
(
level
)
}
// Write writes the given string to t.Logf
func
(
tl
*
TestLogger
)
Write
(
m
[]
byte
)
(
int
,
error
)
{
tl
.
tb
.
Logf
(
string
(
m
))
return
len
(
m
),
nil
}
// SetTB changes the current TB, and returns a function to get back to the
// previous one
func
(
tl
*
TestLogger
)
SetTB
(
tb
testing
.
TB
)
func
()
{
otb
:=
tl
.
tb
tl
.
tb
=
tb
return
func
()
{
tl
.
tb
=
otb
}
}
// GetLogger returns a test Logger
func
GetLogger
(
tb
testing
.
TB
)
zerolog
.
Logger
{
return
NewTestLogger
(
tb
)
.
Logger
()
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment