Skip to content

Commit

Permalink
fix: fixed marker package attempting to parse undefined markers (#280)
Browse files Browse the repository at this point in the history
* test: update tests to prove failure

It was discovered that this failure only happened to occur on collection
markers and not on regular markers.

Signed-off-by: Dustin Scott <sdustin@vmware.com>

* fix: Fixes #260 added check to ensure marker exists before adding to results

Signed-off-by: Dustin Scott <sdustin@vmware.com>

* test: fix test to include namespace on namespaced resource

Signed-off-by: Dustin Scott <sdustin@vmware.com>

* fix: Fixes #260, reversed previous fix and added proper fix

Signed-off-by: Dustin Scott <sdustin@vmware.com>

* test: added test for kubebuilder marker with semicolon naked delimiter

Signed-off-by: Dustin Scott <sdustin@vmware.com>
  • Loading branch information
scottd018 authored Mar 7, 2022
1 parent f2daa61 commit 8aadf85
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
17 changes: 17 additions & 0 deletions internal/markers/lexer/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,23 @@ func TestLexer(t *testing.T) {
{Type: lexer.LexemeEOF, Value: ""},
},
},
{
name: "kubebuilder marker",
input: `# +kubebuilder:validation:Enum=aws;azure;vmware`,
expected: []lexer.Lexeme{
{Type: lexer.LexemeComment, Value: "#"},
{Type: lexer.LexemeMarkerStart, Value: "+"},
{Type: lexer.LexemeScope, Value: "kubebuilder"},
{Type: lexer.LexemeSeparator, Value: ":"},
{Type: lexer.LexemeScope, Value: "validation"},
{Type: lexer.LexemeSeparator, Value: ":"},
{Type: lexer.LexemeArg, Value: "Enum"},
{Type: lexer.LexemeArgAssignment, Value: "="},
{Type: lexer.LexemeStringLiteral, Value: "aws;azure;vmware"},
{Type: lexer.LexemeMarkerEnd, Value: "\n"},
{Type: lexer.LexemeEOF, Value: ""},
},
},
}

focused := false
Expand Down
2 changes: 1 addition & 1 deletion internal/markers/lexer/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func lexNakedStringLiteral(l *Lexer, nextState stateFn) (stateFn, bool) {
exceptions := []rune{
':', '=', ' ', '"', '\'', '`',
',', '+', '{', '}', '[', ']',
'(', ')', ';', '\n', eof,
'(', ')', '\n', eof,
}

if argValue := l.consumeUntil(exceptions...); !argValue {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ data:
anotheroption: another
justtesting: multistringyaml
---
# +operator-builder:resource:collectionField=provider,value="aws",include
kind: ConfigMap
apiVersion: v1
metadata:
name: test-include
namespace: ingress-system # +operator-builder:field:name=namespace,default=ingress-system,type=string
labels:
# +operator-builder:collection:field:name=provider,type=string,default="aws",description=`
# +kubebuilder:validation:Enum=aws;azure;vmware
# This test ensures that kubebuilder markers with a semicolon properly work.
# See https://github.com/vmware-tanzu-labs/operator-builder/issues/260 for details.`
provider: "aws"
data:
test: "data"
---
apiVersion: v1
kind: Secret
metadata:
Expand Down
6 changes: 5 additions & 1 deletion test/cases/edge-standalone/.workloadConfig/resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ apiVersion: v1
metadata:
name: test-include
labels:
provider: "aws" # +operator-builder:field:name=provider,type=string,default="aws"
# +operator-builder:field:name=provider,type=string,default="aws",description=`
# +kubebuilder:validation:Enum=aws;azure;vmware
# This test ensures that kubebuilder markers with a semicolon properly work.
# See https://github.com/vmware-tanzu-labs/operator-builder/issues/260 for details.`
provider: "aws"
data:
test: "data"
---
Expand Down

0 comments on commit 8aadf85

Please sign in to comment.