Skip to content

Commit

Permalink
refmt project
Browse files Browse the repository at this point in the history
  • Loading branch information
rogermyang committed May 13, 2018
1 parent ab04b47 commit 0802f30
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 25 deletions.
13 changes: 6 additions & 7 deletions client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ package client

import (
"errors"
"github.com/BurntSushi/toml"
"github.com/ubclaunchpad/inertia/common"
"io"
"io/ioutil"
"os"
"path/filepath"

"github.com/ubclaunchpad/inertia/common"
"github.com/BurntSushi/toml"
"reflect"
)

Expand Down Expand Up @@ -178,7 +177,7 @@ func GetConfigFilePath() (string, error) {

// SetProperty takes a struct pointer and searches for its "toml" tag with a search key
// and set property value with the tag
func SetProperty(name string, value string,structObject interface{}) bool {
func SetProperty(name string, value string, structObject interface{}) bool {
val := reflect.ValueOf(structObject)

if val.Kind() != reflect.Ptr {
Expand All @@ -188,12 +187,12 @@ func SetProperty(name string, value string,structObject interface{}) bool {
for i := 0; i < structVal.NumField(); i++ {
valueField := structVal.Field(i)
typeField := structVal.Type().Field(i)
if typeField.Tag.Get("toml") == name{
if (valueField.IsValid() && valueField.CanSet() && valueField.Kind() == reflect.String){
if typeField.Tag.Get("toml") == name {
if valueField.IsValid() && valueField.CanSet() && valueField.Kind() == reflect.String {
valueField.SetString(value)
return true
}
}
}
return false
}
}
32 changes: 16 additions & 16 deletions client/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,27 +103,27 @@ func TestConfigRemoteRemote(t *testing.T) {

func TestSetProperty(t *testing.T) {

testDaemonConfig:= &DaemonConfig{
testDaemonConfig := &DaemonConfig{
Port: "8080",
SSHPort: "22",
}

testRemote := & RemoteVPS{
Name: "testName",
IP: "1234",
User: "testUser",
PEM: "/some/pem/file",
testRemote := &RemoteVPS{
Name: "testName",
IP: "1234",
User: "testUser",
PEM: "/some/pem/file",
Daemon: testDaemonConfig,
}
a := SetProperty("name","newTestName",testRemote)
assert.True(t,a)
assert.Equal(t,"newTestName",testRemote.Name)
a := SetProperty("name", "newTestName", testRemote)
assert.True(t, a)
assert.Equal(t, "newTestName", testRemote.Name)

b := SetProperty("wrongtag","otherTestName",testRemote)
assert.False(t,b)
assert.Equal(t,"newTestName",testRemote.Name)
b := SetProperty("wrongtag", "otherTestName", testRemote)
assert.False(t, b)
assert.Equal(t, "newTestName", testRemote.Name)

c := SetProperty("port","8000",testDaemonConfig)
assert.True(t,c)
assert.Equal(t,"8000",testDaemonConfig.Port)
}
c := SetProperty("port", "8000", testDaemonConfig)
assert.True(t, c)
assert.Equal(t, "8000", testDaemonConfig.Port)
}
2 changes: 1 addition & 1 deletion client/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,4 @@ func (remote *RemoteVPS) getDaemonAPIToken(session SSHSession, daemonVersion str

// There may be a newline, remove it.
return strings.TrimSuffix(stdout.String(), "\n"), nil
}
}
2 changes: 1 addition & 1 deletion remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ var setCmd = &cobra.Command{

remote, found := config.GetRemote(args[0])
if found {
success := client.SetProperty(args[1], args[2],remote)
success := client.SetProperty(args[1], args[2], remote)
if success {
println("Remote '" + args[0] + "' has been updated.")
printRemoteDetails(remote)
Expand Down

0 comments on commit 0802f30

Please sign in to comment.