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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
fix bug
  • Loading branch information
suchen-sci committed Nov 1, 2023
commit 4219c6019989e269518f70fbb899704021574cf7
2 changes: 1 addition & 1 deletion cmd/client/commandv2/convert/nginx/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (env *Env) Clone() (*Env, error) {
if err != nil {
return nil, err
}
newEnv.updateFn = getEnvUpdateFn(env)
newEnv.updateFn = getEnvUpdateFn(&newEnv)
return &newEnv, nil
}

Expand Down
50 changes: 50 additions & 0 deletions cmd/client/commandv2/convert/nginx/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,53 @@ func TestLoadIncludes(t *testing.T) {
assert.Equal(t, 1, len(httpDirectives))
}
}

func TestParsePayload(t *testing.T) {
tempDir := newTempTestDir(t)
defer tempDir.Clean()
{
nginxConf := `
events {}
http {
upstream backend {
server localhost:1234;
server localhost:2345 weight=10;
}

server {
listen 80;

location / {
proxy_set_header X-Path "prefix";
proxy_pass http:https://localhost:8080;
}

location /apis {
proxy_set_header X-Path "apis";
proxy_pass http:https://localhost:8880;

location /apis/v1 {
proxy_set_header X-Path "apis/v1";
proxy_pass http:https://localhost:8888;
}
}

location = /user {
proxy_pass http:https://localhost:8890;
}

location /upstream {
proxy_pass http:https://backend;
}
}
}
`
file := tempDir.Create("nginx.conf", []byte(nginxConf))
payload, err := crossplane.Parse(file, &crossplane.ParseOptions{})
assert.Nil(t, err)

config, err := parsePayload(payload)
assert.Nil(t, err)
printJson(config)
}
}
8 changes: 0 additions & 8 deletions cmd/client/commandv2/convert/nginx/test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package nginx

import (
"encoding/json"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -55,10 +54,3 @@ func (dir *tempTestDir) Clean() {
}
os.Remove(dir.dir)
}

func printJson(t *testing.T, v interface{}) {
t.Helper()
b, err := json.MarshalIndent(v, "", " ")
require.Nil(t, err)
t.Log(string(b))
}
10 changes: 9 additions & 1 deletion cmd/client/commandv2/convert/nginx/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@

package nginx

import "fmt"
import (
"encoding/json"
"fmt"
)

func directiveInfo(d *Directive) string {
return fmt.Sprintf("directive %s in line %d of file %s", d.Directive, d.Line, d.File)
}

func printJson(v interface{}) {
b, _ := json.MarshalIndent(v, "", " ")
fmt.Println(string(b))
}