@@ -3,6 +3,7 @@ package tcurls
33import (
44 "fmt"
55 "io/ioutil"
6+ "strings"
67 "testing"
78
89 "gopkg.in/yaml.v2"
@@ -35,12 +36,14 @@ func testFunc(t *testing.T, functionType string, root string, args ...string) (s
3536 return Schema (root , args [0 ], args [1 ]), nil
3637 case "ui" :
3738 return UI (root , args [0 ]), nil
39+ case "servicesManifest" :
40+ return ServicesManifest (root ), nil
3841 default :
3942 return "" , fmt .Errorf ("Unknown function type: %s" , functionType )
4043 }
4144}
4245
43- func TestUrls (t * testing.T ) {
46+ func TestURLs (t * testing.T ) {
4447 data , err := ioutil .ReadFile ("specification.yml" )
4548 if err != nil {
4649 t .Error (err )
@@ -52,41 +55,56 @@ func TestUrls(t *testing.T) {
5255 }
5356
5457 for _ , test := range specs .Specs {
55- // First test "new" urls
5658 for _ , argSet := range test .ArgSets {
59+
60+ // Test "new" URLs
5761 result , err := testFunc (t , test .FunctionType , rootURL , argSet ... )
5862 if err != nil {
5963 t .Error (err )
6064 continue
6165 }
6266 if result != test .ExpectedURL {
63- t .Errorf ("Url is not correct. Got %s wanted %s " , result , test .ExpectedURL )
67+ t .Errorf ("URL is not correct. Got %q wanted %q " , result , test .ExpectedURL )
6468 continue
6569 }
6670 result , err = testFunc (t , test .FunctionType , fmt .Sprintf ("%s/" , rootURL ), argSet ... )
6771 if err != nil {
6872 t .Error (err )
6973 }
7074 if result != test .ExpectedURL {
71- t .Errorf ("Url is not correct. Got %s wanted %s " , result , test .ExpectedURL )
75+ t .Errorf ("URL is not correct. Got %q wanted %q " , result , test .ExpectedURL )
7276 continue
7377 }
78+ t .Logf (`%v %v(%v) = %q` , greenTick (), test .FunctionType , quotedList (rootURL , argSet ), result )
7479
75- // Now the old ones
80+ // Test " old" URLs
7681 result , err = testFunc (t , test .FunctionType , oldRootURL , argSet ... )
7782 if err != nil {
7883 t .Error (err )
7984 }
8085 if result != test .OldExpectedURL {
81- t .Errorf ("Url is not correct. Got %s wanted %s " , result , test .OldExpectedURL )
86+ t .Errorf ("URL is not correct. Got %q wanted %q " , result , test .OldExpectedURL )
8287 }
8388 result , err = testFunc (t , test .FunctionType , fmt .Sprintf ("%s/" , oldRootURL ), argSet ... )
8489 if err != nil {
8590 t .Error (err )
8691 }
8792 if result != test .OldExpectedURL {
88- t .Errorf ("Url is not correct. Got %s wanted %s " , result , test .OldExpectedURL )
93+ t .Errorf ("URL is not correct. Got %q wanted %q " , result , test .OldExpectedURL )
8994 }
95+ t .Logf (`%v %v(%v) = %q` , greenTick (), test .FunctionType , quotedList (oldRootURL , argSet ), result )
9096 }
9197 }
9298}
99+
100+ // quotedList returns a quoted list of the arguments passed in
101+ func quotedList (url string , args []string ) string {
102+ all := append ([]string {url }, args ... )
103+ return `'` + strings .Join (all , `', '` ) + `'`
104+ }
105+
106+ // greenTick returns an ANSI string including escape codes to render a light
107+ // green tick (✓) in a color console
108+ func greenTick () string {
109+ return string ([]byte {0x1b , 0x5b , 0x33 , 0x32 , 0x6d , 0xe2 , 0x9c , 0x93 , 0x1b , 0x5b , 0x30 , 0x6d })
110+ }
0 commit comments