@@ -3,7 +3,6 @@ package config
33import (
44 "bytes"
55 "encoding/base64"
6- "fmt"
76 "io/ioutil"
87 "os"
98 "testing"
@@ -27,7 +26,7 @@ func TestGetConfig(t *testing.T) {
2726 expected := "foo\n 8000\n "
2827 output := testWriter .String ()
2928 if output != expected {
30- t .Error ( fmt . Errorf ("Expected: '%s', Got:'%s'" , expected , output ) )
29+ t .Errorf ("Expected: '%s', Got:'%s'" , expected , output )
3130 }
3231}
3332
@@ -59,7 +58,21 @@ func TestSetConfig(t *testing.T) {
5958 expected := "bar\n 1000\n "
6059 output := testWriter .String ()
6160 if output != expected {
62- t .Error (fmt .Errorf ("Expected: '%s', Got:'%s'" , expected , output ))
61+ t .Errorf ("Expected: '%s', Got:'%s'" , expected , output )
62+ }
63+ }
64+
65+ func TestSetConfigError (t * testing.T ) {
66+ t .Parallel ()
67+
68+ testMock := mock.ConfigBackend {Expected : []* model.ConfigNode {}}
69+ testWriter := bytes.Buffer {}
70+
71+ expected := "'foo' does not match the pattern 'key=var', ex: foo=bar\n "
72+ err := doConfig ("controller" , "set" , []string {"foo" , "=" , "bar" }, testMock , & testWriter )
73+
74+ if err .Error () != expected {
75+ t .Errorf ("Expected: '%s', Got:'%q'" , expected , err )
6376 }
6477}
6578
@@ -78,7 +91,7 @@ func TestDeleteConfig(t *testing.T) {
7891 expected := "testing\n port\n "
7992 output := testWriter .String ()
8093 if output != expected {
81- t .Error ( fmt . Errorf ("Expected: '%s', Got:'%s'" , expected , output ) )
94+ t .Errorf ("Expected: '%s', Got:'%s'" , expected , output )
8295 }
8396}
8497
0 commit comments