-
Notifications
You must be signed in to change notification settings - Fork 988
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rough imp, unable to debug further recursion
- Loading branch information
Showing
3 changed files
with
209 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package models | ||
|
||
import log "github.com/sirupsen/logrus" | ||
|
||
// Custom error type so that we can give helpful messages in CLI | ||
type Error struct { | ||
Err error | ||
DebugMessage string | ||
FriendlyMessage string | ||
} | ||
|
||
func (e *Error) printFriendlyMessage() { | ||
log.Infoln(e.FriendlyMessage) | ||
} |
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,122 @@ | ||
package util | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/Infisical/infisical-merge/packages/models" | ||
) | ||
|
||
// References to self should return the value unaltered | ||
// func Test_SubstituteSecrets_When_ReferenceToSelf(t *testing.T) { | ||
|
||
// var tests = []struct { | ||
// Key string | ||
// Value string | ||
// ExpectedValue string | ||
// }{ | ||
// {Key: "A", Value: "${A}", ExpectedValue: "${A}"}, | ||
// {Key: "A", Value: "${A} ${A}", ExpectedValue: "${A} ${A}"}, | ||
// {Key: "A", Value: "${A}${A}", ExpectedValue: "${A}${A}"}, | ||
// } | ||
|
||
// for _, test := range tests { | ||
// secret := models.SingleEnvironmentVariable{ | ||
// Key: test.Key, | ||
// Value: test.Value, | ||
// } | ||
|
||
// secrets := []models.SingleEnvironmentVariable{secret} | ||
// result := SubstituteSecrets(secrets) | ||
|
||
// if result[0].Value != test.ExpectedValue { | ||
// t.Errorf("Test_SubstituteSecrets_When_ReferenceToSelf: expected %s but got %s for input %s", test.ExpectedValue, result[0].Value, test.Value) | ||
// } | ||
|
||
// } | ||
// } | ||
|
||
// func Test_SubstituteSecrets_When_ReferenceDoesNotExist(t *testing.T) { | ||
|
||
// var tests = []struct { | ||
// Key string | ||
// Value string | ||
// ExpectedValue string | ||
// }{ | ||
// {Key: "A", Value: "${X}", ExpectedValue: "${X}"}, | ||
// {Key: "A", Value: "${H}HELLO", ExpectedValue: "${H}HELLO"}, | ||
// {Key: "A", Value: "${L}${S}", ExpectedValue: "${L}${S}"}, | ||
// } | ||
|
||
// for _, test := range tests { | ||
// secret := models.SingleEnvironmentVariable{ | ||
// Key: test.Key, | ||
// Value: test.Value, | ||
// } | ||
|
||
// secrets := []models.SingleEnvironmentVariable{secret} | ||
// result := SubstituteSecrets(secrets) | ||
|
||
// if result[0].Value != test.ExpectedValue { | ||
// t.Errorf("Test_SubstituteSecrets_When_ReferenceToSelf: expected %s but got %s for input %s", test.ExpectedValue, result[0].Value, test.Value) | ||
// } | ||
|
||
// } | ||
// } | ||
|
||
func Test_SubstituteSecrets_When_ReferenceDoesNotExist_And_Self_Referencing(t *testing.T) { | ||
|
||
tests := []struct { | ||
Key string | ||
Value string | ||
ExpectedValue string | ||
}{ | ||
{ | ||
Key: "A", | ||
Value: "*${A}* ${X}", | ||
ExpectedValue: "*${A}*", | ||
}, | ||
{ | ||
Key: "H", | ||
Value: "${X} >>>", | ||
ExpectedValue: "*${A}*", | ||
}, | ||
{ | ||
Key: "X", | ||
Value: "DOMAIN", | ||
ExpectedValue: "DOMAIN", | ||
}, | ||
{ | ||
Key: "P", | ||
Value: "${X} === ${A} ${H}", | ||
ExpectedValue: "DOMAIN", | ||
}, | ||
// { | ||
// Key: "B", | ||
// Value: "*${A}*TOKEN*${X}*", | ||
// ExpectedValue: "*${A}*TOKEN*DOMAIN*", | ||
// }, | ||
// { | ||
// Key: "C", | ||
// Value: "*${A}* *${X}* *${B}* *${UNKNOWN}*", | ||
// ExpectedValue: "*${A}* *DOMAIN* **${A}*TOKEN*DOMAIN** *${UNKNOWN}*", | ||
// }, | ||
// { | ||
// Key: "W", | ||
// Value: "*${W}* ${LOL $JK} *${C}* *${C}*", | ||
// ExpectedValue: "*${W}* ${LOL $JK} **${A}* *DOMAIN* **${A}*TOKEN*DOMAIN** *${UNKNOWN}** **${A}* *DOMAIN* **${A}*TOKEN*DOMAIN** *${UNKNOWN}**", | ||
// }, | ||
} | ||
|
||
secrets := []models.SingleEnvironmentVariable{} | ||
for _, test := range tests { | ||
secrets = append(secrets, models.SingleEnvironmentVariable{Key: test.Key, Value: test.Value}) | ||
} | ||
|
||
SubstituteSecrets(secrets) | ||
|
||
// if result[0].Value != test.ExpectedValue { | ||
// t.Errorf("Test_SubstituteSecrets_When_ReferenceToSelf: expected %s but got %s for input %s", test.ExpectedValue, result[0].Value, test.Value) | ||
// } | ||
|
||
// fmt.Println(result) | ||
} |