github.com/emcfarlane/larking@v0.0.0-20220605172417-1704b45ee6c3/starlib/net/starlarkhttp/http_test.go (about) 1 // Copyright 2021 Edward McFarlane. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package starlarkhttp_test 6 7 import ( 8 "fmt" 9 "net/http" 10 "net/http/httptest" 11 "testing" 12 13 "github.com/emcfarlane/larking/starlib" 14 "go.starlark.net/starlark" 15 ) 16 17 func TestExecFile(t *testing.T) { 18 mux := http.NewServeMux() 19 mux.HandleFunc("/hello", func(w http.ResponseWriter, _ *http.Request) { 20 fmt.Fprintln(w, "world") 21 }) 22 23 // Create a test http server. 24 ts := httptest.NewServer(mux) 25 t.Cleanup(ts.Close) 26 27 globals := starlark.StringDict{ 28 "addr": starlark.String(ts.URL), 29 } 30 starlib.RunTests(t, "testdata/*.star", globals) 31 }