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
3bcc68c6b41f
Commit
3bcc68c6b41f
authored
2 years ago
by
steeve.chailloux
Browse files
Options
Downloads
Patches
Plain Diff
add sha feature test suite
parent
99e28d72f88f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#38961
failed
2 years ago
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
runner/config_test.go
+43
-5
43 additions, 5 deletions
runner/config_test.go
runner/fixtures/f2/base/demoytt.tmpl.yaml
+1
-1
1 addition, 1 deletion
runner/fixtures/f2/base/demoytt.tmpl.yaml
with
44 additions
and
6 deletions
runner/config_test.go
+
43
−
5
View file @
3bcc68c6
...
...
@@ -2,6 +2,7 @@
import
(
"os"
"bytes"
"path/filepath"
"testing"
...
...
@@ -5,6 +6,7 @@
"path/filepath"
"testing"
"github.com/go-yaml/yaml"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
...
...
@@ -96,5 +98,4 @@
}
}
/*
func
TestSha
(
t
*
testing
.
T
)
{
...
...
@@ -100,7 +101,8 @@
func
TestSha
(
t
*
testing
.
T
)
{
shaValue
:=
"2145bea9e32804c65d960e6d4af1c87f95ccc39fad7df5eec2f3925a193112ab"
tl
:=
testutils
.
NewTestLogger
(
t
)
absConfigDir
,
err
:=
filepath
.
Abs
(
shaFixtures
)
require
.
NoError
(
t
,
err
)
c
:=
runner
.
NewCmdConfig
(
tl
.
Logger
(),
absConfigDir
,
"base"
,
false
,
""
)
tmpDir
,
err
:=
os
.
MkdirTemp
(
os
.
TempDir
(),
"beaver-"
)
require
.
NoError
(
t
,
err
)
...
...
@@ -101,12 +103,12 @@
tl
:=
testutils
.
NewTestLogger
(
t
)
absConfigDir
,
err
:=
filepath
.
Abs
(
shaFixtures
)
require
.
NoError
(
t
,
err
)
c
:=
runner
.
NewCmdConfig
(
tl
.
Logger
(),
absConfigDir
,
"base"
,
false
,
""
)
tmpDir
,
err
:=
os
.
MkdirTemp
(
os
.
TempDir
(),
"beaver-"
)
require
.
NoError
(
t
,
err
)
//
defer func() {
//
assert.NoError(t, os.RemoveAll(tmpDir))
//
}()
defer
func
()
{
assert
.
NoError
(
t
,
os
.
RemoveAll
(
tmpDir
))
}()
require
.
NoError
(
t
,
c
.
Initialize
(
tmpDir
))
r
:=
runner
.
NewRunner
(
c
)
require
.
NoError
(
t
,
r
.
Build
(
tmpDir
))
...
...
@@ -110,4 +112,16 @@
require
.
NoError
(
t
,
c
.
Initialize
(
tmpDir
))
r
:=
runner
.
NewRunner
(
c
)
require
.
NoError
(
t
,
r
.
Build
(
tmpDir
))
buildDir
:=
filepath
.
Join
(
shaFixtures
,
"build"
,
"example"
)
configMap
:=
filepath
.
Join
(
buildDir
,
"ConfigMap.v1.demo.yaml"
)
cm
:=
parseFile
(
t
,
configMap
)
sha
:=
getLabel
(
t
,
cm
,
"mysha"
)
require
.
Equal
(
t
,
shaValue
,
sha
)
deployment
:=
filepath
.
Join
(
buildDir
,
"Deployment.apps_v1.nginx.yaml"
)
deploy
:=
parseFile
(
t
,
deployment
)
sha
=
getLabel
(
t
,
deploy
,
"config.sha"
)
require
.
Equal
(
t
,
shaValue
,
sha
)
}
...
...
@@ -113,2 +127,26 @@
}
*/
func
getLabel
(
t
*
testing
.
T
,
resource
map
[
string
]
interface
{},
label
string
)
string
{
metadata
,
ok
:=
resource
[
"metadata"
]
.
(
map
[
interface
{}]
interface
{})
require
.
True
(
t
,
ok
)
labels
,
ok
:=
metadata
[
"labels"
]
.
(
map
[
interface
{}]
interface
{})
require
.
True
(
t
,
ok
)
result
,
ok
:=
labels
[
label
]
.
(
string
)
require
.
True
(
t
,
ok
)
return
result
}
func
parseFile
(
t
*
testing
.
T
,
input
string
)
map
[
string
]
interface
{}
{
resource
:=
make
(
map
[
string
]
interface
{})
content
,
err
:=
os
.
ReadFile
(
input
)
require
.
NoError
(
t
,
err
)
byteContent
:=
bytes
.
NewReader
(
content
)
decoder
:=
yaml
.
NewDecoder
(
byteContent
)
err
=
decoder
.
Decode
(
&
resource
)
require
.
NoError
(
t
,
err
)
return
resource
}
This diff is collapsed.
Click to expand it.
runner/fixtures/f2/base/demoytt.tmpl.yaml
+
1
−
1
View file @
3bcc68c6
...
...
@@ -4,7 +4,7 @@
kind
:
ConfigMap
metadata
:
name
:
demo
label
:
label
s
:
mysha
:
#@ data.values.sha
data
:
answer
:
#@ data.values.answer
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