-
Notifications
You must be signed in to change notification settings - Fork 0
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
Devops 831 fix env var cleanup upon change #23
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
94206ba
redo patch env var function
4153524
fix updating same container 2 times within the same apply to kube api
b398f1e
remove comment
0268ca9
add test cases
cf21b8f
bump github actions deps
271ec1d
replace append with proper Delete func
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
package controller | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
func Test_findEnvVarIndex(t *testing.T) { | ||
type args struct { | ||
envVarName string | ||
envVarList []corev1.EnvVar | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want int | ||
}{ | ||
{ | ||
name: "correctly finds the index of the env var", | ||
args: args{ | ||
envVarName: "test", | ||
envVarList: []corev1.EnvVar{ | ||
{ | ||
Name: "test", | ||
Value: "test", | ||
}, | ||
}, | ||
}, | ||
want: 0, | ||
}, | ||
{ | ||
name: "correctly finds the index of the env var", | ||
args: args{ | ||
envVarName: "test", | ||
envVarList: []corev1.EnvVar{ | ||
{ | ||
Name: "test1", | ||
Value: "test", | ||
}, | ||
}, | ||
}, | ||
want: -1, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := findEnvVarIndex(tt.args.envVarName, tt.args.envVarList); got != tt.want { | ||
t.Errorf("findEnvVarIndex() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func Test_unpatchEnvVarValue(t *testing.T) { | ||
type args struct { | ||
origValue string | ||
removalValue string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
}{ | ||
{ | ||
name: "correctly removes the value from the env var", | ||
args: args{ | ||
origValue: "test", | ||
removalValue: "test", | ||
}, | ||
want: "", | ||
}, | ||
{ | ||
name: "correctly removes the value from the env var", | ||
args: args{ | ||
origValue: "test", | ||
removalValue: "test1", | ||
}, | ||
want: "test", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := unpatchEnvVarValue(tt.args.origValue, tt.args.removalValue); got != tt.want { | ||
t.Errorf("unpatchEnvVarValue() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func Test_agentEnvVarArgument(t *testing.T) { | ||
type args struct { | ||
mountPath string | ||
agentCliFlags string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "correctly returns the agent env var argument", | ||
args: args{ | ||
mountPath: "test", | ||
agentCliFlags: "test", | ||
}, | ||
want: " -agentpath:test/agent/lightrun_agent.so=test", | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "correctly returns the agent env var argument", | ||
args: args{ | ||
mountPath: "test", | ||
agentCliFlags: "", | ||
}, | ||
want: " -agentpath:test/agent/lightrun_agent.so", | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "return error when agentpath with agentCliFlags has more than 1024 chars", | ||
args: args{ | ||
mountPath: "test", | ||
agentCliFlags: strings.Repeat("a", 1024), | ||
}, | ||
want: "", | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := agentEnvVarArgument(tt.args.mountPath, tt.args.agentCliFlags) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("agentEnvVarArgument() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if got != tt.want { | ||
t.Errorf("agentEnvVarArgument() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose this test represent a scenario where the arg envVarName is not in envVarList and therefore function return -1 , right ? in that case it's still true to name it "correctly finds the index of the env var" ? maybe test envVarName does not exist or something like that