示例#1
0
func main() {
	logDest := flag.String("log", "STDERR", "Where to log to - STDOUT, STDERR or a filename")
	configFile := flag.String("config-file", defaultConfigFile, "Path to the config file")
	returnVersion := flag.Bool("version", false, "return version information and exit")

	flag.Parse()

	if *returnVersion {
		fmt.Printf("temperature-monitor %s\n", versionInfo())
		os.Exit(0)
	}

	err := setupLogging(*logDest)
	if err != nil {
		log.Fatal(err)
	}

	config, err := loadConfig(*configFile)
	if err != nil {
		log.Fatal("Error opening config file : ", err)
	}

	srv := webserver.New(config.Port)
	err = addSensors(config, srv)
	if err != nil {
		log.Fatal(err)
	}

	err = srv.Run()
	if err != nil {
		log.Fatal(err)
	}
}
	"github.com/alext/temperature-monitor/webserver"
)

func TestWebServer(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "Webserver")
}

var _ = Describe("the webserver", func() {
	var (
		server *webserver.Webserver
	)

	BeforeEach(func() {
		server = webserver.New(8080)
	})

	Describe("the root page", func() {
		It("resturns a 200", func() {
			resp := doGetRequest(server, "/")
			Expect(resp.Code).To(Equal(http.StatusOK))

		})
	})

	Describe("reading a sensor", func() {
		var (
			sensor *dummySensor
		)