github.com/billybanfield/evergreen@v0.0.0-20170525200750-eeee692790f7/model/project_vars_test.go (about) 1 package model 2 3 import ( 4 "testing" 5 6 "github.com/evergreen-ci/evergreen/db" 7 "github.com/evergreen-ci/evergreen/testutil" 8 . "github.com/smartystreets/goconvey/convey" 9 ) 10 11 func TestFindOneProjectVar(t *testing.T) { 12 Convey("With an existing repository var", t, func() { 13 testutil.HandleTestingErr(db.Clear(ProjectVarsCollection), t, 14 "Error clearing collection") 15 vars := map[string]string{ 16 "a": "b", 17 "c": "d", 18 } 19 projectVars := ProjectVars{ 20 Id: "mongodb", 21 Vars: vars, 22 } 23 24 Convey("all fields should be returned accurately for the "+ 25 "corresponding project vars", func() { 26 _, err := projectVars.Upsert() 27 So(err, ShouldBeNil) 28 projectVarsFromDB, err := FindOneProjectVars("mongodb") 29 So(err, ShouldBeNil) 30 So(projectVarsFromDB.Id, ShouldEqual, "mongodb") 31 So(projectVarsFromDB.Vars, ShouldResemble, vars) 32 }) 33 }) 34 } 35 36 func TestRedactPrivateVars(t *testing.T) { 37 Convey("With vars", t, func() { 38 vars := map[string]string{ 39 "a": "a", 40 "b": "b", 41 } 42 privateVars := map[string]bool{ 43 "a": true, 44 } 45 projectVars := ProjectVars{ 46 Id: "mongodb", 47 Vars: vars, 48 PrivateVars: privateVars, 49 } 50 51 Convey("then redacting should return empty strings for private vars", func() { 52 projectVars.RedactPrivateVars() 53 So(projectVars.Vars["a"], ShouldEqual, "") 54 }) 55 }) 56 }