Skip to content

Commit

Permalink
refactor: remove http config
Browse files Browse the repository at this point in the history
  • Loading branch information
siyul-park committed Dec 6, 2023
1 parent fb0db41 commit 5b5062a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 28 deletions.
4 changes: 1 addition & 3 deletions pkg/plugin/networkx/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ func AddToScheme() func(*scheme.Scheme) error {
return func(s *scheme.Scheme) error {
s.AddKnownType(KindHTTP, &HTTPSpec{})
s.AddCodec(KindHTTP, scheme.CodecWithType[*HTTPSpec](func(spec *HTTPSpec) (node.Node, error) {
return NewHTTPNode(HTTPNodeConfig{
Address: spec.Address,
}), nil
return NewHTTPNode(spec.Address), nil
}))

s.AddKnownType(KindRouter, &RouterSpec{})
Expand Down
4 changes: 1 addition & 3 deletions pkg/plugin/networkx/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ func TestAddToHooks(t *testing.T) {
port, err := freeport.GetFreePort()
assert.NoError(t, err)

n := NewHTTPNode(HTTPNodeConfig{
Address: fmt.Sprintf(":%d", port),
})
n := NewHTTPNode(fmt.Sprintf(":%d", port))

err = hk.Load(n)
assert.NoError(t, err)
Expand Down
11 changes: 2 additions & 9 deletions pkg/plugin/networkx/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ import (
"github.com/siyul-park/uniflow/pkg/scheme"
)

// HTTPNodeConfig represents the configuration of an HTTP node.
type HTTPNodeConfig struct {
Address string
}

// HTTPNode represents a node based on the HTTP protocol.
type HTTPNode struct {
address string
Expand Down Expand Up @@ -247,10 +242,8 @@ func init() {
}
}

// NewHTTPNode creates a new HTTPNode with the given configuration.
func NewHTTPNode(config HTTPNodeConfig) *HTTPNode {
address := config.Address

// NewHTTPNode creates a new HTTPNode.
func NewHTTPNode(address string) *HTTPNode {
n := &HTTPNode{
address: address,
server: new(http.Server),
Expand Down
20 changes: 7 additions & 13 deletions pkg/plugin/networkx/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ func TestNewHTTPNode(t *testing.T) {
port, err := freeport.GetFreePort()
assert.NoError(t, err)

n := NewHTTPNode(HTTPNodeConfig{
Address: fmt.Sprintf(":%d", port),
})
n := NewHTTPNode(fmt.Sprintf(":%d", port))
assert.NotNil(t, n)

assert.NoError(t, n.Close())
Expand All @@ -33,9 +31,7 @@ func TestHTTPNode_Port(t *testing.T) {
port, err := freeport.GetFreePort()
assert.NoError(t, err)

n := NewHTTPNode(HTTPNodeConfig{
Address: fmt.Sprintf(":%d", port),
})
n := NewHTTPNode(fmt.Sprintf(":%d", port))
defer n.Close()

p, ok := n.Port(node.PortIO)
Expand All @@ -59,9 +55,7 @@ func TestHTTPNode_ServeAndShutdown(t *testing.T) {
port, err := freeport.GetFreePort()
assert.NoError(t, err)

n := NewHTTPNode(HTTPNodeConfig{
Address: fmt.Sprintf(":%d", port),
})
n := NewHTTPNode(fmt.Sprintf(":%d", port))
defer n.Close()

errChan := make(chan error)
Expand All @@ -83,7 +77,7 @@ func TestHTTPNode_ServeAndShutdown(t *testing.T) {

func TestHTTPNode_ServeHTTP(t *testing.T) {
t.Run("IO", func(t *testing.T) {
n := NewHTTPNode(HTTPNodeConfig{})
n := NewHTTPNode("")
defer func() { _ = n.Close() }()

io := port.New()
Expand Down Expand Up @@ -119,7 +113,7 @@ func TestHTTPNode_ServeHTTP(t *testing.T) {
})

t.Run("In/Out", func(t *testing.T) {
n := NewHTTPNode(HTTPNodeConfig{})
n := NewHTTPNode("")
defer func() { _ = n.Close() }()

in := port.New()
Expand Down Expand Up @@ -162,7 +156,7 @@ func TestHTTPNode_ServeHTTP(t *testing.T) {

func BenchmarkHTTPNode_Send(b *testing.B) {
b.Run("IO", func(b *testing.B) {
n := NewHTTPNode(HTTPNodeConfig{})
n := NewHTTPNode("")
defer func() { _ = n.Close() }()

io := port.New()
Expand Down Expand Up @@ -198,7 +192,7 @@ func BenchmarkHTTPNode_Send(b *testing.B) {
})

b.Run("In/Out", func(b *testing.B) {
n := NewHTTPNode(HTTPNodeConfig{})
n := NewHTTPNode("")
defer func() { _ = n.Close() }()

in := port.New()
Expand Down

0 comments on commit 5b5062a

Please sign in to comment.