| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package templateproto | 5 package templateproto |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "testing" | 8 "testing" |
| 9 | 9 |
| 10 "golang.org/x/net/context" | |
| 11 | |
| 12 "github.com/luci/luci-go/common/config" | |
| 13 "github.com/luci/luci-go/common/config/impl/memory" | |
| 14 . "github.com/luci/luci-go/common/testing/assertions" | 10 . "github.com/luci/luci-go/common/testing/assertions" |
| 15 . "github.com/smartystreets/goconvey/convey" | 11 . "github.com/smartystreets/goconvey/convey" |
| 16 ) | 12 ) |
| 17 | 13 |
| 18 func TestLoadFromConfig(t *testing.T) { | 14 func TestLoadFromConfig(t *testing.T) { |
| 19 t.Parallel() | 15 t.Parallel() |
| 20 | 16 |
| 21 Convey("LoadFile", t, func() { | 17 Convey("LoadFile", t, func() { |
| 22 » » c := config.SetImplementation(context.Background(), memory.New(m
ap[string]memory.ConfigSet{"projects/foo": {"templates/bar.cfg": ` | 18 » » templateContent := ` |
| 23 template: < | 19 template: < |
| 24 key: "hardcode" | 20 key: "hardcode" |
| 25 value: < | 21 value: < |
| 26 doc: "it's hard-coded" | 22 doc: "it's hard-coded" |
| 27 body: <<EOF | 23 body: <<EOF |
| 28 {"woot": ["sauce"]} | 24 {"woot": ["sauce"]} |
| 29 EOF | 25 EOF |
| 30 > | 26 > |
| 31 > | 27 > |
| 32 | 28 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 nullable: true | 66 nullable: true |
| 71 schema:<object:<>> | 67 schema:<object:<>> |
| 72 default: <object: <<EOF | 68 default: <object: <<EOF |
| 73 {"yes": "please"} | 69 {"yes": "please"} |
| 74 EOF | 70 EOF |
| 75 > | 71 > |
| 76 > | 72 > |
| 77 > | 73 > |
| 78 > | 74 > |
| 79 > | 75 > |
| 80 » » `}})) | 76 » » ` |
| 81 | 77 |
| 82 Convey("basic load", func() { | 78 Convey("basic load", func() { |
| 83 » » » file, vers, err := LoadFile(c, "projects/foo", "template
s/bar.cfg") | 79 » » » file, err := LoadFile(templateContent) |
| 84 So(err, ShouldBeNil) | 80 So(err, ShouldBeNil) |
| 85 So(vers, ShouldEqual, "v1:989dbfaacc4565bcf1491388c912e7
afc378d19d") | |
| 86 So(file, ShouldResemble, &File{Template: map[string]*Fil
e_Template{ | 81 So(file, ShouldResemble, &File{Template: map[string]*Fil
e_Template{ |
| 87 "hardcode": { | 82 "hardcode": { |
| 88 Doc: "it's hard-coded", | 83 Doc: "it's hard-coded", |
| 89 Body: `{"woot": ["sauce"]}`, | 84 Body: `{"woot": ["sauce"]}`, |
| 90 }, | 85 }, |
| 91 | 86 |
| 92 "templ_1": { | 87 "templ_1": { |
| 93 Doc: "This template is templ_1!\nIt's p
retty \"exciting\"!", | 88 Doc: "This template is templ_1!\nIt's p
retty \"exciting\"!", |
| 94 Body: "{\n\t\"json_key\": ${json_key},\n
\t\"cmd\": [\"array\", \"of\", ${thing}],\n\t\"extra\": ${extra}\n}", | 89 Body: "{\n\t\"json_key\": ${json_key},\n
\t\"cmd\": [\"array\", \"of\", ${thing}],\n\t\"extra\": ${extra}\n}", |
| 95 Param: map[string]*File_Template_Paramet
er{ | 90 Param: map[string]*File_Template_Paramet
er{ |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 | 138 |
| 144 Convey("hardcode", func() { | 139 Convey("hardcode", func() { |
| 145 ret, err := file.RenderL("hardcode", nil) | 140 ret, err := file.RenderL("hardcode", nil) |
| 146 So(err, ShouldBeNil) | 141 So(err, ShouldBeNil) |
| 147 So(ret, ShouldEqual, `{"woot": ["sauce"]}`) | 142 So(ret, ShouldEqual, `{"woot": ["sauce"]}`) |
| 148 }) | 143 }) |
| 149 }) | 144 }) |
| 150 | 145 |
| 151 }) | 146 }) |
| 152 } | 147 } |
| OLD | NEW |