Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support nginx conf #1130

Merged
merged 23 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add more test in cmd
  • Loading branch information
suchen-sci committed Nov 7, 2023
commit 5a8c60604aed45c4f4d27cb7cd99c78576ba55ed
10 changes: 10 additions & 0 deletions cmd/client/commandv2/convert/nginx/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ func Cmd() *cobra.Command {
Use: "nginx",
Short: "Convert nginx.conf to easegress yaml file",
Args: func(cmd *cobra.Command, args []string) error {
if flags.NginxConf == "" {
return fmt.Errorf("nginx.conf file path is required")
}
if flags.Output == "" {
return fmt.Errorf("output yaml file path is required")
}
if flags.Prefix == "" {
return fmt.Errorf("prefix is required")
}
return nil
},
Run: func(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -128,5 +137,6 @@ func writeYaml(filename string, servers []*common.HTTPServerSpec, pipelines []*c
file.WriteString(string(data))
file.WriteString("\n---\n")
}
file.Sync()
return nil
}
40 changes: 40 additions & 0 deletions cmd/client/commandv2/convert/nginx/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package nginx

import (
"io"
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -26,4 +28,42 @@ import (
func TestCmd(t *testing.T) {
cmd := Cmd()
assert.NotNil(t, cmd)
cmd.ParseFlags([]string{""})
assert.NotNil(t, cmd.Args(cmd, []string{}))

cmd.ParseFlags([]string{"-f", "test.conf"})
assert.NotNil(t, cmd.Args(cmd, []string{}))

cmd.ParseFlags([]string{"-o", "test.yaml"})
assert.NotNil(t, cmd.Args(cmd, []string{}))

cmd.ParseFlags([]string{"--prefix", "test"})
assert.Nil(t, cmd.Args(cmd, []string{}))

tempDir := newTempTestDir(t)
defer tempDir.Clean()

nginxConf := `
events {}
http {
server {
listen 127.0.0.1:8080;

location = /user {
proxy_pass http:https://localhost:9999;
}
}
}
`
nginxFile := tempDir.Create("nginx.conf", []byte(nginxConf))
outputFile := tempDir.Create("test.yaml", []byte(""))
cmd.ParseFlags([]string{"-f", nginxFile, "-o", outputFile, "--prefix", "test"})
cmd.Run(cmd, []string{})
file, err := os.Open(outputFile)
assert.Nil(t, err)
defer file.Close()
data, err := io.ReadAll(file)
assert.Nil(t, err)
assert.Contains(t, string(data), "test-8080")
assert.Contains(t, string(data), "test-user")
}
1 change: 1 addition & 0 deletions cmd/client/commandv2/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ import (
func TestCmd(t *testing.T) {
cmd := Cmd()
assert.NotNil(t, cmd)
assert.Error(t, cmd.Args(cmd, nil))
}
Loading