| 
									
										
										
										
											2019-04-22 23:58:24 +08:00
										 |  |  | package setting | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"path/filepath" | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-13 14:45:54 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/infra/log" | 
					
						
							| 
									
										
										
										
											2019-04-22 23:58:24 +08:00
										 |  |  | 	. "github.com/smartystreets/goconvey/convey" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type testLogger struct { | 
					
						
							|  |  |  | 	log.Logger | 
					
						
							|  |  |  | 	warnCalled  bool | 
					
						
							|  |  |  | 	warnMessage string | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (stub *testLogger) Warn(testMessage string, ctx ...interface{}) { | 
					
						
							|  |  |  | 	stub.warnCalled = true | 
					
						
							|  |  |  | 	stub.warnMessage = testMessage | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | func TestSessionSettings(t *testing.T) { | 
					
						
							|  |  |  | 	Convey("session config", t, func() { | 
					
						
							|  |  |  | 		skipStaticRootValidation = true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Convey("Reading session should log error ", func() { | 
					
						
							|  |  |  | 			var ( | 
					
						
							|  |  |  | 				cfg      = NewCfg() | 
					
						
							|  |  |  | 				homePath = "../../" | 
					
						
							|  |  |  | 			) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			stub := &testLogger{} | 
					
						
							|  |  |  | 			cfg.Logger = stub | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-22 22:17:49 +08:00
										 |  |  | 			err := cfg.Load(&CommandLineArgs{ | 
					
						
							| 
									
										
										
										
											2019-04-22 23:58:24 +08:00
										 |  |  | 				HomePath: homePath, | 
					
						
							|  |  |  | 				Config:   filepath.Join(homePath, "pkg/setting/testdata/session.ini"), | 
					
						
							|  |  |  | 			}) | 
					
						
							| 
									
										
										
										
											2019-10-22 22:17:49 +08:00
										 |  |  | 			So(err, ShouldBeNil) | 
					
						
							| 
									
										
										
										
											2019-04-22 23:58:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			So(stub.warnCalled, ShouldEqual, true) | 
					
						
							|  |  |  | 			So(len(stub.warnMessage), ShouldBeGreaterThan, 0) | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | } |