As we reevaluate how to best support and maintain Staging Ref in the future, we encourage development teams using this environment to highlight their use cases in the following issue: https://gitlab.com/gitlab-com/gl-infra/software-delivery/framework/software-delivery-framework-issue-tracker/-/issues/36.

Skip to content
Snippets Groups Projects
Unverified Commit c44e4e4e authored by Ash McKenzie's avatar Ash McKenzie
Browse files

New config.MetaData struct and NewMetaData()

parent 49bd5e39
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -6,6 +6,7 @@ import (
"os"
"path"
"path/filepath"
"strings"
"sync"
"time"
Loading
Loading
@@ -82,6 +83,12 @@ type Config struct {
GitalyClient gitaly.Client
}
type MetaData struct {
Username string `json:"username"`
Project string `json:"project,omitempty"`
RootNamespace string `json:"root_namespace,omitempty"`
}
// The defaults to apply before parsing the config file(s).
var (
DefaultConfig = Config{
Loading
Loading
@@ -110,6 +117,26 @@ var (
}
)
func NewMetaData(project, username string) MetaData {
rootNameSpace := ""
if len(project) > 0 {
splitFn := func(c rune) bool {
return c == '/'
}
m := strings.FieldsFunc(project, splitFn)
if len(m) > 0 {
rootNameSpace = m[0]
}
}
return MetaData{
Username: username,
Project: project,
RootNamespace: rootNameSpace,
}
}
func (d *YamlDuration) UnmarshalYAML(unmarshal func(interface{}) error) error {
var intDuration int
if err := unmarshal(&intDuration); err != nil {
Loading
Loading
Loading
Loading
@@ -98,3 +98,40 @@ func TestYAMLDuration(t *testing.T) {
})
}
}
func TestNewMetaData(t *testing.T) {
testCases := []struct {
desc string
project string
username string
expectedRootNamespace string
}{
{
desc: "Project under single namespace",
project: "flightjs/Flight",
username: "@alex-doe",
expectedRootNamespace: "flightjs",
},
{
desc: "Project under single odd namespace",
project: "flightjs///Flight",
username: "@alex-doe",
expectedRootNamespace: "flightjs",
},
{
desc: "Project under deeper namespace",
project: "flightjs/one/Flight",
username: "@alex-doe",
expectedRootNamespace: "flightjs",
},
}
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
metaData := NewMetaData(tc.project, tc.username)
require.Equal(t, tc.project, metaData.Project)
require.Equal(t, tc.username, metaData.Username)
require.Equal(t, tc.expectedRootNamespace, metaData.RootNamespace)
})
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment