From a6f26e44a072b28f6e756b2bcc095324b0c80d5d Mon Sep 17 00:00:00 2001 From: Helene Durand Date: Tue, 20 Feb 2024 17:37:26 +0100 Subject: [PATCH] BUG/MINOR: add compression algo-req algo-res type-req type-res --- parsers/compression-algo-req.go | 53 +++++++++++ parsers/compression-algo-req_generated.go | 99 ++++++++++++++++++++ parsers/compression-algo-res.go | 61 ++++++++++++ parsers/compression-algo-res_generated.go | 99 ++++++++++++++++++++ parsers/compression-type-req.go | 61 ++++++++++++ parsers/compression-type-req_generated.go | 99 ++++++++++++++++++++ parsers/compression-type-res.go | 61 ++++++++++++ parsers/compression-type-res_generated.go | 99 ++++++++++++++++++++ section-parsers.go | 18 +++- tests/compression-algo-req_generated_test.go | 82 ++++++++++++++++ tests/compression-algo-res_generated_test.go | 82 ++++++++++++++++ tests/compression-type-req_generated_test.go | 83 ++++++++++++++++ tests/compression-type-res_generated_test.go | 83 ++++++++++++++++ types/types-generic.go | 22 ++++- 14 files changed, 999 insertions(+), 3 deletions(-) create mode 100644 parsers/compression-algo-req.go create mode 100644 parsers/compression-algo-req_generated.go create mode 100644 parsers/compression-algo-res.go create mode 100644 parsers/compression-algo-res_generated.go create mode 100644 parsers/compression-type-req.go create mode 100644 parsers/compression-type-req_generated.go create mode 100644 parsers/compression-type-res.go create mode 100644 parsers/compression-type-res_generated.go create mode 100644 tests/compression-algo-req_generated_test.go create mode 100644 tests/compression-algo-res_generated_test.go create mode 100644 tests/compression-type-req_generated_test.go create mode 100644 tests/compression-type-res_generated_test.go diff --git a/parsers/compression-algo-req.go b/parsers/compression-algo-req.go new file mode 100644 index 0000000..ab49ea6 --- /dev/null +++ b/parsers/compression-algo-req.go @@ -0,0 +1,53 @@ +/* +Copyright 2022 HAProxy Technologies + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package parsers + +import ( + "fmt" + + "github.com/haproxytech/config-parser/v5/common" + "github.com/haproxytech/config-parser/v5/errors" + "github.com/haproxytech/config-parser/v5/types" +) + +type CompressionAlgoReq struct { + data *types.StringC + preComments []string // comments that appear before the actual line +} + +func (c *CompressionAlgoReq) Parse(line string, parts []string, comment string) (string, error) { + if len(parts) < 3 { + return "", &errors.ParseError{Parser: "CompressionAlgoReq", Line: line, Message: "Parse error"} + } + c.data = &types.StringC{ + Value: parts[2], + Comment: comment, + } + return "", nil +} + +func (c *CompressionAlgoReq) Result() ([]common.ReturnResultLine, error) { + if c.data == nil { + return nil, errors.ErrFetch + } + return []common.ReturnResultLine{ + { + Data: fmt.Sprintf("compression algo-req %s", c.data.Value), + Comment: c.data.Comment, + }, + }, nil +} diff --git a/parsers/compression-algo-req_generated.go b/parsers/compression-algo-req_generated.go new file mode 100644 index 0000000..c03451f --- /dev/null +++ b/parsers/compression-algo-req_generated.go @@ -0,0 +1,99 @@ +// Code generated by go generate; DO NOT EDIT. +/* +Copyright 2019 HAProxy Technologies + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package parsers + +import ( + "github.com/haproxytech/config-parser/v5/common" + "github.com/haproxytech/config-parser/v5/errors" + "github.com/haproxytech/config-parser/v5/types" +) + +func (p *CompressionAlgoReq) Init() { + p.data = nil + p.preComments = []string{} +} + +func (p *CompressionAlgoReq) GetParserName() string { + return "compression algo-req" +} + +func (p *CompressionAlgoReq) Get(createIfNotExist bool) (common.ParserData, error) { + if p.data == nil { + if createIfNotExist { + p.data = &types.StringC{} + return p.data, nil + } + return nil, errors.ErrFetch + } + return p.data, nil +} + +func (p *CompressionAlgoReq) GetPreComments() ([]string, error) { + return p.preComments, nil +} + +func (p *CompressionAlgoReq) SetPreComments(preComments []string) { + p.preComments = preComments +} + +func (p *CompressionAlgoReq) GetOne(index int) (common.ParserData, error) { + if index > 0 { + return nil, errors.ErrFetch + } + if p.data == nil { + return nil, errors.ErrFetch + } + return p.data, nil +} + +func (p *CompressionAlgoReq) Delete(index int) error { + p.Init() + return nil +} + +func (p *CompressionAlgoReq) Insert(data common.ParserData, index int) error { + return p.Set(data, index) +} + +func (p *CompressionAlgoReq) Set(data common.ParserData, index int) error { + if data == nil { + p.Init() + return nil + } + switch newValue := data.(type) { + case *types.StringC: + p.data = newValue + case types.StringC: + p.data = &newValue + default: + return errors.ErrInvalidData + } + return nil +} + +func (p *CompressionAlgoReq) PreParse(line string, parts []string, preComments []string, comment string) (string, error) { + changeState, err := p.Parse(line, parts, comment) + if err == nil && preComments != nil { + p.preComments = append(p.preComments, preComments...) + } + return changeState, err +} + +func (p *CompressionAlgoReq) ResultAll() ([]common.ReturnResultLine, []string, error) { + res, err := p.Result() + return res, p.preComments, err +} diff --git a/parsers/compression-algo-res.go b/parsers/compression-algo-res.go new file mode 100644 index 0000000..4fd5319 --- /dev/null +++ b/parsers/compression-algo-res.go @@ -0,0 +1,61 @@ +/* +Copyright 2022 HAProxy Technologies + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package parsers + +import ( + "strings" + + "github.com/haproxytech/config-parser/v5/common" + "github.com/haproxytech/config-parser/v5/errors" + "github.com/haproxytech/config-parser/v5/types" +) + +type CompressionAlgoRes struct { + data *types.StringSliceC + preComments []string // comments that appear before the actual line +} + +func (c *CompressionAlgoRes) Parse(line string, parts []string, comment string) (string, error) { + if len(parts) < 3 { + return "", &errors.ParseError{Parser: "CompressionAlgoRes", Line: line, Message: "Parse error"} + } + c.data = &types.StringSliceC{ + Value: parts[2:], + Comment: comment, + } + return "", nil +} + +func (c *CompressionAlgoRes) Result() ([]common.ReturnResultLine, error) { + if c.data == nil || len(c.data.Value) == 0 { + return nil, errors.ErrFetch + } + var result strings.Builder + result.WriteString("compression algo-res") + + for _, typereq := range c.data.Value { + result.WriteString(" ") + result.WriteString(typereq) + } + + return []common.ReturnResultLine{ + { + Data: result.String(), + Comment: c.data.Comment, + }, + }, nil +} diff --git a/parsers/compression-algo-res_generated.go b/parsers/compression-algo-res_generated.go new file mode 100644 index 0000000..e2ccd0a --- /dev/null +++ b/parsers/compression-algo-res_generated.go @@ -0,0 +1,99 @@ +// Code generated by go generate; DO NOT EDIT. +/* +Copyright 2019 HAProxy Technologies + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package parsers + +import ( + "github.com/haproxytech/config-parser/v5/common" + "github.com/haproxytech/config-parser/v5/errors" + "github.com/haproxytech/config-parser/v5/types" +) + +func (p *CompressionAlgoRes) Init() { + p.data = nil + p.preComments = []string{} +} + +func (p *CompressionAlgoRes) GetParserName() string { + return "compression algo-res" +} + +func (p *CompressionAlgoRes) Get(createIfNotExist bool) (common.ParserData, error) { + if p.data == nil { + if createIfNotExist { + p.data = &types.StringSliceC{} + return p.data, nil + } + return nil, errors.ErrFetch + } + return p.data, nil +} + +func (p *CompressionAlgoRes) GetPreComments() ([]string, error) { + return p.preComments, nil +} + +func (p *CompressionAlgoRes) SetPreComments(preComments []string) { + p.preComments = preComments +} + +func (p *CompressionAlgoRes) GetOne(index int) (common.ParserData, error) { + if index > 0 { + return nil, errors.ErrFetch + } + if p.data == nil { + return nil, errors.ErrFetch + } + return p.data, nil +} + +func (p *CompressionAlgoRes) Delete(index int) error { + p.Init() + return nil +} + +func (p *CompressionAlgoRes) Insert(data common.ParserData, index int) error { + return p.Set(data, index) +} + +func (p *CompressionAlgoRes) Set(data common.ParserData, index int) error { + if data == nil { + p.Init() + return nil + } + switch newValue := data.(type) { + case *types.StringSliceC: + p.data = newValue + case types.StringSliceC: + p.data = &newValue + default: + return errors.ErrInvalidData + } + return nil +} + +func (p *CompressionAlgoRes) PreParse(line string, parts []string, preComments []string, comment string) (string, error) { + changeState, err := p.Parse(line, parts, comment) + if err == nil && preComments != nil { + p.preComments = append(p.preComments, preComments...) + } + return changeState, err +} + +func (p *CompressionAlgoRes) ResultAll() ([]common.ReturnResultLine, []string, error) { + res, err := p.Result() + return res, p.preComments, err +} diff --git a/parsers/compression-type-req.go b/parsers/compression-type-req.go new file mode 100644 index 0000000..f3d8147 --- /dev/null +++ b/parsers/compression-type-req.go @@ -0,0 +1,61 @@ +/* +Copyright 2022 HAProxy Technologies + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package parsers + +import ( + "strings" + + "github.com/haproxytech/config-parser/v5/common" + "github.com/haproxytech/config-parser/v5/errors" + "github.com/haproxytech/config-parser/v5/types" +) + +type CompressionTypeReq struct { + data *types.StringSliceC + preComments []string // comments that appear before the actual line +} + +func (c *CompressionTypeReq) Parse(line string, parts []string, comment string) (string, error) { + if len(parts) < 3 { + return "", &errors.ParseError{Parser: "CompressionTypeReq", Line: line, Message: "Parse error"} + } + c.data = &types.StringSliceC{ + Value: parts[2:], + Comment: comment, + } + return "", nil +} + +func (c *CompressionTypeReq) Result() ([]common.ReturnResultLine, error) { + if c.data == nil || len(c.data.Value) == 0 { + return nil, errors.ErrFetch + } + var result strings.Builder + result.WriteString("compression type-req") + + for _, typereq := range c.data.Value { + result.WriteString(" ") + result.WriteString(typereq) + } + + return []common.ReturnResultLine{ + { + Data: result.String(), + Comment: c.data.Comment, + }, + }, nil +} diff --git a/parsers/compression-type-req_generated.go b/parsers/compression-type-req_generated.go new file mode 100644 index 0000000..71d7bef --- /dev/null +++ b/parsers/compression-type-req_generated.go @@ -0,0 +1,99 @@ +// Code generated by go generate; DO NOT EDIT. +/* +Copyright 2019 HAProxy Technologies + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package parsers + +import ( + "github.com/haproxytech/config-parser/v5/common" + "github.com/haproxytech/config-parser/v5/errors" + "github.com/haproxytech/config-parser/v5/types" +) + +func (p *CompressionTypeReq) Init() { + p.data = nil + p.preComments = []string{} +} + +func (p *CompressionTypeReq) GetParserName() string { + return "compression type-req" +} + +func (p *CompressionTypeReq) Get(createIfNotExist bool) (common.ParserData, error) { + if p.data == nil { + if createIfNotExist { + p.data = &types.StringSliceC{} + return p.data, nil + } + return nil, errors.ErrFetch + } + return p.data, nil +} + +func (p *CompressionTypeReq) GetPreComments() ([]string, error) { + return p.preComments, nil +} + +func (p *CompressionTypeReq) SetPreComments(preComments []string) { + p.preComments = preComments +} + +func (p *CompressionTypeReq) GetOne(index int) (common.ParserData, error) { + if index > 0 { + return nil, errors.ErrFetch + } + if p.data == nil { + return nil, errors.ErrFetch + } + return p.data, nil +} + +func (p *CompressionTypeReq) Delete(index int) error { + p.Init() + return nil +} + +func (p *CompressionTypeReq) Insert(data common.ParserData, index int) error { + return p.Set(data, index) +} + +func (p *CompressionTypeReq) Set(data common.ParserData, index int) error { + if data == nil { + p.Init() + return nil + } + switch newValue := data.(type) { + case *types.StringSliceC: + p.data = newValue + case types.StringSliceC: + p.data = &newValue + default: + return errors.ErrInvalidData + } + return nil +} + +func (p *CompressionTypeReq) PreParse(line string, parts []string, preComments []string, comment string) (string, error) { + changeState, err := p.Parse(line, parts, comment) + if err == nil && preComments != nil { + p.preComments = append(p.preComments, preComments...) + } + return changeState, err +} + +func (p *CompressionTypeReq) ResultAll() ([]common.ReturnResultLine, []string, error) { + res, err := p.Result() + return res, p.preComments, err +} diff --git a/parsers/compression-type-res.go b/parsers/compression-type-res.go new file mode 100644 index 0000000..12737ef --- /dev/null +++ b/parsers/compression-type-res.go @@ -0,0 +1,61 @@ +/* +Copyright 2022 HAProxy Technologies + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package parsers + +import ( + "strings" + + "github.com/haproxytech/config-parser/v5/common" + "github.com/haproxytech/config-parser/v5/errors" + "github.com/haproxytech/config-parser/v5/types" +) + +type CompressionTypeRes struct { + data *types.StringSliceC + preComments []string // comments that appear before the actual line +} + +func (c *CompressionTypeRes) Parse(line string, parts []string, comment string) (string, error) { + if len(parts) < 3 { + return "", &errors.ParseError{Parser: "CompressionTypeRes", Line: line, Message: "Parse error"} + } + c.data = &types.StringSliceC{ + Value: parts[2:], + Comment: comment, + } + return "", nil +} + +func (c *CompressionTypeRes) Result() ([]common.ReturnResultLine, error) { + if c.data == nil || len(c.data.Value) == 0 { + return nil, errors.ErrFetch + } + var result strings.Builder + result.WriteString("compression type-res") + + for _, typereq := range c.data.Value { + result.WriteString(" ") + result.WriteString(typereq) + } + + return []common.ReturnResultLine{ + { + Data: result.String(), + Comment: c.data.Comment, + }, + }, nil +} diff --git a/parsers/compression-type-res_generated.go b/parsers/compression-type-res_generated.go new file mode 100644 index 0000000..8488353 --- /dev/null +++ b/parsers/compression-type-res_generated.go @@ -0,0 +1,99 @@ +// Code generated by go generate; DO NOT EDIT. +/* +Copyright 2019 HAProxy Technologies + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package parsers + +import ( + "github.com/haproxytech/config-parser/v5/common" + "github.com/haproxytech/config-parser/v5/errors" + "github.com/haproxytech/config-parser/v5/types" +) + +func (p *CompressionTypeRes) Init() { + p.data = nil + p.preComments = []string{} +} + +func (p *CompressionTypeRes) GetParserName() string { + return "compression type-res" +} + +func (p *CompressionTypeRes) Get(createIfNotExist bool) (common.ParserData, error) { + if p.data == nil { + if createIfNotExist { + p.data = &types.StringSliceC{} + return p.data, nil + } + return nil, errors.ErrFetch + } + return p.data, nil +} + +func (p *CompressionTypeRes) GetPreComments() ([]string, error) { + return p.preComments, nil +} + +func (p *CompressionTypeRes) SetPreComments(preComments []string) { + p.preComments = preComments +} + +func (p *CompressionTypeRes) GetOne(index int) (common.ParserData, error) { + if index > 0 { + return nil, errors.ErrFetch + } + if p.data == nil { + return nil, errors.ErrFetch + } + return p.data, nil +} + +func (p *CompressionTypeRes) Delete(index int) error { + p.Init() + return nil +} + +func (p *CompressionTypeRes) Insert(data common.ParserData, index int) error { + return p.Set(data, index) +} + +func (p *CompressionTypeRes) Set(data common.ParserData, index int) error { + if data == nil { + p.Init() + return nil + } + switch newValue := data.(type) { + case *types.StringSliceC: + p.data = newValue + case types.StringSliceC: + p.data = &newValue + default: + return errors.ErrInvalidData + } + return nil +} + +func (p *CompressionTypeRes) PreParse(line string, parts []string, preComments []string, comment string) (string, error) { + changeState, err := p.Parse(line, parts, comment) + if err == nil && preComments != nil { + p.preComments = append(p.preComments, preComments...) + } + return changeState, err +} + +func (p *CompressionTypeRes) ResultAll() ([]common.ReturnResultLine, []string, error) { + res, err := p.Result() + return res, p.preComments, err +} diff --git a/section-parsers.go b/section-parsers.go index 22234e5..9f91698 100644 --- a/section-parsers.go +++ b/section-parsers.go @@ -175,7 +175,11 @@ func (p *configParser) getDefaultParser() *Parsers { addParser(parser, &sequence, &simple.Time{Name: "srvtcpka-intvl"}) addParser(parser, &sequence, &simple.Word{Name: "server-state-file-name"}) addParser(parser, &sequence, &parsers.CompressionAlgo{}) + addParser(parser, &sequence, &parsers.CompressionAlgoReq{}) + addParser(parser, &sequence, &parsers.CompressionAlgoRes{}) addParser(parser, &sequence, &parsers.CompressionType{}) + addParser(parser, &sequence, &parsers.CompressionTypeReq{}) + addParser(parser, &sequence, &parsers.CompressionTypeRes{}) addParser(parser, &sequence, &parsers.CompressionOffload{}) addParser(parser, &sequence, &parsers.CompressionDirection{}) addParser(parser, &sequence, &parsers.DefaultServer{}) @@ -482,7 +486,11 @@ func (p *configParser) getFrontendParser() *Parsers { addParser(parser, &sequence, &simple.Time{Name: "clitcpka-intvl"}) addParser(parser, &sequence, &filters.Filters{}) addParser(parser, &sequence, &parsers.CompressionAlgo{}) + addParser(parser, &sequence, &parsers.CompressionAlgoReq{}) + addParser(parser, &sequence, &parsers.CompressionAlgoRes{}) addParser(parser, &sequence, &parsers.CompressionType{}) + addParser(parser, &sequence, &parsers.CompressionTypeReq{}) + addParser(parser, &sequence, &parsers.CompressionTypeRes{}) addParser(parser, &sequence, &parsers.CompressionOffload{}) addParser(parser, &sequence, &tcp.Requests{}) addParser(parser, &sequence, &stats.Stats{Mode: "frontend"}) @@ -588,7 +596,11 @@ func (p *configParser) getBackendParser() *Parsers { addParser(parser, &sequence, &parsers.Stick{}) addParser(parser, &sequence, &filters.Filters{}) addParser(parser, &sequence, &parsers.CompressionAlgo{}) + addParser(parser, &sequence, &parsers.CompressionAlgoReq{}) + addParser(parser, &sequence, &parsers.CompressionAlgoRes{}) addParser(parser, &sequence, &parsers.CompressionType{}) + addParser(parser, &sequence, &parsers.CompressionTypeReq{}) + addParser(parser, &sequence, &parsers.CompressionTypeRes{}) addParser(parser, &sequence, &parsers.CompressionOffload{}) addParser(parser, &sequence, &parsers.CompressionDirection{}) addParser(parser, &sequence, &tcp.Requests{}) @@ -729,9 +741,13 @@ func (p *configParser) getListenParser() *Parsers { addParser(parser, &sequence, &parsers.Stick{}) addParser(parser, &sequence, &filters.Filters{}) addParser(parser, &sequence, &parsers.CompressionAlgo{}) + addParser(parser, &sequence, &parsers.CompressionAlgoReq{}) + addParser(parser, &sequence, &parsers.CompressionAlgoRes{}) addParser(parser, &sequence, &parsers.CompressionType{}) + addParser(parser, &sequence, &parsers.CompressionTypeReq{}) + addParser(parser, &sequence, &parsers.CompressionTypeRes{}) addParser(parser, &sequence, &parsers.CompressionOffload{}) - addParser(parser, &sequence, &parsers.CompressionType{}) + addParser(parser, &sequence, &parsers.CompressionDirection{}) addParser(parser, &sequence, &tcp.Requests{}) addParser(parser, &sequence, &stats.Stats{Mode: "listen"}) addParser(parser, &sequence, &parsers.HTTPReuse{}) diff --git a/tests/compression-algo-req_generated_test.go b/tests/compression-algo-req_generated_test.go new file mode 100644 index 0000000..d817a16 --- /dev/null +++ b/tests/compression-algo-req_generated_test.go @@ -0,0 +1,82 @@ +// Code generated by go generate; DO NOT EDIT. +/* +Copyright 2019 HAProxy Technologies + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package tests + +import ( + "fmt" + "strings" + "testing" + + "github.com/haproxytech/config-parser/v5/parsers" +) + +func TestCompressionAlgoReq(t *testing.T) { + tests := map[string]bool{ + "compression algo-req gzip": true, + "compression algo-req": false, + "---": false, + "--- ---": false, + } + parser := &parsers.CompressionAlgoReq{} + for command, shouldPass := range tests { + t.Run(command, func(t *testing.T) { + line := strings.TrimSpace(command) + lines := strings.SplitN(line, "\n", -1) + var err error + parser.Init() + if len(lines) > 1 { + for _, line = range lines { + line = strings.TrimSpace(line) + if err = ProcessLine(line, parser); err != nil { + break + } + } + } else { + err = ProcessLine(line, parser) + } + if shouldPass { + if err != nil { + t.Errorf(err.Error()) + return + } + result, err := parser.Result() + if err != nil { + t.Errorf(err.Error()) + return + } + var returnLine string + if result[0].Comment == "" { + returnLine = result[0].Data + } else { + returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) + } + if command != returnLine { + t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + } + } else { + if err == nil { + t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + } + _, parseErr := parser.Result() + if parseErr == nil { + t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + } + } + }) + } +} diff --git a/tests/compression-algo-res_generated_test.go b/tests/compression-algo-res_generated_test.go new file mode 100644 index 0000000..7da0d71 --- /dev/null +++ b/tests/compression-algo-res_generated_test.go @@ -0,0 +1,82 @@ +// Code generated by go generate; DO NOT EDIT. +/* +Copyright 2019 HAProxy Technologies + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package tests + +import ( + "fmt" + "strings" + "testing" + + "github.com/haproxytech/config-parser/v5/parsers" +) + +func TestCompressionAlgoRes(t *testing.T) { + tests := map[string]bool{ + "compression algo-res gzip raw-deflate": true, + "compression algo-res": false, + "---": false, + "--- ---": false, + } + parser := &parsers.CompressionAlgoRes{} + for command, shouldPass := range tests { + t.Run(command, func(t *testing.T) { + line := strings.TrimSpace(command) + lines := strings.SplitN(line, "\n", -1) + var err error + parser.Init() + if len(lines) > 1 { + for _, line = range lines { + line = strings.TrimSpace(line) + if err = ProcessLine(line, parser); err != nil { + break + } + } + } else { + err = ProcessLine(line, parser) + } + if shouldPass { + if err != nil { + t.Errorf(err.Error()) + return + } + result, err := parser.Result() + if err != nil { + t.Errorf(err.Error()) + return + } + var returnLine string + if result[0].Comment == "" { + returnLine = result[0].Data + } else { + returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) + } + if command != returnLine { + t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + } + } else { + if err == nil { + t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + } + _, parseErr := parser.Result() + if parseErr == nil { + t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + } + } + }) + } +} diff --git a/tests/compression-type-req_generated_test.go b/tests/compression-type-req_generated_test.go new file mode 100644 index 0000000..17b0636 --- /dev/null +++ b/tests/compression-type-req_generated_test.go @@ -0,0 +1,83 @@ +// Code generated by go generate; DO NOT EDIT. +/* +Copyright 2019 HAProxy Technologies + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package tests + +import ( + "fmt" + "strings" + "testing" + + "github.com/haproxytech/config-parser/v5/parsers" +) + +func TestCompressionTypeReq(t *testing.T) { + tests := map[string]bool{ + "compression type-req text/plain": true, + "compression type-req text/plain application/json": true, + "compression type-req": false, + "---": false, + "--- ---": false, + } + parser := &parsers.CompressionTypeReq{} + for command, shouldPass := range tests { + t.Run(command, func(t *testing.T) { + line := strings.TrimSpace(command) + lines := strings.SplitN(line, "\n", -1) + var err error + parser.Init() + if len(lines) > 1 { + for _, line = range lines { + line = strings.TrimSpace(line) + if err = ProcessLine(line, parser); err != nil { + break + } + } + } else { + err = ProcessLine(line, parser) + } + if shouldPass { + if err != nil { + t.Errorf(err.Error()) + return + } + result, err := parser.Result() + if err != nil { + t.Errorf(err.Error()) + return + } + var returnLine string + if result[0].Comment == "" { + returnLine = result[0].Data + } else { + returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) + } + if command != returnLine { + t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + } + } else { + if err == nil { + t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + } + _, parseErr := parser.Result() + if parseErr == nil { + t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + } + } + }) + } +} diff --git a/tests/compression-type-res_generated_test.go b/tests/compression-type-res_generated_test.go new file mode 100644 index 0000000..d26e647 --- /dev/null +++ b/tests/compression-type-res_generated_test.go @@ -0,0 +1,83 @@ +// Code generated by go generate; DO NOT EDIT. +/* +Copyright 2019 HAProxy Technologies + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package tests + +import ( + "fmt" + "strings" + "testing" + + "github.com/haproxytech/config-parser/v5/parsers" +) + +func TestCompressionTypeRes(t *testing.T) { + tests := map[string]bool{ + "compression type-res text/plain": true, + "compression type-res text/plain application/json": true, + "compression type-res": false, + "---": false, + "--- ---": false, + } + parser := &parsers.CompressionTypeRes{} + for command, shouldPass := range tests { + t.Run(command, func(t *testing.T) { + line := strings.TrimSpace(command) + lines := strings.SplitN(line, "\n", -1) + var err error + parser.Init() + if len(lines) > 1 { + for _, line = range lines { + line = strings.TrimSpace(line) + if err = ProcessLine(line, parser); err != nil { + break + } + } + } else { + err = ProcessLine(line, parser) + } + if shouldPass { + if err != nil { + t.Errorf(err.Error()) + return + } + result, err := parser.Result() + if err != nil { + t.Errorf(err.Error()) + return + } + var returnLine string + if result[0].Comment == "" { + returnLine = result[0].Data + } else { + returnLine = fmt.Sprintf("%s # %s", result[0].Data, result[0].Comment) + } + if command != returnLine { + t.Errorf(fmt.Sprintf("error: has [%s] expects [%s]", returnLine, command)) + } + } else { + if err == nil { + t.Errorf(fmt.Sprintf("error: did not throw error for line [%s]", line)) + } + _, parseErr := parser.Result() + if parseErr == nil { + t.Errorf(fmt.Sprintf("error: did not throw error on result for line [%s]", line)) + } + } + }) + } +} diff --git a/types/types-generic.go b/types/types-generic.go index 7f84db2..51d1b6d 100644 --- a/types/types-generic.go +++ b/types/types-generic.go @@ -77,7 +77,7 @@ type Int64C struct { Comment string } -// String is used by parsers Mode, DefaultBackend, SimpleTimeTwoWords, StatsTimeout, CompressionDirection +// String is used by parsers Mode, DefaultBackend, SimpleTimeTwoWords, StatsTimeout, CompressionDirection, CompressionAlgoReq // //generate:type:Mode //name:mode @@ -104,12 +104,16 @@ type Int64C struct { //name:compression direction //test:ok:compression direction both //test:fail:compression direction +//generate:type:CompressionAlgoReq +//name:compression algo-req +//test:ok:compression algo-req gzip +//test:fail:compression algo-req type StringC struct { Value string Comment string } -// StringSliceC is used by ConfigSnippet, CompressionAlgo, CompressionType +// StringSliceC is used by ConfigSnippet, CompressionAlgo, CompressionType, CompressionTypeReq, CompressionTypeRes, CompressionAlgoRes // //generate:type:ConfigSnippet //name:config-snippet @@ -125,6 +129,20 @@ type StringC struct { //test:ok:compression type text/plain //test:ok:compression type text/plain application/json //test:fail:compression type +//generate:type:CompressionTypeReq +//name:compression type-req +//test:ok:compression type-req text/plain +//test:ok:compression type-req text/plain application/json +//test:fail:compression type-req +//generate:type:CompressionTypeRes +//name:compression type-res +//test:ok:compression type-res text/plain +//test:ok:compression type-res text/plain application/json +//test:fail:compression type-res +//generate:type:CompressionAlgoRes +//name:compression algo-res +//test:ok:compression algo-res gzip raw-deflate +//test:fail:compression algo-res type StringSliceC struct { Value []string Comment string