refactor: use properties as map type

This commit is contained in:
Jan De Dobbeleer 2021-11-26 10:37:33 +01:00 committed by Jan De Dobbeleer
parent 8e82d2b80c
commit 09df670e07
79 changed files with 422 additions and 666 deletions

View file

@ -15,7 +15,7 @@ You can use the following template as a guide.
package main package main
type new struct { type new struct {
props *properties props properties
env environmentInfo env environmentInfo
Text string Text string
@ -48,7 +48,7 @@ func (n *new) string() string {
return text return text
} }
func (n *new) init(props *properties, env environmentInfo) { func (n *new) init(props properties, env environmentInfo) {
n.props = props n.props = props
n.env = env n.env = env
} }

View file

@ -37,17 +37,10 @@ const (
DisplayDefault Property = "display_default" DisplayDefault Property = "display_default"
) )
type properties struct { type properties map[Property]interface{}
values map[Property]interface{}
foreground string
background string
}
func (p *properties) getString(property Property, defaultValue string) string { func (p properties) getString(property Property, defaultValue string) string {
if p == nil || p.values == nil { val, found := p[property]
return defaultValue
}
val, found := p.values[property]
if !found { if !found {
return defaultValue return defaultValue
} }
@ -62,11 +55,8 @@ func parseString(value interface{}, defaultValue string) string {
return stringValue return stringValue
} }
func (p *properties) getColor(property Property, defaultValue string) string { func (p properties) getColor(property Property, defaultValue string) string {
if p == nil || p.values == nil { val, found := p[property]
return defaultValue
}
val, found := p.values[property]
if !found { if !found {
return defaultValue return defaultValue
} }
@ -81,11 +71,8 @@ func (p *properties) getColor(property Property, defaultValue string) string {
return defaultValue return defaultValue
} }
func (p *properties) getBool(property Property, defaultValue bool) bool { func (p properties) getBool(property Property, defaultValue bool) bool {
if p == nil || p.values == nil { val, found := p[property]
return defaultValue
}
val, found := p.values[property]
if !found { if !found {
return defaultValue return defaultValue
} }
@ -96,11 +83,8 @@ func (p *properties) getBool(property Property, defaultValue bool) bool {
return boolValue return boolValue
} }
func (p *properties) getFloat64(property Property, defaultValue float64) float64 { func (p properties) getFloat64(property Property, defaultValue float64) float64 {
if p == nil || p.values == nil { val, found := p[property]
return defaultValue
}
val, found := p.values[property]
if !found { if !found {
return defaultValue return defaultValue
} }
@ -113,11 +97,8 @@ func (p *properties) getFloat64(property Property, defaultValue float64) float64
return floatValue return floatValue
} }
func (p *properties) getInt(property Property, defaultValue int) int { func (p properties) getInt(property Property, defaultValue int) int {
if p == nil || p.values == nil { val, found := p[property]
return defaultValue
}
val, found := p.values[property]
if !found { if !found {
return defaultValue return defaultValue
} }
@ -135,11 +116,8 @@ func (p *properties) getInt(property Property, defaultValue int) int {
return int(intValue) return int(intValue)
} }
func (p *properties) getKeyValueMap(property Property, defaultValue map[string]string) map[string]string { func (p properties) getKeyValueMap(property Property, defaultValue map[string]string) map[string]string {
if p == nil || p.values == nil { val, found := p[property]
return defaultValue
}
val, found := p.values[property]
if !found { if !found {
return defaultValue return defaultValue
} }

View file

@ -12,146 +12,101 @@ const (
) )
func TestGetString(t *testing.T) { func TestGetString(t *testing.T) {
values := map[Property]interface{}{TextProperty: expected} var properties properties = map[Property]interface{}{TextProperty: expected}
properties := properties{
values: values,
}
value := properties.getString(TextProperty, "err") value := properties.getString(TextProperty, "err")
assert.Equal(t, expected, value) assert.Equal(t, expected, value)
} }
func TestGetStringNoEntry(t *testing.T) { func TestGetStringNoEntry(t *testing.T) {
values := map[Property]interface{}{} var properties properties = map[Property]interface{}{}
properties := properties{
values: values,
}
value := properties.getString(TextProperty, expected) value := properties.getString(TextProperty, expected)
assert.Equal(t, expected, value) assert.Equal(t, expected, value)
} }
func TestGetStringNoTextEntry(t *testing.T) { func TestGetStringNoTextEntry(t *testing.T) {
values := map[Property]interface{}{TextProperty: true} var properties properties = map[Property]interface{}{TextProperty: true}
properties := properties{
values: values,
}
value := properties.getString(TextProperty, expected) value := properties.getString(TextProperty, expected)
assert.Equal(t, expected, value) assert.Equal(t, expected, value)
} }
func TestGetHexColor(t *testing.T) { func TestGetHexColor(t *testing.T) {
expected := expectedColor expected := expectedColor
values := map[Property]interface{}{UserColor: expected} var properties properties = map[Property]interface{}{UserColor: expected}
properties := properties{
values: values,
}
value := properties.getColor(UserColor, "#789123") value := properties.getColor(UserColor, "#789123")
assert.Equal(t, expected, value) assert.Equal(t, expected, value)
} }
func TestGetColor(t *testing.T) { func TestGetColor(t *testing.T) {
expected := "yellow" expected := "yellow"
values := map[Property]interface{}{UserColor: expected} var properties properties = map[Property]interface{}{UserColor: expected}
properties := properties{
values: values,
}
value := properties.getColor(UserColor, "#789123") value := properties.getColor(UserColor, "#789123")
assert.Equal(t, expected, value) assert.Equal(t, expected, value)
} }
func TestDefaultColorWithInvalidColorCode(t *testing.T) { func TestDefaultColorWithInvalidColorCode(t *testing.T) {
expected := expectedColor expected := expectedColor
values := map[Property]interface{}{UserColor: "invalid"} var properties properties = map[Property]interface{}{UserColor: "invalid"}
properties := properties{
values: values,
}
value := properties.getColor(UserColor, expected) value := properties.getColor(UserColor, expected)
assert.Equal(t, expected, value) assert.Equal(t, expected, value)
} }
func TestDefaultColorWithUnavailableProperty(t *testing.T) { func TestDefaultColorWithUnavailableProperty(t *testing.T) {
expected := expectedColor expected := expectedColor
values := map[Property]interface{}{} var properties properties = map[Property]interface{}{}
properties := properties{
values: values,
}
value := properties.getColor(UserColor, expected) value := properties.getColor(UserColor, expected)
assert.Equal(t, expected, value) assert.Equal(t, expected, value)
} }
func TestGetPaletteColor(t *testing.T) { func TestGetPaletteColor(t *testing.T) {
expected := "p:red" expected := "p:red"
values := map[Property]interface{}{Background: expected} var properties properties = map[Property]interface{}{Background: expected}
properties := properties{
values: values,
}
value := properties.getColor(Background, "white") value := properties.getColor(Background, "white")
assert.Equal(t, expected, value) assert.Equal(t, expected, value)
} }
func TestGetBool(t *testing.T) { func TestGetBool(t *testing.T) {
expected := true expected := true
values := map[Property]interface{}{DisplayHost: expected} var properties properties = map[Property]interface{}{DisplayHost: expected}
properties := properties{
values: values,
}
value := properties.getBool(DisplayHost, false) value := properties.getBool(DisplayHost, false)
assert.True(t, value) assert.True(t, value)
} }
func TestGetBoolPropertyNotInMap(t *testing.T) { func TestGetBoolPropertyNotInMap(t *testing.T) {
values := map[Property]interface{}{} var properties properties = map[Property]interface{}{}
properties := properties{
values: values,
}
value := properties.getBool(DisplayHost, false) value := properties.getBool(DisplayHost, false)
assert.False(t, value) assert.False(t, value)
} }
func TestGetBoolInvalidProperty(t *testing.T) { func TestGetBoolInvalidProperty(t *testing.T) {
values := map[Property]interface{}{DisplayHost: "borked"} var properties properties = map[Property]interface{}{DisplayHost: "borked"}
properties := properties{
values: values,
}
value := properties.getBool(DisplayHost, false) value := properties.getBool(DisplayHost, false)
assert.False(t, value) assert.False(t, value)
} }
func TestGetFloat64(t *testing.T) { func TestGetFloat64(t *testing.T) {
expected := float64(1337) expected := float64(1337)
values := map[Property]interface{}{"myfloat": expected} var properties properties = map[Property]interface{}{"myfloat": expected}
properties := properties{
values: values,
}
value := properties.getFloat64("myfloat", 9001) value := properties.getFloat64("myfloat", 9001)
assert.Equal(t, expected, value) assert.Equal(t, expected, value)
} }
func TestGetFloat64PropertyNotInMap(t *testing.T) { func TestGetFloat64PropertyNotInMap(t *testing.T) {
expected := float64(1337) expected := float64(1337)
values := map[Property]interface{}{} var properties properties = map[Property]interface{}{}
properties := properties{
values: values,
}
value := properties.getFloat64(ThresholdProperty, expected) value := properties.getFloat64(ThresholdProperty, expected)
assert.Equal(t, expected, value) assert.Equal(t, expected, value)
} }
func TestGetFloat64InvalidStringProperty(t *testing.T) { func TestGetFloat64InvalidStringProperty(t *testing.T) {
expected := float64(1337) expected := float64(1337)
values := map[Property]interface{}{ThresholdProperty: "invalid"} var properties properties = map[Property]interface{}{ThresholdProperty: "invalid"}
properties := properties{
values: values,
}
value := properties.getFloat64(ThresholdProperty, expected) value := properties.getFloat64(ThresholdProperty, expected)
assert.Equal(t, expected, value) assert.Equal(t, expected, value)
} }
func TestGetFloat64InvalidBoolProperty(t *testing.T) { func TestGetFloat64InvalidBoolProperty(t *testing.T) {
expected := float64(1337) expected := float64(1337)
values := map[Property]interface{}{ThresholdProperty: true} var properties properties = map[Property]interface{}{ThresholdProperty: true}
properties := properties{
values: values,
}
value := properties.getFloat64(ThresholdProperty, expected) value := properties.getFloat64(ThresholdProperty, expected)
assert.Equal(t, expected, value) assert.Equal(t, expected, value)
} }

View file

@ -9,19 +9,18 @@ import (
// Segment represent a single segment and it's configuration // Segment represent a single segment and it's configuration
type Segment struct { type Segment struct {
Type SegmentType `config:"type"` Type SegmentType `config:"type"`
Tips []string `config:"tips"` Tips []string `config:"tips"`
Style SegmentStyle `config:"style"` Style SegmentStyle `config:"style"`
PowerlineSymbol string `config:"powerline_symbol"` PowerlineSymbol string `config:"powerline_symbol"`
InvertPowerline bool `config:"invert_powerline"` InvertPowerline bool `config:"invert_powerline"`
Foreground string `config:"foreground"` Foreground string `config:"foreground"`
ForegroundTemplates []string `config:"foreground_templates"` ForegroundTemplates []string `config:"foreground_templates"`
Background string `config:"background"` Background string `config:"background"`
BackgroundTemplates []string `config:"background_templates"` BackgroundTemplates []string `config:"background_templates"`
LeadingDiamond string `config:"leading_diamond"` LeadingDiamond string `config:"leading_diamond"`
TrailingDiamond string `config:"trailing_diamond"` TrailingDiamond string `config:"trailing_diamond"`
Properties map[Property]interface{} `config:"properties"` Properties properties `config:"properties"`
props *properties
writer SegmentWriter writer SegmentWriter
stringValue string stringValue string
active bool active bool
@ -42,7 +41,7 @@ type SegmentTiming struct {
type SegmentWriter interface { type SegmentWriter interface {
enabled() bool enabled() bool
string() string string() string
init(props *properties, env environmentInfo) init(props properties, env environmentInfo)
} }
// SegmentStyle the syle of segment, for more information, see the constants // SegmentStyle the syle of segment, for more information, see the constants
@ -215,18 +214,12 @@ func (segment *Segment) shouldInvokeWithTip(tip string) bool {
} }
func (segment *Segment) foreground() string { func (segment *Segment) foreground() string {
color := segment.Foreground color := segment.Properties.getColor(ForegroundOverride, segment.Foreground)
if segment.props != nil {
color = segment.props.foreground
}
return segment.getColor(segment.ForegroundTemplates, color) return segment.getColor(segment.ForegroundTemplates, color)
} }
func (segment *Segment) background() string { func (segment *Segment) background() string {
color := segment.Background color := segment.Properties.getColor(BackgroundOverride, segment.Background)
if segment.props != nil {
color = segment.props.background
}
return segment.getColor(segment.BackgroundTemplates, color) return segment.getColor(segment.BackgroundTemplates, color)
} }
@ -274,14 +267,8 @@ func (segment *Segment) mapSegmentWithWriter(env environmentInfo) error {
WinReg: &winreg{}, WinReg: &winreg{},
} }
if writer, ok := functions[segment.Type]; ok { if writer, ok := functions[segment.Type]; ok {
props := &properties{ writer.init(segment.Properties, env)
values: segment.Properties,
foreground: segment.Foreground,
background: segment.Background,
}
writer.init(props, env)
segment.writer = writer segment.writer = writer
segment.props = props
return nil return nil
} }
return errors.New("unable to map writer") return errors.New("unable to map writer")

View file

@ -8,7 +8,7 @@ func (a *angular) string() string {
return a.language.string() return a.language.string()
} }
func (a *angular) init(props *properties, env environmentInfo) { func (a *angular) init(props properties, env environmentInfo) {
a.language = &language{ a.language = &language{
env: env, env: env,
props: props, props: props,

View file

@ -6,7 +6,7 @@ import (
) )
type aws struct { type aws struct {
props *properties props properties
env environmentInfo env environmentInfo
Profile string Profile string
Region string Region string
@ -16,7 +16,7 @@ const (
defaultUser = "default" defaultUser = "default"
) )
func (a *aws) init(props *properties, env environmentInfo) { func (a *aws) init(props properties, env environmentInfo) {
a.props = props a.props = props
a.env = env a.env = env
} }

View file

@ -54,13 +54,11 @@ func TestAWSSegment(t *testing.T) {
env.On("getenv", "AWS_CONFIG_FILE").Return(tc.ConfigFile) env.On("getenv", "AWS_CONFIG_FILE").Return(tc.ConfigFile)
env.On("getFileContent", "/usr/home/.aws/config").Return("") env.On("getFileContent", "/usr/home/.aws/config").Return("")
env.On("homeDir", nil).Return("/usr/home") env.On("homeDir", nil).Return("/usr/home")
props := &properties{ var props properties = map[Property]interface{}{
values: map[Property]interface{}{ DisplayDefault: tc.DisplayDefault,
DisplayDefault: tc.DisplayDefault,
},
} }
if tc.Template != "" { if tc.Template != "" {
props.values[SegmentTemplate] = tc.Template props[SegmentTemplate] = tc.Template
} }
aws := &aws{ aws := &aws{

View file

@ -6,7 +6,7 @@ import (
) )
type az struct { type az struct {
props *properties props properties
env environmentInfo env environmentInfo
EnvironmentName string `json:"environmentName"` EnvironmentName string `json:"environmentName"`
@ -47,7 +47,7 @@ func (a *az) string() string {
return text return text
} }
func (a *az) init(props *properties, env environmentInfo) { func (a *az) init(props properties, env environmentInfo) {
a.props = props a.props = props
a.env = env a.env = env
} }
@ -92,8 +92,8 @@ func (a *az) getFromAzCli() bool {
} }
if strings.Contains(output, updateConsentNeeded) { if strings.Contains(output, updateConsentNeeded) {
a.props.foreground = updateForeground a.props[ForegroundOverride] = updateForeground
a.props.background = updateBackground a.props[BackgroundOverride] = updateBackground
a.Name = updateMessage a.Name = updateMessage
return true return true
} }

View file

@ -8,7 +8,7 @@ func (az *azfunc) string() string {
return az.language.string() return az.language.string()
} }
func (az *azfunc) init(props *properties, env environmentInfo) { func (az *azfunc) init(props properties, env environmentInfo) {
az.language = &language{ az.language = &language{
env: env, env: env,
props: props, props: props,

View file

@ -140,10 +140,8 @@ func TestAzSegment(t *testing.T) {
}`, tc.CLIEnvironmentname, tc.CLISubscriptionID, tc.CLIAccountName, tc.CLIUserName), }`, tc.CLIEnvironmentname, tc.CLISubscriptionID, tc.CLIAccountName, tc.CLIUserName),
nil, nil,
) )
props := &properties{ var props properties = map[Property]interface{}{
values: map[Property]interface{}{ SegmentTemplate: tc.Template,
SegmentTemplate: tc.Template,
},
} }
az := &az{ az := &az{

View file

@ -7,7 +7,7 @@ import (
) )
type batt struct { type batt struct {
props *properties props properties
env environmentInfo env environmentInfo
battery.Battery battery.Battery
@ -118,7 +118,7 @@ func (b *batt) string() string {
return text return text
} }
func (b *batt) init(props *properties, env environmentInfo) { func (b *batt) init(props properties, env environmentInfo) {
b.props = props b.props = props
b.env = env b.env = env
} }

View file

@ -3,7 +3,7 @@ package main
import "strings" import "strings"
type command struct { type command struct {
props *properties props properties
env environmentInfo env environmentInfo
value string value string
} }
@ -48,7 +48,7 @@ func (c *command) string() string {
return c.value return c.value
} }
func (c *command) init(props *properties, env environmentInfo) { func (c *command) init(props properties, env environmentInfo) {
c.props = props c.props = props
c.env = env c.env = env
} }

View file

@ -14,10 +14,8 @@ func TestExecuteCommand(t *testing.T) {
env.init(&args{ env.init(&args{
Debug: &debug, Debug: &debug,
}) })
props := &properties{ var props properties = map[Property]interface{}{
values: map[Property]interface{}{ Command: "echo hello",
Command: "echo hello",
},
} }
c := &command{ c := &command{
props: props, props: props,
@ -34,10 +32,8 @@ func TestExecuteMultipleCommandsOrFirst(t *testing.T) {
env.init(&args{ env.init(&args{
Debug: &debug, Debug: &debug,
}) })
props := &properties{ var props properties = map[Property]interface{}{
values: map[Property]interface{}{ Command: "exit 1 || echo hello",
Command: "exit 1 || echo hello",
},
} }
c := &command{ c := &command{
props: props, props: props,
@ -54,10 +50,8 @@ func TestExecuteMultipleCommandsOrSecond(t *testing.T) {
env.init(&args{ env.init(&args{
Debug: &debug, Debug: &debug,
}) })
props := &properties{ var props properties = map[Property]interface{}{
values: map[Property]interface{}{ Command: "echo hello || echo world",
Command: "echo hello || echo world",
},
} }
c := &command{ c := &command{
props: props, props: props,
@ -74,10 +68,8 @@ func TestExecuteMultipleCommandsAnd(t *testing.T) {
env.init(&args{ env.init(&args{
Debug: &debug, Debug: &debug,
}) })
props := &properties{ var props properties = map[Property]interface{}{
values: map[Property]interface{}{ Command: "echo hello && echo world",
Command: "echo hello && echo world",
},
} }
c := &command{ c := &command{
props: props, props: props,
@ -94,10 +86,8 @@ func TestExecuteSingleCommandEmpty(t *testing.T) {
env.init(&args{ env.init(&args{
Debug: &debug, Debug: &debug,
}) })
props := &properties{ var props properties = map[Property]interface{}{
values: map[Property]interface{}{ Command: "",
Command: "",
},
} }
c := &command{ c := &command{
props: props, props: props,
@ -113,7 +103,7 @@ func TestExecuteSingleCommandNoCommandProperty(t *testing.T) {
env.init(&args{ env.init(&args{
Debug: &debug, Debug: &debug,
}) })
props := &properties{} var props properties
c := &command{ c := &command{
props: props, props: props,
env: env, env: env,
@ -129,10 +119,8 @@ func TestExecuteMultipleCommandsAndDisabled(t *testing.T) {
env.init(&args{ env.init(&args{
Debug: &debug, Debug: &debug,
}) })
props := &properties{ var props properties = map[Property]interface{}{
values: map[Property]interface{}{ Command: "echo && echo",
Command: "echo && echo",
},
} }
c := &command{ c := &command{
props: props, props: props,
@ -148,10 +136,8 @@ func TestExecuteMultipleCommandsOrDisabled(t *testing.T) {
env.init(&args{ env.init(&args{
Debug: &debug, Debug: &debug,
}) })
props := &properties{ var props properties = map[Property]interface{}{
values: map[Property]interface{}{ Command: "echo|| echo",
Command: "echo|| echo",
},
} }
c := &command{ c := &command{
props: props, props: props,

View file

@ -8,7 +8,7 @@ func (c *crystal) string() string {
return c.language.string() return c.language.string()
} }
func (c *crystal) init(props *properties, env environmentInfo) { func (c *crystal) init(props properties, env environmentInfo) {
c.language = &language{ c.language = &language{
env: env, env: env,
props: props, props: props,

View file

@ -8,7 +8,7 @@ func (d *dart) string() string {
return d.language.string() return d.language.string()
} }
func (d *dart) init(props *properties, env environmentInfo) { func (d *dart) init(props properties, env environmentInfo) {
d.language = &language{ d.language = &language{
env: env, env: env,
props: props, props: props,

View file

@ -8,19 +8,26 @@ import (
"github.com/distatus/battery" "github.com/distatus/battery"
) )
// Segment
const (
BackgroundOverride Property = "background"
ForegroundOverride Property = "foreground"
)
// Properties // Properties
func (p *properties) getOneOfBool(property, legacyProperty Property) bool { func (p properties) getOneOfBool(property, legacyProperty Property) bool {
_, found := p.values[legacyProperty] _, found := p[legacyProperty]
if found { if found {
return p.getBool(legacyProperty, false) return p.getBool(legacyProperty, false)
} }
return p.getBool(property, false) return p.getBool(property, false)
} }
func (p *properties) hasOneOf(properties ...Property) bool { func (p properties) hasOneOf(properties ...Property) bool {
for _, property := range properties { for _, property := range properties {
if _, found := p.values[property]; found { if _, found := p[property]; found {
return true return true
} }
} }
@ -100,9 +107,9 @@ func (g *git) deprecatedString(statusColorsEnabled bool) string {
func (g *git) SetStatusColor() { func (g *git) SetStatusColor() {
if g.props.getBool(ColorBackground, true) { if g.props.getBool(ColorBackground, true) {
g.props.background = g.getStatusColor(g.props.background) g.props[BackgroundOverride] = g.getStatusColor(g.props.getColor(BackgroundOverride, ""))
} else { } else {
g.props.foreground = g.getStatusColor(g.props.foreground) g.props[ForegroundOverride] = g.getStatusColor(g.props.getColor(ForegroundOverride, ""))
} }
} }
@ -121,26 +128,25 @@ func (g *git) getStatusColor(defaultValue string) string {
func (g *git) getStatusDetailString(status *GitStatus, color, icon Property, defaultIcon string) string { func (g *git) getStatusDetailString(status *GitStatus, color, icon Property, defaultIcon string) string {
prefix := g.props.getString(icon, defaultIcon) prefix := g.props.getString(icon, defaultIcon)
foregroundColor := g.props.getColor(color, g.props.foreground) foregroundColor := g.props.getColor(color, g.props.getColor(ForegroundOverride, ""))
if !g.props.getBool(DisplayStatusDetail, true) { detail := ""
return g.colorStatusString(prefix, "", foregroundColor) if g.props.getBool(DisplayStatusDetail, true) {
detail = status.String()
} }
return g.colorStatusString(prefix, status.String(), foregroundColor) statusStr := g.colorStatusString(prefix, detail, foregroundColor)
return strings.TrimSpace(statusStr)
} }
func (g *git) colorStatusString(prefix, status, color string) string { func (g *git) colorStatusString(prefix, status, color string) string {
if color == g.props.foreground && len(status) == 0 { if len(color) == 0 {
return prefix
}
if color == g.props.foreground {
return fmt.Sprintf("%s %s", prefix, status) return fmt.Sprintf("%s %s", prefix, status)
} }
if strings.Contains(prefix, "</>") {
return fmt.Sprintf("%s <%s>%s</>", prefix, color, status)
}
if len(status) == 0 { if len(status) == 0 {
return fmt.Sprintf("<%s>%s</>", color, prefix) return fmt.Sprintf("<%s>%s</>", color, prefix)
} }
if strings.Contains(prefix, "</>") {
return fmt.Sprintf("%s <%s>%s</>", prefix, color, status)
}
return fmt.Sprintf("<%s>%s %s</>", color, prefix, status) return fmt.Sprintf("<%s>%s %s</>", color, prefix, status)
} }
@ -162,10 +168,10 @@ const (
func (e *exit) deprecatedString() string { func (e *exit) deprecatedString() string {
colorBackground := e.props.getBool(ColorBackground, false) colorBackground := e.props.getBool(ColorBackground, false)
if e.Code != 0 && !colorBackground { if e.Code != 0 && !colorBackground {
e.props.foreground = e.props.getColor(ErrorColor, e.props.foreground) e.props[ForegroundOverride] = e.props.getColor(ErrorColor, e.props.getColor(ForegroundOverride, ""))
} }
if e.Code != 0 && colorBackground { if e.Code != 0 && colorBackground {
e.props.background = e.props.getColor(ErrorColor, e.props.background) e.props[BackgroundOverride] = e.props.getColor(ErrorColor, e.props.getColor(BackgroundOverride, ""))
} }
if e.Code == 0 { if e.Code == 0 {
return e.props.getString(SuccessIcon, "") return e.props.getString(SuccessIcon, "")
@ -212,9 +218,9 @@ func (b *batt) colorSegment() {
} }
colorBackground := b.props.getBool(ColorBackground, false) colorBackground := b.props.getBool(ColorBackground, false)
if colorBackground { if colorBackground {
b.props.background = b.props.getColor(colorProperty, b.props.background) b.props[BackgroundOverride] = b.props.getColor(colorProperty, b.props.getColor(BackgroundOverride, ""))
} else { } else {
b.props.foreground = b.props.getColor(colorProperty, b.props.foreground) b.props[ForegroundOverride] = b.props.getColor(colorProperty, b.props.getColor(ForegroundOverride, ""))
} }
} }

View file

@ -16,11 +16,7 @@ func TestGetStatusDetailStringDefault(t *testing.T) {
Changed: true, Changed: true,
Added: 1, Added: 1,
} }
g := &git{ g := &git{}
props: &properties{
foreground: "#111111",
},
}
assert.Equal(t, expected, g.getStatusDetailString(status, WorkingColor, LocalWorkingIcon, "icon")) assert.Equal(t, expected, g.getStatusDetailString(status, WorkingColor, LocalWorkingIcon, "icon"))
} }
@ -30,13 +26,11 @@ func TestGetStatusDetailStringDefaultColorOverride(t *testing.T) {
Changed: true, Changed: true,
Added: 1, Added: 1,
} }
var props properties = map[Property]interface{}{
WorkingColor: "#123456",
}
g := &git{ g := &git{
props: &properties{ props: props,
values: map[Property]interface{}{
WorkingColor: "#123456",
},
foreground: "#111111",
},
} }
assert.Equal(t, expected, g.getStatusDetailString(status, WorkingColor, LocalWorkingIcon, "icon")) assert.Equal(t, expected, g.getStatusDetailString(status, WorkingColor, LocalWorkingIcon, "icon"))
} }
@ -47,14 +41,12 @@ func TestGetStatusDetailStringDefaultColorOverrideAndIconColorOverride(t *testin
Changed: true, Changed: true,
Added: 1, Added: 1,
} }
var props properties = map[Property]interface{}{
WorkingColor: "#123456",
LocalWorkingIcon: "<#789123>work</>",
}
g := &git{ g := &git{
props: &properties{ props: props,
values: map[Property]interface{}{
WorkingColor: "#123456",
LocalWorkingIcon: "<#789123>work</>",
},
foreground: "#111111",
},
} }
assert.Equal(t, expected, g.getStatusDetailString(status, WorkingColor, LocalWorkingIcon, "icon")) assert.Equal(t, expected, g.getStatusDetailString(status, WorkingColor, LocalWorkingIcon, "icon"))
} }
@ -65,14 +57,12 @@ func TestGetStatusDetailStringDefaultColorOverrideNoIconColorOverride(t *testing
Changed: true, Changed: true,
Added: 1, Added: 1,
} }
var props properties = map[Property]interface{}{
WorkingColor: "#123456",
LocalWorkingIcon: "work",
}
g := &git{ g := &git{
props: &properties{ props: props,
values: map[Property]interface{}{
WorkingColor: "#123456",
LocalWorkingIcon: "work",
},
foreground: "#111111",
},
} }
assert.Equal(t, expected, g.getStatusDetailString(status, WorkingColor, LocalWorkingIcon, "icon")) assert.Equal(t, expected, g.getStatusDetailString(status, WorkingColor, LocalWorkingIcon, "icon"))
} }
@ -83,13 +73,11 @@ func TestGetStatusDetailStringNoStatus(t *testing.T) {
Changed: true, Changed: true,
Added: 1, Added: 1,
} }
var props properties = map[Property]interface{}{
DisplayStatusDetail: false,
}
g := &git{ g := &git{
props: &properties{ props: props,
values: map[Property]interface{}{
DisplayStatusDetail: false,
},
foreground: "#111111",
},
} }
assert.Equal(t, expected, g.getStatusDetailString(status, WorkingColor, LocalWorkingIcon, "icon")) assert.Equal(t, expected, g.getStatusDetailString(status, WorkingColor, LocalWorkingIcon, "icon"))
} }
@ -100,26 +88,23 @@ func TestGetStatusDetailStringNoStatusColorOverride(t *testing.T) {
Changed: true, Changed: true,
Added: 1, Added: 1,
} }
var props properties = map[Property]interface{}{
DisplayStatusDetail: false,
WorkingColor: "#123456",
}
g := &git{ g := &git{
props: &properties{ props: props,
values: map[Property]interface{}{
DisplayStatusDetail: false,
WorkingColor: "#123456",
},
foreground: "#111111",
},
} }
assert.Equal(t, expected, g.getStatusDetailString(status, WorkingColor, LocalWorkingIcon, "icon")) assert.Equal(t, expected, g.getStatusDetailString(status, WorkingColor, LocalWorkingIcon, "icon"))
} }
func TestGetStatusColorLocalChangesStaging(t *testing.T) { func TestGetStatusColorLocalChangesStaging(t *testing.T) {
expected := changesColor expected := changesColor
var props properties = map[Property]interface{}{
LocalChangesColor: expected,
}
g := &git{ g := &git{
props: &properties{ props: props,
values: map[Property]interface{}{
LocalChangesColor: expected,
},
},
Staging: &GitStatus{ Staging: &GitStatus{
Changed: true, Changed: true,
}, },
@ -129,120 +114,109 @@ func TestGetStatusColorLocalChangesStaging(t *testing.T) {
func TestGetStatusColorLocalChangesWorking(t *testing.T) { func TestGetStatusColorLocalChangesWorking(t *testing.T) {
expected := changesColor expected := changesColor
var props properties = map[Property]interface{}{
LocalChangesColor: expected,
}
g := &git{ g := &git{
props: props,
Staging: &GitStatus{}, Staging: &GitStatus{},
Working: &GitStatus{ Working: &GitStatus{
Changed: true, Changed: true,
}, },
props: &properties{
values: map[Property]interface{}{
LocalChangesColor: expected,
},
},
} }
assert.Equal(t, expected, g.getStatusColor("#fg1111")) assert.Equal(t, expected, g.getStatusColor("#fg1111"))
} }
func TestGetStatusColorAheadAndBehind(t *testing.T) { func TestGetStatusColorAheadAndBehind(t *testing.T) {
expected := changesColor expected := changesColor
var props properties = map[Property]interface{}{
AheadAndBehindColor: expected,
}
g := &git{ g := &git{
props: props,
Staging: &GitStatus{}, Staging: &GitStatus{},
Working: &GitStatus{}, Working: &GitStatus{},
Ahead: 1, Ahead: 1,
Behind: 3, Behind: 3,
props: &properties{
values: map[Property]interface{}{
AheadAndBehindColor: expected,
},
},
} }
assert.Equal(t, expected, g.getStatusColor("#fg1111")) assert.Equal(t, expected, g.getStatusColor("#fg1111"))
} }
func TestGetStatusColorAhead(t *testing.T) { func TestGetStatusColorAhead(t *testing.T) {
expected := changesColor expected := changesColor
var props properties = map[Property]interface{}{
AheadColor: expected,
}
g := &git{ g := &git{
props: props,
Staging: &GitStatus{}, Staging: &GitStatus{},
Working: &GitStatus{}, Working: &GitStatus{},
Ahead: 1, Ahead: 1,
Behind: 0, Behind: 0,
props: &properties{
values: map[Property]interface{}{
AheadColor: expected,
},
},
} }
assert.Equal(t, expected, g.getStatusColor("#fg1111")) assert.Equal(t, expected, g.getStatusColor("#fg1111"))
} }
func TestGetStatusColorBehind(t *testing.T) { func TestGetStatusColorBehind(t *testing.T) {
expected := changesColor expected := changesColor
var props properties = map[Property]interface{}{
BehindColor: expected,
}
g := &git{ g := &git{
props: props,
Staging: &GitStatus{}, Staging: &GitStatus{},
Working: &GitStatus{}, Working: &GitStatus{},
Ahead: 0, Ahead: 0,
Behind: 5, Behind: 5,
props: &properties{
values: map[Property]interface{}{
BehindColor: expected,
},
},
} }
assert.Equal(t, expected, g.getStatusColor("#fg1111")) assert.Equal(t, expected, g.getStatusColor("#fg1111"))
} }
func TestGetStatusColorDefault(t *testing.T) { func TestGetStatusColorDefault(t *testing.T) {
expected := changesColor expected := changesColor
var props properties = map[Property]interface{}{
BehindColor: changesColor,
}
g := &git{ g := &git{
props: props,
Staging: &GitStatus{}, Staging: &GitStatus{},
Working: &GitStatus{}, Working: &GitStatus{},
Ahead: 0, Ahead: 0,
Behind: 0, Behind: 0,
props: &properties{
values: map[Property]interface{}{
BehindColor: changesColor,
},
},
} }
assert.Equal(t, expected, g.getStatusColor(expected)) assert.Equal(t, expected, g.getStatusColor(expected))
} }
func TestSetStatusColorForeground(t *testing.T) { func TestSetStatusColorForeground(t *testing.T) {
expected := changesColor expected := changesColor
var props properties = map[Property]interface{}{
LocalChangesColor: changesColor,
ColorBackground: false,
}
g := &git{ g := &git{
props: props,
Staging: &GitStatus{ Staging: &GitStatus{
Changed: true, Changed: true,
}, },
props: &properties{
values: map[Property]interface{}{
LocalChangesColor: changesColor,
ColorBackground: false,
},
foreground: "#ffffff",
background: "#111111",
},
} }
g.SetStatusColor() g.SetStatusColor()
assert.Equal(t, expected, g.props.foreground) assert.Equal(t, expected, g.props[ForegroundOverride])
} }
func TestSetStatusColorBackground(t *testing.T) { func TestSetStatusColorBackground(t *testing.T) {
expected := changesColor expected := changesColor
var props properties = map[Property]interface{}{
LocalChangesColor: changesColor,
ColorBackground: true,
}
g := &git{ g := &git{
props: props,
Staging: &GitStatus{ Staging: &GitStatus{
Changed: true, Changed: true,
}, },
props: &properties{
values: map[Property]interface{}{
LocalChangesColor: changesColor,
ColorBackground: true,
},
foreground: "#ffffff",
background: "#111111",
},
} }
g.SetStatusColor() g.SetStatusColor()
assert.Equal(t, expected, g.props.background) assert.Equal(t, expected, g.props[BackgroundOverride])
} }
func TestStatusColorsWithoutDisplayStatus(t *testing.T) { func TestStatusColorsWithoutDisplayStatus(t *testing.T) {
@ -251,15 +225,14 @@ func TestStatusColorsWithoutDisplayStatus(t *testing.T) {
status: "## main...origin/main [ahead 33]\n M myfile", status: "## main...origin/main [ahead 33]\n M myfile",
} }
g := setupHEADContextEnv(context) g := setupHEADContextEnv(context)
g.props = &properties{ var props properties = map[Property]interface{}{
values: map[Property]interface{}{ DisplayStatus: false,
DisplayStatus: false, StatusColorsEnabled: true,
StatusColorsEnabled: true, LocalChangesColor: expected,
LocalChangesColor: expected,
},
} }
g.props = props
g.string() g.string()
assert.Equal(t, expected, g.props.background) assert.Equal(t, expected, g.props[BackgroundOverride])
} }
// EXIT Segement // EXIT Segement
@ -286,15 +259,11 @@ func TestExitWriterDeprecatedString(t *testing.T) {
for _, tc := range cases { for _, tc := range cases {
env := new(MockedEnvironment) env := new(MockedEnvironment)
env.On("lastErrorCode", nil).Return(tc.ExitCode) env.On("lastErrorCode", nil).Return(tc.ExitCode)
props := &properties{ var props properties = map[Property]interface{}{
foreground: "#111111", SuccessIcon: tc.SuccessIcon,
background: "#ffffff", ErrorIcon: tc.ErrorIcon,
values: map[Property]interface{}{ DisplayExitCode: tc.DisplayExitCode,
SuccessIcon: tc.SuccessIcon, AlwaysNumeric: tc.AlwaysNumeric,
ErrorIcon: tc.ErrorIcon,
DisplayExitCode: tc.DisplayExitCode,
AlwaysNumeric: tc.AlwaysNumeric,
},
} }
e := &exit{ e := &exit{
env: env, env: env,
@ -394,26 +363,22 @@ func TestBatterySegmentSingle(t *testing.T) {
for _, tc := range cases { for _, tc := range cases {
env := &MockedEnvironment{} env := &MockedEnvironment{}
props := &properties{ var props properties = map[Property]interface{}{
background: "#111111", ChargingIcon: "charging ",
foreground: "#ffffff", ChargedIcon: "charged ",
values: map[Property]interface{}{ DischargingIcon: "going down ",
ChargingIcon: "charging ", DischargingColor: dischargingColor,
ChargedIcon: "charged ", ChargedColor: chargedColor,
DischargingIcon: "going down ", ChargingColor: chargingColor,
DischargingColor: dischargingColor, ColorBackground: tc.ColorBackground,
ChargedColor: chargedColor, DisplayError: tc.DisplayError,
ChargingColor: chargingColor,
ColorBackground: tc.ColorBackground,
DisplayError: tc.DisplayError,
},
} }
// default values // default values
if tc.DisableCharging { if tc.DisableCharging {
props.values[DisplayCharging] = false props[DisplayCharging] = false
} }
if tc.DisableCharged { if tc.DisableCharged {
props.values[DisplayCharged] = false props[DisplayCharged] = false
} }
env.On("getBatteryInfo", nil).Return(tc.Batteries, tc.Error) env.On("getBatteryInfo", nil).Return(tc.Batteries, tc.Error)
b := &batt{ b := &batt{
@ -429,9 +394,9 @@ func TestBatterySegmentSingle(t *testing.T) {
if len(tc.ExpectedColor) == 0 { if len(tc.ExpectedColor) == 0 {
continue continue
} }
actualColor := b.props.foreground actualColor := b.props[ForegroundOverride]
if tc.ColorBackground { if tc.ColorBackground {
actualColor = b.props.background actualColor = b.props[BackgroundOverride]
} }
assert.Equal(t, tc.ExpectedColor, actualColor, tc.Case) assert.Equal(t, tc.ExpectedColor, actualColor, tc.Case)
} }

View file

@ -21,7 +21,7 @@ func (d *dotnet) string() string {
return version return version
} }
func (d *dotnet) init(props *properties, env environmentInfo) { func (d *dotnet) init(props properties, env environmentInfo) {
d.language = &language{ d.language = &language{
env: env, env: env,
props: props, props: props,

View file

@ -28,11 +28,9 @@ func bootStrapDotnetTest(args *dotnetArgs) *dotnet {
env.On("getPathSeperator", nil).Return("") env.On("getPathSeperator", nil).Return("")
env.On("getcwd", nil).Return("/usr/home/project") env.On("getcwd", nil).Return("/usr/home/project")
env.On("homeDir", nil).Return("/usr/home") env.On("homeDir", nil).Return("/usr/home")
props := &properties{ var props properties = map[Property]interface{}{
values: map[Property]interface{}{ DisplayVersion: args.displayVersion,
DisplayVersion: args.displayVersion, UnsupportedDotnetVersionIcon: args.unsupportedIcon,
UnsupportedDotnetVersionIcon: args.unsupportedIcon,
},
} }
dotnet := &dotnet{} dotnet := &dotnet{}
dotnet.init(props, env) dotnet.init(props, env)

View file

@ -1,7 +1,7 @@
package main package main
type envvar struct { type envvar struct {
props *properties props properties
env environmentInfo env environmentInfo
Value string Value string
} }
@ -34,7 +34,7 @@ func (e *envvar) string() string {
return text return text
} }
func (e *envvar) init(props *properties, env environmentInfo) { func (e *envvar) init(props properties, env environmentInfo) {
e.props = props e.props = props
e.env = env e.env = env
} }

View file

@ -11,15 +11,12 @@ func TestEnvvarAvailable(t *testing.T) {
expected := "derp" expected := "derp"
env := new(MockedEnvironment) env := new(MockedEnvironment)
env.On("getenv", name).Return(expected) env.On("getenv", name).Return(expected)
props := &properties{ e := &envvar{
values: map[Property]interface{}{ env: env,
props: map[Property]interface{}{
VarName: name, VarName: name,
}, },
} }
e := &envvar{
env: env,
props: props,
}
assert.True(t, e.enabled()) assert.True(t, e.enabled())
assert.Equal(t, expected, e.string()) assert.Equal(t, expected, e.string())
} }
@ -29,14 +26,11 @@ func TestEnvvarNotAvailable(t *testing.T) {
expected := "" expected := ""
env := new(MockedEnvironment) env := new(MockedEnvironment)
env.On("getenv", name).Return(expected) env.On("getenv", name).Return(expected)
props := &properties{ e := &envvar{
values: map[Property]interface{}{ env: env,
props: map[Property]interface{}{
VarName: name, VarName: name,
}, },
} }
e := &envvar{
env: env,
props: props,
}
assert.False(t, e.enabled()) assert.False(t, e.enabled())
} }

View file

@ -9,7 +9,7 @@ import (
) )
type executiontime struct { type executiontime struct {
props *properties props properties
env environmentInfo env environmentInfo
FormattedMs string FormattedMs string
@ -63,7 +63,7 @@ func (t *executiontime) string() string {
return t.FormattedMs return t.FormattedMs
} }
func (t *executiontime) init(props *properties, env environmentInfo) { func (t *executiontime) init(props properties, env environmentInfo) {
t.props = props t.props = props
t.env = env t.env = env
} }

View file

@ -28,10 +28,8 @@ func TestExecutionTimeWriterDefaultThresholdDisabled(t *testing.T) {
func TestExecutionTimeWriterCustomThresholdEnabled(t *testing.T) { func TestExecutionTimeWriterCustomThresholdEnabled(t *testing.T) {
env := new(MockedEnvironment) env := new(MockedEnvironment)
env.On("executionTime", nil).Return(99) env.On("executionTime", nil).Return(99)
props := &properties{ var props properties = map[Property]interface{}{
values: map[Property]interface{}{ ThresholdProperty: float64(10),
ThresholdProperty: float64(10),
},
} }
executionTime := &executiontime{ executionTime := &executiontime{
env: env, env: env,
@ -43,10 +41,8 @@ func TestExecutionTimeWriterCustomThresholdEnabled(t *testing.T) {
func TestExecutionTimeWriterCustomThresholdDisabled(t *testing.T) { func TestExecutionTimeWriterCustomThresholdDisabled(t *testing.T) {
env := new(MockedEnvironment) env := new(MockedEnvironment)
env.On("executionTime", nil).Return(99) env.On("executionTime", nil).Return(99)
props := &properties{ var props properties = map[Property]interface{}{
values: map[Property]interface{}{ ThresholdProperty: float64(100),
ThresholdProperty: float64(100),
},
} }
executionTime := &executiontime{ executionTime := &executiontime{
env: env, env: env,

View file

@ -3,7 +3,7 @@ package main
import "strconv" import "strconv"
type exit struct { type exit struct {
props *properties props properties
env environmentInfo env environmentInfo
Code int Code int
@ -21,7 +21,7 @@ func (e *exit) string() string {
return e.getFormattedText() return e.getFormattedText()
} }
func (e *exit) init(props *properties, env environmentInfo) { func (e *exit) init(props properties, env environmentInfo) {
e.props = props e.props = props
e.env = env e.env = env
} }

View file

@ -76,10 +76,8 @@ func TestExitWriterTemplateString(t *testing.T) {
for _, tc := range cases { for _, tc := range cases {
env := new(MockedEnvironment) env := new(MockedEnvironment)
env.On("lastErrorCode", nil).Return(tc.ExitCode) env.On("lastErrorCode", nil).Return(tc.ExitCode)
props := &properties{ var props properties = map[Property]interface{}{
values: map[Property]interface{}{ SegmentTemplate: tc.Template,
SegmentTemplate: tc.Template,
},
} }
e := &exit{ e := &exit{
env: env, env: env,

View file

@ -63,7 +63,7 @@ func (s *GitStatus) String() string {
} }
type git struct { type git struct {
props *properties props properties
env environmentInfo env environmentInfo
Working *GitStatus Working *GitStatus
@ -174,10 +174,7 @@ func (g *git) enabled() bool {
} }
func (g *git) shouldIgnoreRootRepository(rootDir string) bool { func (g *git) shouldIgnoreRootRepository(rootDir string) bool {
if g.props == nil || g.props.values == nil { value, ok := g.props[ExcludeFolders]
return false
}
value, ok := g.props.values[ExcludeFolders]
if !ok { if !ok {
return false return false
} }
@ -226,7 +223,7 @@ func (g *git) templateString(segmentTemplate string) string {
return text return text
} }
func (g *git) init(props *properties, env environmentInfo) { func (g *git) init(props properties, env environmentInfo) {
g.props = props g.props = props
g.env = env g.env = env
} }

View file

@ -555,14 +555,12 @@ func TestGitUpstream(t *testing.T) {
env.On("runCommand", "git", []string{"-C", "", "--no-optional-locks", "-c", "core.quotepath=false", env.On("runCommand", "git", []string{"-C", "", "--no-optional-locks", "-c", "core.quotepath=false",
"-c", "color.status=false", "remote", "get-url", "origin"}).Return(tc.Upstream, nil) "-c", "color.status=false", "remote", "get-url", "origin"}).Return(tc.Upstream, nil)
env.On("getRuntimeGOOS", nil).Return("unix") env.On("getRuntimeGOOS", nil).Return("unix")
props := &properties{ var props properties = map[Property]interface{}{
values: map[Property]interface{}{ GithubIcon: "GH",
GithubIcon: "GH", GitlabIcon: "GL",
GitlabIcon: "GL", BitbucketIcon: "BB",
BitbucketIcon: "BB", AzureDevOpsIcon: "AD",
AzureDevOpsIcon: "AD", GitIcon: "G",
GitIcon: "G",
},
} }
g := &git{ g := &git{
env: env, env: env,
@ -591,15 +589,14 @@ func TestGetBranchStatus(t *testing.T) {
} }
for _, tc := range cases { for _, tc := range cases {
var props properties = map[Property]interface{}{
BranchAheadIcon: "up",
BranchBehindIcon: "down",
BranchIdenticalIcon: "equal",
BranchGoneIcon: "gone",
}
g := &git{ g := &git{
props: &properties{ props: props,
values: map[Property]interface{}{
BranchAheadIcon: "up",
BranchBehindIcon: "down",
BranchIdenticalIcon: "equal",
BranchGoneIcon: "gone",
},
},
Ahead: tc.Ahead, Ahead: tc.Ahead,
Behind: tc.Behind, Behind: tc.Behind,
Upstream: tc.Upstream, Upstream: tc.Upstream,
@ -621,7 +618,7 @@ func TestShouldIgnoreRootRepository(t *testing.T) {
} }
for _, tc := range cases { for _, tc := range cases {
props := map[Property]interface{}{ var props properties = map[Property]interface{}{
ExcludeFolders: []string{ ExcludeFolders: []string{
"/home/bill", "/home/bill",
"/home/gates.*", "/home/gates.*",
@ -631,10 +628,8 @@ func TestShouldIgnoreRootRepository(t *testing.T) {
env.On("homeDir", nil).Return("/home/bill") env.On("homeDir", nil).Return("/home/bill")
env.On("getRuntimeGOOS", nil).Return(windowsPlatform) env.On("getRuntimeGOOS", nil).Return(windowsPlatform)
git := &git{ git := &git{
props: &properties{ props: props,
values: props, env: env,
},
env: env,
} }
got := git.shouldIgnoreRootRepository(tc.Dir) got := git.shouldIgnoreRootRepository(tc.Dir)
assert.Equal(t, tc.Expected, got, tc.Case) assert.Equal(t, tc.Expected, got, tc.Case)
@ -656,12 +651,11 @@ func TestTruncateBranch(t *testing.T) {
} }
for _, tc := range cases { for _, tc := range cases {
var props properties = map[Property]interface{}{
BranchMaxLength: tc.MaxLength,
}
g := &git{ g := &git{
props: &properties{ props: props,
values: map[Property]interface{}{
BranchMaxLength: tc.MaxLength,
},
},
} }
assert.Equal(t, tc.Expected, g.truncateBranch(tc.Branch), tc.Case) assert.Equal(t, tc.Expected, g.truncateBranch(tc.Branch), tc.Case)
} }
@ -683,13 +677,12 @@ func TestTruncateBranchWithSymbol(t *testing.T) {
} }
for _, tc := range cases { for _, tc := range cases {
var props properties = map[Property]interface{}{
BranchMaxLength: tc.MaxLength,
TruncateSymbol: tc.TruncateSymbol,
}
g := &git{ g := &git{
props: &properties{ props: props,
values: map[Property]interface{}{
BranchMaxLength: tc.MaxLength,
TruncateSymbol: tc.TruncateSymbol,
},
},
} }
assert.Equal(t, tc.Expected, g.truncateBranch(tc.Branch), tc.Case) assert.Equal(t, tc.Expected, g.truncateBranch(tc.Branch), tc.Case)
} }
@ -847,11 +840,10 @@ func TestGitTemplateString(t *testing.T) {
} }
for _, tc := range cases { for _, tc := range cases {
tc.Git.props = &properties{ var props properties = map[Property]interface{}{
values: map[Property]interface{}{ FetchStatus: true,
FetchStatus: true,
},
} }
tc.Git.props = props
assert.Equal(t, tc.Expected, tc.Git.templateString(tc.Template), tc.Case) assert.Equal(t, tc.Expected, tc.Git.templateString(tc.Template), tc.Case)
} }
} }

View file

@ -8,7 +8,7 @@ func (g *golang) string() string {
return g.language.string() return g.language.string()
} }
func (g *golang) init(props *properties, env environmentInfo) { func (g *golang) init(props properties, env environmentInfo) {
g.language = &language{ g.language = &language{
env: env, env: env,
props: props, props: props,

View file

@ -14,17 +14,15 @@ type mockedLanguageParams struct {
extension string extension string
} }
func getMockedLanguageEnv(params *mockedLanguageParams) (*MockedEnvironment, *properties) { func getMockedLanguageEnv(params *mockedLanguageParams) (*MockedEnvironment, properties) {
env := new(MockedEnvironment) env := new(MockedEnvironment)
env.On("hasCommand", params.cmd).Return(true) env.On("hasCommand", params.cmd).Return(true)
env.On("runCommand", params.cmd, []string{params.versionParam}).Return(params.versionOutput, nil) env.On("runCommand", params.cmd, []string{params.versionParam}).Return(params.versionOutput, nil)
env.On("hasFiles", params.extension).Return(true) env.On("hasFiles", params.extension).Return(true)
env.On("getcwd", nil).Return("/usr/home/project") env.On("getcwd", nil).Return("/usr/home/project")
env.On("homeDir", nil).Return("/usr/home") env.On("homeDir", nil).Return("/usr/home")
props := &properties{ var props properties = map[Property]interface{}{
values: map[Property]interface{}{ DisplayVersion: true,
DisplayVersion: true,
},
} }
return env, props return env, props
} }

View file

@ -10,7 +10,7 @@ func (j *java) string() string {
return j.language.string() return j.language.string()
} }
func (j *java) init(props *properties, env environmentInfo) { func (j *java) init(props properties, env environmentInfo) {
javaRegex := `(?: JRE)(?: \(.*\))? \((?P<version>(?P<major>[0-9]+)(?:\.(?P<minor>[0-9]+))?(?:\.(?P<patch>[0-9]+))?).*\),` javaRegex := `(?: JRE)(?: \(.*\))? \((?P<version>(?P<major>[0-9]+)(?:\.(?P<minor>[0-9]+))?(?:\.(?P<patch>[0-9]+))?).*\),`
javaCmd := &cmd{ javaCmd := &cmd{
executable: "java", executable: "java",

View file

@ -66,10 +66,8 @@ func TestJava(t *testing.T) {
} else { } else {
env.On("getenv", "JAVA_HOME").Return("") env.On("getenv", "JAVA_HOME").Return("")
} }
props := &properties{ var props properties = map[Property]interface{}{
values: map[Property]interface{}{ DisplayVersion: true,
DisplayVersion: true,
},
} }
j := &java{} j := &java{}
j.init(props, env) j.init(props, env)

View file

@ -8,7 +8,7 @@ func (j *julia) string() string {
return j.language.string() return j.language.string()
} }
func (j *julia) init(props *properties, env environmentInfo) { func (j *julia) init(props properties, env environmentInfo) {
j.language = &language{ j.language = &language{
env: env, env: env,
props: props, props: props,

View file

@ -5,7 +5,7 @@ import (
) )
type kubectl struct { type kubectl struct {
props *properties props properties
env environmentInfo env environmentInfo
Context string Context string
Namespace string Namespace string
@ -25,7 +25,7 @@ func (k *kubectl) string() string {
return text return text
} }
func (k *kubectl) init(props *properties, env environmentInfo) { func (k *kubectl) init(props properties, env environmentInfo) {
k.props = props k.props = props
k.env = env k.env = env
} }

View file

@ -29,11 +29,9 @@ func bootStrapKubectlTest(args *kubectlArgs) *kubectl {
env.On("runCommand", "kubectl", []string{"config", "view", "--minify", "--output", "jsonpath={..current-context},{..namespace}"}).Return(kubectlOut, kubectlErr) env.On("runCommand", "kubectl", []string{"config", "view", "--minify", "--output", "jsonpath={..current-context},{..namespace}"}).Return(kubectlOut, kubectlErr)
k := &kubectl{ k := &kubectl{
env: env, env: env,
props: &properties{ props: map[Property]interface{}{
values: map[Property]interface{}{ SegmentTemplate: args.template,
SegmentTemplate: args.template, DisplayError: args.displayError,
DisplayError: args.displayError,
},
}, },
} }
return k return k

View file

@ -65,7 +65,7 @@ func (c *cmd) buildVersionURL(text, template string) string {
} }
type language struct { type language struct {
props *properties props properties
env environmentInfo env environmentInfo
extensions []string extensions []string
commands []*cmd commands []*cmd
@ -234,8 +234,8 @@ func (l *language) setVersionFileMismatch() {
return return
} }
if l.props.getBool(ColorBackground, false) { if l.props.getBool(ColorBackground, false) {
l.props.background = l.props.getColor(VersionMismatchColor, l.props.background) l.props[BackgroundOverride] = l.props.getColor(VersionMismatchColor, l.props.getColor(BackgroundOverride, ""))
return return
} }
l.props.foreground = l.props.getColor(VersionMismatchColor, l.props.foreground) l.props[ForegroundOverride] = l.props.getColor(VersionMismatchColor, l.props.getColor(ForegroundOverride, ""))
} }

View file

@ -50,11 +50,8 @@ func bootStrapLanguageTest(args *languageArgs) *language {
} }
env.On("getcwd", nil).Return(cwd) env.On("getcwd", nil).Return(cwd)
env.On("homeDir", nil).Return(home) env.On("homeDir", nil).Return(home)
props := &properties{
values: args.properties,
}
l := &language{ l := &language{
props: props, props: args.properties,
env: env, env: env,
extensions: args.extensions, extensions: args.extensions,
commands: args.commands, commands: args.commands,
@ -549,9 +546,9 @@ func TestLanguageVersionMismatch(t *testing.T) {
assert.True(t, lang.enabled(), tc.Case) assert.True(t, lang.enabled(), tc.Case)
assert.Equal(t, universion, lang.string(), tc.Case) assert.Equal(t, universion, lang.string(), tc.Case)
if tc.ColorBackground { if tc.ColorBackground {
assert.Equal(t, tc.ExpectedColor, lang.props.background, tc.Case) assert.Equal(t, tc.ExpectedColor, lang.props[BackgroundOverride], tc.Case)
return return
} }
assert.Equal(t, tc.ExpectedColor, lang.props.foreground, tc.Case) assert.Equal(t, tc.ExpectedColor, lang.props.getColor(ForegroundOverride, ""), tc.Case)
} }
} }

View file

@ -5,7 +5,7 @@ import (
) )
type nbgv struct { type nbgv struct {
props *properties props properties
env environmentInfo env environmentInfo
nbgv *versionInfo nbgv *versionInfo
} }
@ -52,7 +52,7 @@ func (n *nbgv) string() string {
return text return text
} }
func (n *nbgv) init(props *properties, env environmentInfo) { func (n *nbgv) init(props properties, env environmentInfo) {
n.props = props n.props = props
n.env = env n.env = env
} }

View file

@ -62,10 +62,8 @@ func TestNbgv(t *testing.T) {
env.On("runCommand", "nbgv", []string{"get-version", "--format=json"}).Return(tc.Response, tc.Error) env.On("runCommand", "nbgv", []string{"get-version", "--format=json"}).Return(tc.Response, tc.Error)
nbgv := &nbgv{ nbgv := &nbgv{
env: env, env: env,
props: &properties{ props: map[Property]interface{}{
values: map[Property]interface{}{ SegmentTemplate: tc.SegmentTemplate,
SegmentTemplate: tc.SegmentTemplate,
},
}, },
} }
enabled := nbgv.enabled() enabled := nbgv.enabled()

View file

@ -8,7 +8,7 @@ import (
// segment struct, makes templating easier // segment struct, makes templating easier
type nightscout struct { type nightscout struct {
props *properties props properties
env environmentInfo env environmentInfo
NightscoutData NightscoutData
@ -148,7 +148,7 @@ func (ns *nightscout) getResult() (*NightscoutData, error) {
return data, nil return data, nil
} }
func (ns *nightscout) init(props *properties, env environmentInfo) { func (ns *nightscout) init(props properties, env environmentInfo) {
ns.props = props ns.props = props
ns.env = env ns.env = env
} }

View file

@ -130,11 +130,9 @@ func TestNSSegment(t *testing.T) {
for _, tc := range cases { for _, tc := range cases {
env := &MockedEnvironment{} env := &MockedEnvironment{}
props := &properties{ var props properties = map[Property]interface{}{
values: map[Property]interface{}{ CacheTimeout: tc.CacheTimeout,
CacheTimeout: tc.CacheTimeout, URL: "FAKE",
URL: "FAKE",
},
} }
cache := &MockedCache{} cache := &MockedCache{}
@ -145,7 +143,7 @@ func TestNSSegment(t *testing.T) {
env.On("cache", nil).Return(cache) env.On("cache", nil).Return(cache)
if tc.Template != "" { if tc.Template != "" {
props.values[SegmentTemplate] = tc.Template props[SegmentTemplate] = tc.Template
} }
ns := &nightscout{ ns := &nightscout{

View file

@ -21,7 +21,7 @@ func (n *node) string() string {
return fmt.Sprintf("%s%s", version, n.packageManagerIcon) return fmt.Sprintf("%s%s", version, n.packageManagerIcon)
} }
func (n *node) init(props *properties, env environmentInfo) { func (n *node) init(props properties, env environmentInfo) {
n.language = &language{ n.language = &language{
env: env, env: env,
props: props, props: props,

View file

@ -68,12 +68,10 @@ func TestNodeInContext(t *testing.T) {
node := &node{ node := &node{
language: &language{ language: &language{
env: env, env: env,
props: &properties{ props: map[Property]interface{}{
values: map[Property]interface{}{ YarnIcon: "yarn",
YarnIcon: "yarn", NPMIcon: "npm",
NPMIcon: "npm", DisplayPackageManager: tc.PkgMgrEnabled,
DisplayPackageManager: tc.PkgMgrEnabled,
},
}, },
}, },
} }

View file

@ -5,7 +5,7 @@ import (
) )
type osInfo struct { type osInfo struct {
props *properties props properties
env environmentInfo env environmentInfo
OS string OS string
} }
@ -145,7 +145,7 @@ func (n *osInfo) getDistroName(distro, defaultName string) string {
return n.props.getString(Linux, "\uF17C") return n.props.getString(Linux, "\uF17C")
} }
func (n *osInfo) init(props *properties, env environmentInfo) { func (n *osInfo) init(props properties, env environmentInfo) {
n.props = props n.props = props
n.env = env n.env = env
} }

View file

@ -64,8 +64,9 @@ func TestOSInfo(t *testing.T) {
env.On("getRuntimeGOOS", nil).Return(tc.GOOS) env.On("getRuntimeGOOS", nil).Return(tc.GOOS)
env.On("getenv", "WSL_DISTRO_NAME").Return(tc.WSLDistro) env.On("getenv", "WSL_DISTRO_NAME").Return(tc.WSLDistro)
env.On("getPlatform", nil).Return(tc.Platform) env.On("getPlatform", nil).Return(tc.Platform)
props := &properties{ osInfo := &osInfo{
values: map[Property]interface{}{ env: env,
props: map[Property]interface{}{
WSL: "WSL", WSL: "WSL",
WSLSeparator: " at ", WSLSeparator: " at ",
DisplayDistroName: tc.DisplayDistroName, DisplayDistroName: tc.DisplayDistroName,
@ -73,10 +74,6 @@ func TestOSInfo(t *testing.T) {
MacOS: "darwin", MacOS: "darwin",
}, },
} }
osInfo := &osInfo{
env: env,
props: props,
}
assert.Equal(t, tc.ExpectedString, osInfo.string(), tc.Case) assert.Equal(t, tc.ExpectedString, osInfo.string(), tc.Case)
if tc.WSLDistro != "" { if tc.WSLDistro != "" {
assert.Equal(t, tc.WSLDistro, osInfo.OS, tc.Case) assert.Equal(t, tc.WSLDistro, osInfo.OS, tc.Case)

View file

@ -6,7 +6,7 @@ import (
) )
type owm struct { type owm struct {
props *properties props properties
env environmentInfo env environmentInfo
Temperature float64 Temperature float64
Weather string Weather string
@ -168,7 +168,7 @@ func (d *owm) setStatus() error {
return nil return nil
} }
func (d *owm) init(props *properties, env environmentInfo) { func (d *owm) init(props properties, env environmentInfo) {
d.props = props d.props = props
d.env = env d.env = env
} }

View file

@ -51,19 +51,17 @@ func TestOWMSegmentSingle(t *testing.T) {
for _, tc := range cases { for _, tc := range cases {
env := &MockedEnvironment{} env := &MockedEnvironment{}
props := &properties{ var props properties = map[Property]interface{}{
values: map[Property]interface{}{ APIKey: "key",
APIKey: "key", Location: "AMSTERDAM,NL",
Location: "AMSTERDAM,NL", Units: "metric",
Units: "metric", CacheTimeout: 0,
CacheTimeout: 0,
},
} }
env.On("doGet", OWMAPIURL).Return([]byte(tc.JSONResponse), tc.Error) env.On("doGet", OWMAPIURL).Return([]byte(tc.JSONResponse), tc.Error)
if tc.Template != "" { if tc.Template != "" {
props.values[SegmentTemplate] = tc.Template props[SegmentTemplate] = tc.Template
} }
o := &owm{ o := &owm{
@ -182,14 +180,6 @@ func TestOWMSegmentIcons(t *testing.T) {
for _, tc := range cases { for _, tc := range cases {
env := &MockedEnvironment{} env := &MockedEnvironment{}
props := &properties{
values: map[Property]interface{}{
APIKey: "key",
Location: "AMSTERDAM,NL",
Units: "metric",
CacheTimeout: 0,
},
}
response := fmt.Sprintf(`{"weather":[{"icon":"%s"}],"main":{"temp":20}}`, tc.IconID) response := fmt.Sprintf(`{"weather":[{"icon":"%s"}],"main":{"temp":20}}`, tc.IconID)
expectedString := fmt.Sprintf("%s (20°C)", tc.ExpectedIconString) expectedString := fmt.Sprintf("%s (20°C)", tc.ExpectedIconString)
@ -197,8 +187,13 @@ func TestOWMSegmentIcons(t *testing.T) {
env.On("doGet", OWMAPIURL).Return([]byte(response), nil) env.On("doGet", OWMAPIURL).Return([]byte(response), nil)
o := &owm{ o := &owm{
props: props, props: map[Property]interface{}{
env: env, APIKey: "key",
Location: "AMSTERDAM,NL",
Units: "metric",
CacheTimeout: 0,
},
env: env,
} }
assert.Nil(t, o.setStatus()) assert.Nil(t, o.setStatus())
@ -208,26 +203,22 @@ func TestOWMSegmentIcons(t *testing.T) {
// test with hyperlink enabled // test with hyperlink enabled
for _, tc := range cases { for _, tc := range cases {
env := &MockedEnvironment{} env := &MockedEnvironment{}
props := &properties{
values: map[Property]interface{}{
APIKey: "key",
Location: "AMSTERDAM,NL",
Units: "metric",
CacheTimeout: 0,
EnableHyperlink: true,
},
}
response := fmt.Sprintf(`{"weather":[{"icon":"%s"}],"main":{"temp":20}}`, tc.IconID) response := fmt.Sprintf(`{"weather":[{"icon":"%s"}],"main":{"temp":20}}`, tc.IconID)
expectedString := fmt.Sprintf("[%s (20°C)](http://api.openweathermap.org/data/2.5/weather?q=AMSTERDAM,NL&units=metric&appid=key)", tc.ExpectedIconString) expectedString := fmt.Sprintf("[%s (20°C)](http://api.openweathermap.org/data/2.5/weather?q=AMSTERDAM,NL&units=metric&appid=key)", tc.ExpectedIconString)
env.On("doGet", OWMAPIURL).Return([]byte(response), nil) env.On("doGet", OWMAPIURL).Return([]byte(response), nil)
props.values[SegmentTemplate] = "[{{.Weather}} ({{.Temperature}}{{.UnitIcon}})]({{.URL}})"
o := &owm{ o := &owm{
props: props, props: map[Property]interface{}{
env: env, APIKey: "key",
Location: "AMSTERDAM,NL",
Units: "metric",
CacheTimeout: 0,
EnableHyperlink: true,
SegmentTemplate: "[{{.Weather}} ({{.Temperature}}{{.UnitIcon}})]({{.URL}})",
},
env: env,
} }
assert.Nil(t, o.setStatus()) assert.Nil(t, o.setStatus())
@ -240,16 +231,13 @@ func TestOWMSegmentFromCache(t *testing.T) {
env := &MockedEnvironment{} env := &MockedEnvironment{}
cache := &MockedCache{} cache := &MockedCache{}
props := &properties{ o := &owm{
values: map[Property]interface{}{ props: map[Property]interface{}{
APIKey: "key", APIKey: "key",
Location: "AMSTERDAM,NL", Location: "AMSTERDAM,NL",
Units: "metric", Units: "metric",
}, },
} env: env,
o := &owm{
props: props,
env: env,
} }
cache.On("get", "owm_response").Return(response, true) cache.On("get", "owm_response").Return(response, true)
cache.On("get", "owm_url").Return("http://api.openweathermap.org/data/2.5/weather?q=AMSTERDAM,NL&units=metric&appid=key", true) cache.On("get", "owm_url").Return("http://api.openweathermap.org/data/2.5/weather?q=AMSTERDAM,NL&units=metric&appid=key", true)
@ -266,20 +254,16 @@ func TestOWMSegmentFromCacheWithHyperlink(t *testing.T) {
env := &MockedEnvironment{} env := &MockedEnvironment{}
cache := &MockedCache{} cache := &MockedCache{}
props := &properties{
values: map[Property]interface{}{ o := &owm{
props: map[Property]interface{}{
APIKey: "key", APIKey: "key",
Location: "AMSTERDAM,NL", Location: "AMSTERDAM,NL",
Units: "metric", Units: "metric",
EnableHyperlink: true, EnableHyperlink: true,
SegmentTemplate: "[{{.Weather}} ({{.Temperature}}{{.UnitIcon}})]({{.URL}})",
}, },
} env: env,
props.values[SegmentTemplate] = "[{{.Weather}} ({{.Temperature}}{{.UnitIcon}})]({{.URL}})"
o := &owm{
props: props,
env: env,
} }
cache.On("get", "owm_response").Return(response, true) cache.On("get", "owm_response").Return(response, true)
cache.On("get", "owm_url").Return("http://api.openweathermap.org/data/2.5/weather?q=AMSTERDAM,NL&units=metric&appid=key", true) cache.On("get", "owm_url").Return("http://api.openweathermap.org/data/2.5/weather?q=AMSTERDAM,NL&units=metric&appid=key", true)

View file

@ -8,7 +8,7 @@ import (
) )
type path struct { type path struct {
props *properties props properties
env environmentInfo env environmentInfo
} }
@ -100,7 +100,7 @@ func (pt *path) formatWindowsDrive(pwd string) string {
return pwd + "\\" return pwd + "\\"
} }
func (pt *path) init(props *properties, env environmentInfo) { func (pt *path) init(props properties, env environmentInfo) {
pt.props = props pt.props = props
pt.env = env pt.env = env
} }

View file

@ -231,12 +231,6 @@ func TestRootLocationHome(t *testing.T) {
{Expected: "DRIVE:", HomePath: "/home/bill/", Pwd: "/usr/error/what", Pswd: "DRIVE:", PathSeperator: "/"}, {Expected: "DRIVE:", HomePath: "/home/bill/", Pwd: "/usr/error/what", Pswd: "DRIVE:", PathSeperator: "/"},
} }
for _, tc := range cases { for _, tc := range cases {
props := &properties{
values: map[Property]interface{}{
HomeIcon: tc.HomeIcon,
WindowsRegistryIcon: tc.RegistryIcon,
},
}
env := new(MockedEnvironment) env := new(MockedEnvironment)
env.On("homeDir", nil).Return(tc.HomePath) env.On("homeDir", nil).Return(tc.HomePath)
env.On("getcwd", nil).Return(tc.Pwd) env.On("getcwd", nil).Return(tc.Pwd)
@ -247,8 +241,11 @@ func TestRootLocationHome(t *testing.T) {
env.On("getPathSeperator", nil).Return(tc.PathSeperator) env.On("getPathSeperator", nil).Return(tc.PathSeperator)
env.On("getRuntimeGOOS", nil).Return("") env.On("getRuntimeGOOS", nil).Return("")
path := &path{ path := &path{
env: env, env: env,
props: props, props: map[Property]interface{}{
HomeIcon: tc.HomeIcon,
WindowsRegistryIcon: tc.RegistryIcon,
},
} }
got := path.rootLocation() got := path.rootLocation()
assert.EqualValues(t, tc.Expected, got) assert.EqualValues(t, tc.Expected, got)
@ -396,12 +393,10 @@ func TestAgnosterPathStyles(t *testing.T) {
env.On("getArgs", nil).Return(args) env.On("getArgs", nil).Return(args)
path := &path{ path := &path{
env: env, env: env,
props: &properties{ props: map[Property]interface{}{
values: map[Property]interface{}{ FolderSeparatorIcon: tc.FolderSeparatorIcon,
FolderSeparatorIcon: tc.FolderSeparatorIcon, Style: tc.Style,
Style: tc.Style, MaxDepth: tc.MaxDepth,
MaxDepth: tc.MaxDepth,
},
}, },
} }
got := path.string() got := path.string()
@ -513,17 +508,15 @@ func TestGetFullPath(t *testing.T) {
PSWD: &tc.Pswd, PSWD: &tc.Pswd,
} }
env.On("getArgs", nil).Return(args) env.On("getArgs", nil).Return(args)
props := &properties{ var props properties = map[Property]interface{}{
values: map[Property]interface{}{ Style: tc.Style,
Style: tc.Style, StackCountEnabled: tc.StackCountEnabled,
StackCountEnabled: tc.StackCountEnabled,
},
} }
if tc.FolderSeparatorIcon != "" { if tc.FolderSeparatorIcon != "" {
props.values[FolderSeparatorIcon] = tc.FolderSeparatorIcon props[FolderSeparatorIcon] = tc.FolderSeparatorIcon
} }
if tc.DisableMappedLocations { if tc.DisableMappedLocations {
props.values[MappedLocationsEnabled] = false props[MappedLocationsEnabled] = false
} }
path := &path{ path := &path{
env: env, env: env,
@ -563,11 +556,9 @@ func TestGetFullPathCustomMappedLocations(t *testing.T) {
env.On("getArgs", nil).Return(args) env.On("getArgs", nil).Return(args)
path := &path{ path := &path{
env: env, env: env,
props: &properties{ props: map[Property]interface{}{
values: map[Property]interface{}{ MappedLocationsEnabled: false,
MappedLocationsEnabled: false, MappedLocations: tc.MappedLocations,
MappedLocations: tc.MappedLocations,
},
}, },
} }
got := path.getFullPath() got := path.getFullPath()
@ -616,11 +607,9 @@ func TestGetFolderPathCustomMappedLocations(t *testing.T) {
env.On("getArgs", nil).Return(args) env.On("getArgs", nil).Return(args)
path := &path{ path := &path{
env: env, env: env,
props: &properties{ props: map[Property]interface{}{
values: map[Property]interface{}{ MappedLocations: map[string]string{
MappedLocations: map[string]string{ "/a/b/c/d": "#",
"/a/b/c/d": "#",
},
}, },
}, },
} }
@ -654,13 +643,6 @@ func TestAgnosterPath(t *testing.T) {
} }
for _, tc := range cases { for _, tc := range cases {
props := &properties{
values: map[Property]interface{}{
FolderSeparatorIcon: " > ",
FolderIcon: "f",
HomeIcon: "~",
},
}
env := new(MockedEnvironment) env := new(MockedEnvironment)
env.On("homeDir", nil).Return(tc.Home) env.On("homeDir", nil).Return(tc.Home)
env.On("getPathSeperator", nil).Return(tc.PathSeparator) env.On("getPathSeperator", nil).Return(tc.PathSeparator)
@ -671,8 +653,12 @@ func TestAgnosterPath(t *testing.T) {
} }
env.On("getArgs", nil).Return(args) env.On("getArgs", nil).Return(args)
path := &path{ path := &path{
env: env, env: env,
props: props, props: map[Property]interface{}{
FolderSeparatorIcon: " > ",
FolderIcon: "f",
HomeIcon: "~",
},
} }
got := path.getAgnosterPath() got := path.getAgnosterPath()
assert.Equal(t, tc.Expected, got, tc.Case) assert.Equal(t, tc.Expected, got, tc.Case)
@ -716,12 +702,10 @@ func TestGetPwd(t *testing.T) {
env.On("getArgs", nil).Return(args) env.On("getArgs", nil).Return(args)
path := &path{ path := &path{
env: env, env: env,
props: &properties{ props: map[Property]interface{}{
values: map[Property]interface{}{ MappedLocationsEnabled: tc.MappedLocationsEnabled,
MappedLocationsEnabled: tc.MappedLocationsEnabled, MappedLocations: map[string]string{
MappedLocations: map[string]string{ "/a/b/c/d": "#",
"/a/b/c/d": "#",
},
}, },
}, },
} }
@ -751,10 +735,7 @@ func TestParseMappedLocations(t *testing.T) {
var segment Segment var segment Segment
err = config.BindStruct("", &segment) err = config.BindStruct("", &segment)
assert.NoError(t, err) assert.NoError(t, err)
props := &properties{ mappedLocations := segment.Properties.getKeyValueMap(MappedLocations, make(map[string]string))
values: segment.Properties,
}
mappedLocations := props.getKeyValueMap(MappedLocations, make(map[string]string))
assert.Equal(t, "two", mappedLocations["folder2"]) assert.Equal(t, "two", mappedLocations["folder2"])
} }
} }

View file

@ -8,7 +8,7 @@ func (n *php) string() string {
return n.language.string() return n.language.string()
} }
func (n *php) init(props *properties, env environmentInfo) { func (n *php) init(props properties, env environmentInfo) {
n.language = &language{ n.language = &language{
env: env, env: env,
props: props, props: props,

View file

@ -3,7 +3,7 @@ package main
import "strings" import "strings"
type poshgit struct { type poshgit struct {
props *properties props properties
env environmentInfo env environmentInfo
gitStatus string gitStatus string
} }
@ -22,7 +22,7 @@ func (p *poshgit) string() string {
return p.gitStatus return p.gitStatus
} }
func (p *poshgit) init(props *properties, env environmentInfo) { func (p *poshgit) init(props properties, env environmentInfo) {
p.props = props p.props = props
p.env = env p.env = env
} }

View file

@ -23,7 +23,7 @@ func (p *python) string() string {
return fmt.Sprintf("%s %s", p.venvName, version) return fmt.Sprintf("%s %s", p.venvName, version)
} }
func (p *python) init(props *properties, env environmentInfo) { func (p *python) init(props properties, env environmentInfo) {
p.language = &language{ p.language = &language{
env: env, env: env,
props: props, props: props,

View file

@ -39,12 +39,10 @@ func TestPythonVirtualEnv(t *testing.T) {
env.On("getPathSeperator", nil).Return("") env.On("getPathSeperator", nil).Return("")
env.On("getcwd", nil).Return("/usr/home/project") env.On("getcwd", nil).Return("/usr/home/project")
env.On("homeDir", nil).Return("/usr/home") env.On("homeDir", nil).Return("/usr/home")
props := &properties{ var props properties = map[Property]interface{}{
values: map[Property]interface{}{ DisplayVersion: tc.DisplayVersion,
DisplayVersion: tc.DisplayVersion, DisplayVirtualEnv: true,
DisplayVirtualEnv: true, DisplayDefault: tc.DisplayDefault,
DisplayDefault: tc.DisplayDefault,
},
} }
python := &python{} python := &python{}
python.init(props, env) python.init(props, env)

View file

@ -1,7 +1,7 @@
package main package main
type root struct { type root struct {
props *properties props properties
env environmentInfo env environmentInfo
} }
@ -18,7 +18,7 @@ func (rt *root) string() string {
return rt.props.getString(RootIcon, "\uF0E7") return rt.props.getString(RootIcon, "\uF0E7")
} }
func (rt *root) init(props *properties, env environmentInfo) { func (rt *root) init(props properties, env environmentInfo) {
rt.props = props rt.props = props
rt.env = env rt.env = env
} }

View file

@ -13,7 +13,7 @@ func (r *ruby) string() string {
return version return version
} }
func (r *ruby) init(props *properties, env environmentInfo) { func (r *ruby) init(props properties, env environmentInfo) {
r.language = &language{ r.language = &language{
env: env, env: env,
props: props, props: props,

View file

@ -98,10 +98,8 @@ func TestRuby(t *testing.T) {
env.On("hasFiles", "Gemfile").Return(tc.HasGemFile) env.On("hasFiles", "Gemfile").Return(tc.HasGemFile)
env.On("getcwd", nil).Return("/usr/home/project") env.On("getcwd", nil).Return("/usr/home/project")
env.On("homeDir", nil).Return("/usr/home") env.On("homeDir", nil).Return("/usr/home")
props := &properties{ var props properties = map[Property]interface{}{
values: map[Property]interface{}{ DisplayVersion: tc.DisplayVersion,
DisplayVersion: tc.DisplayVersion,
},
} }
ruby := &ruby{} ruby := &ruby{}
ruby.init(props, env) ruby.init(props, env)

View file

@ -8,7 +8,7 @@ func (r *rust) string() string {
return r.language.string() return r.language.string()
} }
func (r *rust) init(props *properties, env environmentInfo) { func (r *rust) init(props properties, env environmentInfo) {
r.language = &language{ r.language = &language{
env: env, env: env,
props: props, props: props,

View file

@ -6,7 +6,7 @@ import (
) )
type session struct { type session struct {
props *properties props properties
env environmentInfo env environmentInfo
UserName string UserName string
DefaultUserName string DefaultUserName string
@ -66,7 +66,7 @@ func (s *session) string() string {
return s.getFormattedText() return s.getFormattedText()
} }
func (s *session) init(props *properties, env environmentInfo) { func (s *session) init(props properties, env environmentInfo) {
s.props = props s.props = props
s.env = env s.env = env
} }
@ -83,8 +83,9 @@ func (s *session) getFormattedText() string {
if s.SSHSession { if s.SSHSession {
sshIcon = s.props.getString(SSHIcon, "\uF817 ") sshIcon = s.props.getString(SSHIcon, "\uF817 ")
} }
userColor := s.props.getColor(UserColor, s.props.foreground) defaulColor := s.props.getColor(ForegroundOverride, "")
hostColor := s.props.getColor(HostColor, s.props.foreground) userColor := s.props.getColor(UserColor, defaulColor)
hostColor := s.props.getColor(HostColor, defaulColor)
if len(userColor) > 0 && len(hostColor) > 0 { if len(userColor) > 0 && len(hostColor) > 0 {
return fmt.Sprintf("%s<%s>%s</>%s<%s>%s</>", sshIcon, userColor, s.UserName, separator, hostColor, s.ComputerName) return fmt.Sprintf("%s<%s>%s</>%s<%s>%s</>", sshIcon, userColor, s.UserName, separator, hostColor, s.ComputerName)
} }

View file

@ -179,17 +179,15 @@ func TestPropertySessionSegment(t *testing.T) {
env.On("getenv", "SSH_CLIENT").Return(SSHSession) env.On("getenv", "SSH_CLIENT").Return(SSHSession)
env.On("getenv", defaultUserEnvVar).Return(tc.DefaultUserNameEnv) env.On("getenv", defaultUserEnvVar).Return(tc.DefaultUserNameEnv)
env.On("isRunningAsRoot", nil).Return(tc.Root) env.On("isRunningAsRoot", nil).Return(tc.Root)
props := &properties{ var props properties = map[Property]interface{}{
values: map[Property]interface{}{ UserInfoSeparator: " at ",
UserInfoSeparator: " at ", SSHIcon: "ssh ",
SSHIcon: "ssh ", DefaultUserName: tc.DefaultUserName,
DefaultUserName: tc.DefaultUserName, DisplayDefault: tc.DisplayDefault,
DisplayDefault: tc.DisplayDefault, DisplayUser: tc.DisplayUser,
DisplayUser: tc.DisplayUser, DisplayHost: tc.DisplayHost,
DisplayHost: tc.DisplayHost, HostColor: tc.HostColor,
HostColor: tc.HostColor, UserColor: tc.UserColor,
UserColor: tc.UserColor,
},
} }
session := &session{ session := &session{
env: env, env: env,
@ -303,15 +301,12 @@ func TestSessionSegmentTemplate(t *testing.T) {
env.On("getenv", "SSH_CLIENT").Return(SSHSession) env.On("getenv", "SSH_CLIENT").Return(SSHSession)
env.On("isRunningAsRoot", nil).Return(tc.Root) env.On("isRunningAsRoot", nil).Return(tc.Root)
env.On("getenv", defaultUserEnvVar).Return(tc.DefaultUserName) env.On("getenv", defaultUserEnvVar).Return(tc.DefaultUserName)
props := &properties{ session := &session{
values: map[Property]interface{}{ env: env,
props: map[Property]interface{}{
SegmentTemplate: tc.Template, SegmentTemplate: tc.Template,
}, },
} }
session := &session{
env: env,
props: props,
}
assert.Equal(t, tc.ExpectedEnabled, session.enabled(), tc.Case) assert.Equal(t, tc.ExpectedEnabled, session.enabled(), tc.Case)
if tc.ExpectedEnabled { if tc.ExpectedEnabled {
assert.Equal(t, tc.ExpectedString, session.string(), tc.Case) assert.Equal(t, tc.ExpectedString, session.string(), tc.Case)

View file

@ -3,7 +3,7 @@ package main
import "strings" import "strings"
type shell struct { type shell struct {
props *properties props properties
env environmentInfo env environmentInfo
} }
@ -28,7 +28,7 @@ func (s *shell) string() string {
return shellName return shellName
} }
func (s *shell) init(props *properties, env environmentInfo) { func (s *shell) init(props properties, env environmentInfo) {
s.props = props s.props = props
s.env = env s.env = env
} }

View file

@ -10,10 +10,8 @@ func TestWriteCurrentShell(t *testing.T) {
expected := "zsh" expected := "zsh"
env := new(MockedEnvironment) env := new(MockedEnvironment)
env.On("getShellName", nil).Return(expected, nil) env.On("getShellName", nil).Return(expected, nil)
props := &properties{}
s := &shell{ s := &shell{
env: env, env: env,
props: props,
} }
assert.Equal(t, expected, s.string()) assert.Equal(t, expected, s.string())
} }
@ -32,10 +30,8 @@ func TestUseMappedShellNames(t *testing.T) {
env.On("getShellName", nil).Return(tc.Expected, nil) env.On("getShellName", nil).Return(tc.Expected, nil)
s := &shell{ s := &shell{
env: env, env: env,
props: &properties{ props: map[Property]interface{}{
values: map[Property]interface{}{ MappedShellNames: map[string]string{"pwsh": "PS"},
MappedShellNames: map[string]string{"pwsh": "PS"},
},
}, },
} }
got := s.string() got := s.string()

View file

@ -5,7 +5,7 @@ import (
) )
type spotify struct { type spotify struct {
props *properties props properties
env environmentInfo env environmentInfo
status string status string
artist string artist string
@ -39,7 +39,7 @@ func (s *spotify) string() string {
return fmt.Sprintf("%s%s%s%s", icon, s.artist, separator, s.track) return fmt.Sprintf("%s%s%s%s", icon, s.artist, separator, s.track)
} }
func (s *spotify) init(props *properties, env environmentInfo) { func (s *spotify) init(props properties, env environmentInfo) {
s.props = props s.props = props
s.env = env s.env = env
} }

View file

@ -22,10 +22,8 @@ func bootStrapSpotifyDarwinTest(args *spotifyArgs) *spotify {
env.On("runCommand", "osascript", []string{"-e", "tell application \"Spotify\" to player state as string"}).Return(args.status, nil) env.On("runCommand", "osascript", []string{"-e", "tell application \"Spotify\" to player state as string"}).Return(args.status, nil)
env.On("runCommand", "osascript", []string{"-e", "tell application \"Spotify\" to artist of current track as string"}).Return(args.artist, nil) env.On("runCommand", "osascript", []string{"-e", "tell application \"Spotify\" to artist of current track as string"}).Return(args.artist, nil)
env.On("runCommand", "osascript", []string{"-e", "tell application \"Spotify\" to name of current track as string"}).Return(args.track, nil) env.On("runCommand", "osascript", []string{"-e", "tell application \"Spotify\" to name of current track as string"}).Return(args.track, nil)
props := &properties{}
s := &spotify{ s := &spotify{
env: env, env: env,
props: props,
} }
return s return s
} }

View file

@ -17,10 +17,8 @@ type spotifyArgs struct {
func bootStrapSpotifyWindowsTest(args *spotifyArgs) *spotify { func bootStrapSpotifyWindowsTest(args *spotifyArgs) *spotify {
env := new(MockedEnvironment) env := new(MockedEnvironment)
env.On("getWindowTitle", "spotify.exe").Return(args.title, args.runError) env.On("getWindowTitle", "spotify.exe").Return(args.title, args.runError)
props := &properties{}
s := &spotify{ s := &spotify{
env: env, env: env,
props: props,
} }
return s return s
} }

View file

@ -54,10 +54,8 @@ func TestSpotifyWsl(t *testing.T) {
env := new(MockedEnvironment) env := new(MockedEnvironment)
env.On("isWsl", nil).Return(true) env.On("isWsl", nil).Return(true)
env.On("runCommand", "tasklist.exe", []string{"/V", "/FI", "Imagename eq Spotify.exe", "/FO", "CSV", "/NH"}).Return(tc.ExecOutput, nil) env.On("runCommand", "tasklist.exe", []string{"/V", "/FI", "Imagename eq Spotify.exe", "/FO", "CSV", "/NH"}).Return(tc.ExecOutput, nil)
props := &properties{}
s := &spotify{ s := &spotify{
env: env, env: env,
props: props,
} }
assert.Equal(t, tc.ExpectedEnabled, s.enabled(), fmt.Sprintf("Failed in case: %s", tc.Case)) assert.Equal(t, tc.ExpectedEnabled, s.enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
assert.Equal(t, tc.ExpectedString, s.string(), fmt.Sprintf("Failed in case: %s", tc.Case)) assert.Equal(t, tc.ExpectedString, s.string(), fmt.Sprintf("Failed in case: %s", tc.Case))

View file

@ -7,7 +7,7 @@ import (
) )
type sysinfo struct { type sysinfo struct {
props *properties props properties
env environmentInfo env environmentInfo
Precision int Precision int
// mem // mem
@ -53,7 +53,7 @@ func (s *sysinfo) string() string {
return text return text
} }
func (s *sysinfo) init(props *properties, env environmentInfo) { func (s *sysinfo) init(props properties, env environmentInfo) {
s.props = props s.props = props
s.env = env s.env = env
s.Precision = s.props.getInt(Precision, 2) s.Precision = s.props.getInt(Precision, 2)

View file

@ -35,13 +35,11 @@ func TestSysInfo(t *testing.T) {
for _, tc := range cases { for _, tc := range cases {
tc.SysInfo.env = new(MockedEnvironment) tc.SysInfo.env = new(MockedEnvironment)
tc.SysInfo.props = &properties{ tc.SysInfo.props = map[Property]interface{}{
values: map[Property]interface{}{ Precision: tc.Precision,
Precision: tc.Precision,
},
} }
if tc.Template != "" { if tc.Template != "" {
tc.SysInfo.props.values[SegmentTemplate] = tc.Template tc.SysInfo.props[SegmentTemplate] = tc.Template
} }
if tc.ExpectDisabled { if tc.ExpectDisabled {
assert.Equal(t, false, tc.SysInfo.enabled(), tc.Case) assert.Equal(t, false, tc.SysInfo.enabled(), tc.Case)

View file

@ -1,7 +1,7 @@
package main package main
type terraform struct { type terraform struct {
props *properties props properties
env environmentInfo env environmentInfo
WorkspaceName string WorkspaceName string
} }
@ -20,7 +20,7 @@ func (tf *terraform) string() string {
return text return text
} }
func (tf *terraform) init(props *properties, env environmentInfo) { func (tf *terraform) init(props properties, env environmentInfo) {
tf.props = props tf.props = props
tf.env = env tf.env = env
} }

View file

@ -19,8 +19,7 @@ func bootStrapTerraformTest(args *terraformArgs) *terraform {
env.On("getcwd", nil).Return("") env.On("getcwd", nil).Return("")
env.On("runCommand", "terraform", []string{"workspace", "show"}).Return(args.workspaceName, nil) env.On("runCommand", "terraform", []string{"workspace", "show"}).Return(args.workspaceName, nil)
k := &terraform{ k := &terraform{
env: env, env: env,
props: &properties{},
} }
return k return k
} }

View file

@ -17,7 +17,6 @@ func TestMapSegmentWriterCanMap(t *testing.T) {
} }
env := new(MockedEnvironment) env := new(MockedEnvironment)
err := sc.mapSegmentWithWriter(env) err := sc.mapSegmentWithWriter(env)
assert.NotNil(t, sc.props)
assert.NoError(t, err) assert.NoError(t, err)
assert.NotNil(t, sc.writer) assert.NotNil(t, sc.writer)
} }
@ -28,7 +27,6 @@ func TestMapSegmentWriterCannotMap(t *testing.T) {
} }
env := new(MockedEnvironment) env := new(MockedEnvironment)
err := sc.mapSegmentWithWriter(env) err := sc.mapSegmentWithWriter(env)
assert.Nil(t, sc.props)
assert.Error(t, err) assert.Error(t, err)
} }

View file

@ -1,7 +1,7 @@
package main package main
type text struct { type text struct {
props *properties props properties
env environmentInfo env environmentInfo
content string content string
} }
@ -26,7 +26,7 @@ func (t *text) string() string {
return t.content return t.content
} }
func (t *text) init(props *properties, env environmentInfo) { func (t *text) init(props properties, env environmentInfo) {
t.props = props t.props = props
t.env = env t.env = env
} }

View file

@ -33,15 +33,12 @@ func TestTextSegment(t *testing.T) {
env.On("getenv", "WORLD").Return("") env.On("getenv", "WORLD").Return("")
env.On("getCurrentUser", nil).Return("Posh") env.On("getCurrentUser", nil).Return("Posh")
env.On("getHostName", nil).Return("MyHost", nil) env.On("getHostName", nil).Return("MyHost", nil)
props := &properties{ txt := &text{
values: map[Property]interface{}{ env: env,
props: map[Property]interface{}{
TextProperty: tc.Text, TextProperty: tc.Text,
}, },
} }
txt := &text{
env: env,
props: props,
}
assert.Equal(t, tc.ExpectedDisabled, !txt.enabled(), tc.Case) assert.Equal(t, tc.ExpectedDisabled, !txt.enabled(), tc.Case)
assert.Equal(t, tc.ExpectedString, txt.string(), tc.Case) assert.Equal(t, tc.ExpectedString, txt.string(), tc.Case)
} }

View file

@ -3,7 +3,7 @@ package main
import "time" import "time"
type tempus struct { type tempus struct {
props *properties props properties
env environmentInfo env environmentInfo
templateText string templateText string
CurrentDate time.Time CurrentDate time.Time
@ -40,7 +40,7 @@ func (t *tempus) string() string {
return t.getFormattedText() return t.getFormattedText()
} }
func (t *tempus) init(props *properties, env environmentInfo) { func (t *tempus) init(props properties, env environmentInfo) {
t.props = props t.props = props
t.env = env t.env = env
} }

View file

@ -39,14 +39,11 @@ func TestTimeSegmentTemplate(t *testing.T) {
for _, tc := range cases { for _, tc := range cases {
env := new(MockedEnvironment) env := new(MockedEnvironment)
props := &properties{ tempus := &tempus{
values: map[Property]interface{}{ env: env,
props: map[Property]interface{}{
SegmentTemplate: tc.Template, SegmentTemplate: tc.Template,
}, },
}
tempus := &tempus{
env: env,
props: props,
CurrentDate: currentDate, CurrentDate: currentDate,
} }
assert.Equal(t, tc.ExpectedEnabled, tempus.enabled()) assert.Equal(t, tc.ExpectedEnabled, tempus.enabled())

View file

@ -7,7 +7,7 @@ import (
) )
type wifi struct { type wifi struct {
props *properties props properties
env environmentInfo env environmentInfo
Connected bool Connected bool
State string State string
@ -68,7 +68,7 @@ func (w *wifi) string() string {
return text return text
} }
func (w *wifi) init(props *properties, env environmentInfo) { func (w *wifi) init(props properties, env environmentInfo) {
w.props = props w.props = props
w.env = env w.env = env
} }

View file

@ -120,18 +120,14 @@ func TestWiFiSegment(t *testing.T) {
env.On("hasCommand", "netsh.exe").Return(!tc.CommandNotFound) env.On("hasCommand", "netsh.exe").Return(!tc.CommandNotFound)
env.On("runCommand", mock.Anything, mock.Anything).Return(tc.CommandOutput, tc.CommandError) env.On("runCommand", mock.Anything, mock.Anything).Return(tc.CommandOutput, tc.CommandError)
props := &properties{ w := &wifi{
values: map[Property]interface{}{ env: env,
props: map[Property]interface{}{
DisplayError: tc.DisplayError, DisplayError: tc.DisplayError,
SegmentTemplate: tc.Template, SegmentTemplate: tc.Template,
}, },
} }
w := &wifi{
env: env,
props: props,
}
assert.Equal(t, tc.ExpectedEnabled, w.enabled(), tc.Case) assert.Equal(t, tc.ExpectedEnabled, w.enabled(), tc.Case)
assert.Equal(t, tc.ExpectedString, w.string(), tc.Case) assert.Equal(t, tc.ExpectedString, w.string(), tc.Case)
} }

View file

@ -1,7 +1,7 @@
package main package main
type winreg struct { type winreg struct {
props *properties props properties
env environmentInfo env environmentInfo
Value string Value string
@ -16,7 +16,7 @@ const (
Fallback Property = "fallback" Fallback Property = "fallback"
) )
func (wr *winreg) init(props *properties, env environmentInfo) { func (wr *winreg) init(props properties, env environmentInfo) {
wr.props = props wr.props = props
wr.env = env wr.env = env
} }

View file

@ -66,17 +66,14 @@ func TestRegQueryEnabled(t *testing.T) {
env := new(MockedEnvironment) env := new(MockedEnvironment)
env.On("getRuntimeGOOS", nil).Return(windowsPlatform) env.On("getRuntimeGOOS", nil).Return(windowsPlatform)
env.On("getWindowsRegistryKeyValue", tc.Path, tc.Key).Return(tc.Output, tc.Err) env.On("getWindowsRegistryKeyValue", tc.Path, tc.Key).Return(tc.Output, tc.Err)
props := &properties{ r := &winreg{
values: map[Property]interface{}{ env: env,
props: map[Property]interface{}{
RegistryPath: tc.Path, RegistryPath: tc.Path,
RegistryKey: tc.Key, RegistryKey: tc.Key,
Fallback: tc.Fallback, Fallback: tc.Fallback,
}, },
} }
r := &winreg{
env: env,
props: props,
}
assert.Equal(t, tc.ExpectedSuccess, r.enabled(), tc.CaseDescription) assert.Equal(t, tc.ExpectedSuccess, r.enabled(), tc.CaseDescription)
assert.Equal(t, tc.ExpectedValue, r.string(), tc.CaseDescription) assert.Equal(t, tc.ExpectedValue, r.string(), tc.CaseDescription)

View file

@ -6,7 +6,7 @@ import (
) )
type ytm struct { type ytm struct {
props *properties props properties
env environmentInfo env environmentInfo
status playStatus status playStatus
artist string artist string
@ -39,7 +39,7 @@ func (y *ytm) enabled() bool {
return err == nil return err == nil
} }
func (y *ytm) init(props *properties, env environmentInfo) { func (y *ytm) init(props properties, env environmentInfo) {
y.props = props y.props = props
y.env = env y.env = env
} }

View file

@ -41,15 +41,12 @@ func bootstrapYTMDATest(json string, err error) *ytm {
url := "http://127.0.0.1:9863" url := "http://127.0.0.1:9863"
env := new(MockedEnvironment) env := new(MockedEnvironment)
env.On("doGet", url+"/query").Return([]byte(json), err) env.On("doGet", url+"/query").Return([]byte(json), err)
props := &properties{ ytm := &ytm{
values: map[Property]interface{}{ env: env,
props: map[Property]interface{}{
APIURL: url, APIURL: url,
}, },
} }
ytm := &ytm{
env: env,
props: props,
}
return ytm return ytm
} }