Skip to content

Commit

Permalink
change const to env
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <[email protected]>
  • Loading branch information
HuSharp committed May 21, 2024
1 parent d56c4ec commit 1832d98
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 8 additions & 2 deletions pkg/utils/tempurl/tempurl.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"io"
"net"
"net/http"
"os"
"time"

"github.com/pingcap/log"
Expand All @@ -32,7 +33,7 @@ var (
)

// reference: /pd/tools/pd-ut/alloc/server.go
const utAllocURL = "http://0.0.0.0:20180/alloc"
const AllocURLFromUT = "allocURLFromUT"

// Alloc allocates a local URL for testing.
func Alloc() string {
Expand Down Expand Up @@ -73,7 +74,12 @@ func tryAllocTestURL() string {
}

func getFromUT() string {
resp, err := http.Get(utAllocURL)
addr := os.Getenv(AllocURLFromUT)
if addr == "" {
return ""
}

resp, err := http.Get(addr)

Check failure on line 82 in pkg/utils/tempurl/tempurl.go

View workflow job for this annotation

GitHub Actions / statics

G107: Potential HTTP request made with variable url (gosec)
if err != nil || resp.StatusCode != http.StatusOK {
return ""

Check warning on line 84 in pkg/utils/tempurl/tempurl.go

View check run for this annotation

Codecov / codecov/patch

pkg/utils/tempurl/tempurl.go#L84

Added line #L84 was not covered by tests
}
Expand Down
10 changes: 9 additions & 1 deletion tools/pd-ut/alloc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,26 @@ package alloc

import (
"errors"
"flag"
"fmt"
"net/http"
"os"
"time"

"github.com/gin-gonic/gin"
"github.com/pingcap/log"
flag "github.com/spf13/pflag"
"github.com/tikv/pd/pkg/utils/tempurl"
"go.uber.org/zap"
)

var statusAddress = flag.String("status-addr", "0.0.0.0:20180", "status address")

func RunHTTPServer() *http.Server {
err := os.Setenv(tempurl.AllocURLFromUT, fmt.Sprintf("http://%s/alloc", *statusAddress))
if err != nil {
fmt.Println(err)
}

gin.SetMode(gin.ReleaseMode)
engine := gin.New()
engine.Use(gin.Recovery())
Expand Down

0 comments on commit 1832d98

Please sign in to comment.