-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE/MINOR: add SectionAttributesGet to Parser interface to be abl…
…e to list available / existing attributes in a section
- Loading branch information
1 parent
585d83c
commit 147a23a
Showing
4 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
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 configs //nolint:testpackage | ||
|
||
import ( | ||
"slices" | ||
"strings" | ||
"testing" | ||
|
||
parser "github.com/haproxytech/config-parser/v5" | ||
"github.com/haproxytech/config-parser/v5/options" | ||
) | ||
|
||
func TestParseGetAttributesExistingOnly(t *testing.T) { | ||
tests := []struct { | ||
Name, Config string | ||
}{ | ||
{"configBasic1", configBasic1}, | ||
} | ||
for _, config := range tests { | ||
t.Run(config.Name, func(t *testing.T) { | ||
p, err := parser.New(options.String(config.Config)) | ||
if err != nil { | ||
t.Fatalf(err.Error()) | ||
} | ||
result, err := p.SectionAttributesGet(parser.Frontends, "http", true) | ||
if err != nil { | ||
t.Fatalf("err should be nil %v", err) | ||
} | ||
if 0 != slices.Compare(result, []string{ | ||
"mode", "bind", "default_backend", | ||
}) { | ||
t.Fatalf("retrieved attributes do not match %s", strings.Join(result, ", ")) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestParseGetAttributesComplete(t *testing.T) { | ||
tests := []struct { | ||
Name, Config string | ||
}{ | ||
{"configBasic1", configBasic1}, | ||
} | ||
for _, config := range tests { | ||
t.Run(config.Name, func(t *testing.T) { | ||
p, err := parser.New(options.String(config.Config)) | ||
if err != nil { | ||
t.Fatalf(err.Error()) | ||
} | ||
result, err := p.SectionAttributesGet(parser.Backends, "default_backend", false) | ||
if err != nil { | ||
t.Fatalf("err should be nil %v", err) | ||
} | ||
if !slices.Contains(result, "option tcp-smart-connect") { | ||
t.Fatalf("should contain registered attribute 'option tcp-smart-connect'") | ||
} | ||
}) | ||
} | ||
} |