-
Notifications
You must be signed in to change notification settings - Fork 66
Allow extensions for token parameters #1241 #1244
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
Merged
+1,645
−656
Merged
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
45525ce
pp extensions as requested + extensive unit-tests for the public para…
adecaro 39e5025
fsc update
adecaro 35729ca
fix pp validation
adecaro b4603e2
Extras function
adecaro 3b32c2c
fix
adecaro 7cc9adb
check extras is not nil
adecaro 1c3bc91
unit-test fix
adecaro 5244b48
token gen extenstion + FSC update
adecaro bb0ab94
tokengen update support + unit-tests
adecaro 27c6c49
lint fix
adecaro b31d34f
cleanup
adecaro 56b5f2a
tokegen cleanup + readme
adecaro c1818cf
fix comment to function
adecaro 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 hidden or 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 hidden or 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 hidden or 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,177 @@ | ||
| /* | ||
| Copyright IBM Corp. All Rights Reserved. | ||
|
|
||
| SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package common | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestLoadExtras(t *testing.T) { | ||
| // Create a temporary directory for test files | ||
| tempDir := t.TempDir() | ||
|
|
||
| // Test case 1: Successfully load multiple files | ||
| t.Run("success_multiple_files", func(t *testing.T) { | ||
| // Create test files | ||
| file1Path := filepath.Join(tempDir, "test1.json") | ||
| file1Content := []byte(`{"key": "value1"}`) | ||
| if err := os.WriteFile(file1Path, file1Content, 0644); err != nil { | ||
| t.Fatalf("failed to create test file: %v", err) | ||
| } | ||
|
|
||
| file2Path := filepath.Join(tempDir, "test2.json") | ||
| file2Content := []byte(`{"key": "value2"}`) | ||
| if err := os.WriteFile(file2Path, file2Content, 0644); err != nil { | ||
| t.Fatalf("failed to create test file: %v", err) | ||
| } | ||
|
|
||
| extraFiles := []string{ | ||
| "foo=" + file1Path, | ||
| "bar=" + file2Path, | ||
| } | ||
|
|
||
| result, err := LoadExtras(extraFiles) | ||
| if err != nil { | ||
| t.Fatalf("expected no error, got: %v", err) | ||
| } | ||
|
|
||
| if len(result) != 2 { | ||
| t.Errorf("expected 2 entries, got %d", len(result)) | ||
| } | ||
|
|
||
| if string(result["foo"]) != string(file1Content) { | ||
| t.Errorf("expected %q for foo, got %q", string(file1Content), string(result["foo"])) | ||
| } | ||
|
|
||
| if string(result["bar"]) != string(file2Content) { | ||
| t.Errorf("expected %q for bar, got %q", string(file2Content), string(result["bar"])) | ||
| } | ||
| }) | ||
|
|
||
| // Test case 2: Empty input slice | ||
| t.Run("empty_input", func(t *testing.T) { | ||
| extraFiles := []string{} | ||
|
|
||
| result, err := LoadExtras(extraFiles) | ||
| if err != nil { | ||
| t.Fatalf("expected no error, got: %v", err) | ||
| } | ||
|
|
||
| if len(result) != 0 { | ||
| t.Errorf("expected empty map, got %d entries", len(result)) | ||
| } | ||
| }) | ||
|
|
||
| // Test case 3: File does not exist | ||
| t.Run("file_not_found", func(t *testing.T) { | ||
| extraFiles := []string{ | ||
| "missing=" + filepath.Join(tempDir, "nonexistent.json"), | ||
| } | ||
|
|
||
| result, err := LoadExtras(extraFiles) | ||
| if err == nil { | ||
| t.Fatal("expected error for missing file, got nil") | ||
| } | ||
|
|
||
| if result != nil { | ||
| t.Errorf("expected nil result on error, got: %v", result) | ||
| } | ||
| }) | ||
|
|
||
| // Test case 4: Invalid format - no colon | ||
| t.Run("invalid_format_no_colon", func(t *testing.T) { | ||
| extraFiles := []string{"foobar"} | ||
|
|
||
| result, err := LoadExtras(extraFiles) | ||
| if err == nil { | ||
| t.Fatal("expected error for invalid format, got nil") | ||
| } | ||
|
|
||
| if result != nil { | ||
| t.Errorf("expected nil result on error, got: %v", result) | ||
| } | ||
| }) | ||
|
|
||
| // Test case 5: Invalid format - empty key | ||
| t.Run("invalid_format_empty_key", func(t *testing.T) { | ||
| extraFiles := []string{"=" + filepath.Join(tempDir, "test.json")} | ||
|
|
||
| result, err := LoadExtras(extraFiles) | ||
| if err == nil { | ||
| t.Fatal("expected error for empty key, got nil") | ||
| } | ||
|
|
||
| if result != nil { | ||
| t.Errorf("expected nil result on error, got: %v", result) | ||
| } | ||
| }) | ||
|
|
||
| // Test case 6: Invalid format - empty filepath | ||
| t.Run("invalid_format_empty_filepath", func(t *testing.T) { | ||
| extraFiles := []string{"key="} | ||
|
|
||
| result, err := LoadExtras(extraFiles) | ||
| if err == nil { | ||
| t.Fatal("expected error for empty filepath, got nil") | ||
| } | ||
|
|
||
| if result != nil { | ||
| t.Errorf("expected nil result on error, got: %v", result) | ||
| } | ||
| }) | ||
|
|
||
| // Test case 7: Filepath with colons (e.g., Windows paths or URLs) | ||
| t.Run("filepath_with_colons", func(t *testing.T) { | ||
| filePath := filepath.Join(tempDir, "test.json") | ||
| fileContent := []byte("content") | ||
| if err := os.WriteFile(filePath, fileContent, 0644); err != nil { | ||
| t.Fatalf("failed to create test file: %v", err) | ||
| } | ||
|
|
||
| // Simulate a key with filepath that might have colons | ||
| extraFiles := []string{ | ||
| "mykey=" + filePath, | ||
| } | ||
|
|
||
| result, err := LoadExtras(extraFiles) | ||
| if err != nil { | ||
| t.Fatalf("expected no error, got: %v", err) | ||
| } | ||
|
|
||
| if string(result["mykey"]) != string(fileContent) { | ||
| t.Errorf("expected %q, got %q", string(fileContent), string(result["mykey"])) | ||
| } | ||
| }) | ||
|
|
||
| // Test case 8: Binary file content | ||
| t.Run("binary_content", func(t *testing.T) { | ||
| filePath := filepath.Join(tempDir, "binary.dat") | ||
| binaryContent := []byte{0x00, 0x01, 0x02, 0xFF, 0xFE, 0xFD} | ||
| if err := os.WriteFile(filePath, binaryContent, 0644); err != nil { | ||
| t.Fatalf("failed to create test file: %v", err) | ||
| } | ||
|
|
||
| extraFiles := []string{"binary=" + filePath} | ||
|
|
||
| result, err := LoadExtras(extraFiles) | ||
| if err != nil { | ||
| t.Fatalf("expected no error, got: %v", err) | ||
| } | ||
|
|
||
| if len(result["binary"]) != len(binaryContent) { | ||
| t.Errorf("expected length %d, got %d", len(binaryContent), len(result["binary"])) | ||
| } | ||
|
|
||
| for i, b := range binaryContent { | ||
| if result["binary"][i] != b { | ||
| t.Errorf("byte mismatch at index %d: expected %x, got %x", i, b, result["binary"][i]) | ||
| } | ||
| } | ||
| }) | ||
| } |
This file contains hidden or 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 hidden or 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.
it looks like it's actually expecting key=filepath instead of key:filepath (the : is also in the comment above the function)