mirror of
				https://github.com/steveiliop56/tinyauth.git
				synced 2025-10-30 21:55:43 +00:00 
			
		
		
		
	refactor: rework decoders logic for cleaner code
This commit is contained in:
		| @@ -9,52 +9,29 @@ import ( | ||||
| ) | ||||
|  | ||||
| func TestDecodeEnv(t *testing.T) { | ||||
| 	// Variables | ||||
| 	// Setup | ||||
| 	env := map[string]string{ | ||||
| 		"PROVIDERS_GOOGLE_CLIENT_ID":        "google-client-id", | ||||
| 		"PROVIDERS_GOOGLE_CLIENT_SECRET":    "google-client-secret", | ||||
| 		"PROVIDERS_MY_GITHUB_CLIENT_ID":     "github-client-id", | ||||
| 		"PROVIDERS_MY_GITHUB_CLIENT_SECRET": "github-client-secret", | ||||
| 	} | ||||
|  | ||||
| 	expected := config.Providers{ | ||||
| 		Providers: map[string]config.OAuthServiceConfig{ | ||||
| 			"client1": { | ||||
| 				ClientID:           "client1-id", | ||||
| 				ClientSecret:       "client1-secret", | ||||
| 				Scopes:             []string{"client1-scope1", "client1-scope2"}, | ||||
| 				RedirectURL:        "client1-redirect-url", | ||||
| 				AuthURL:            "client1-auth-url", | ||||
| 				UserinfoURL:        "client1-user-info-url", | ||||
| 				Name:               "Client1", | ||||
| 				InsecureSkipVerify: false, | ||||
| 			"google": { | ||||
| 				ClientID:     "google-client-id", | ||||
| 				ClientSecret: "google-client-secret", | ||||
| 			}, | ||||
| 			"client2": { | ||||
| 				ClientID:           "client2-id", | ||||
| 				ClientSecret:       "client2-secret", | ||||
| 				Scopes:             []string{"client2-scope1", "client2-scope2"}, | ||||
| 				RedirectURL:        "client2-redirect-url", | ||||
| 				AuthURL:            "client2-auth-url", | ||||
| 				UserinfoURL:        "client2-user-info-url", | ||||
| 				Name:               "My Awesome Client2", | ||||
| 				InsecureSkipVerify: false, | ||||
| 			"myGithub": { | ||||
| 				ClientID:     "github-client-id", | ||||
| 				ClientSecret: "github-client-secret", | ||||
| 			}, | ||||
| 		}, | ||||
| 	} | ||||
| 	test := map[string]string{ | ||||
| 		"PROVIDERS_CLIENT1_CLIENT_ID":            "client1-id", | ||||
| 		"PROVIDERS_CLIENT1_CLIENT_SECRET":        "client1-secret", | ||||
| 		"PROVIDERS_CLIENT1_SCOPES":               "client1-scope1,client1-scope2", | ||||
| 		"PROVIDERS_CLIENT1_REDIRECT_URL":         "client1-redirect-url", | ||||
| 		"PROVIDERS_CLIENT1_AUTH_URL":             "client1-auth-url", | ||||
| 		"PROVIDERS_CLIENT1_USER_INFO_URL":        "client1-user-info-url", | ||||
| 		"PROVIDERS_CLIENT1_NAME":                 "Client1", | ||||
| 		"PROVIDERS_CLIENT1_INSECURE_SKIP_VERIFY": "false", | ||||
| 		"PROVIDERS_CLIENT2_CLIENT_ID":            "client2-id", | ||||
| 		"PROVIDERS_CLIENT2_CLIENT_SECRET":        "client2-secret", | ||||
| 		"PROVIDERS_CLIENT2_SCOPES":               "client2-scope1,client2-scope2", | ||||
| 		"PROVIDERS_CLIENT2_REDIRECT_URL":         "client2-redirect-url", | ||||
| 		"PROVIDERS_CLIENT2_AUTH_URL":             "client2-auth-url", | ||||
| 		"PROVIDERS_CLIENT2_USER_INFO_URL":        "client2-user-info-url", | ||||
| 		"PROVIDERS_CLIENT2_NAME":                 "My Awesome Client2", | ||||
| 		"PROVIDERS_CLIENT2_INSECURE_SKIP_VERIFY": "false", | ||||
| 	} | ||||
|  | ||||
| 	// Test | ||||
| 	res, err := decoders.DecodeEnv(test) | ||||
| 	// Execute | ||||
| 	result, err := decoders.DecodeEnv[config.Providers, config.OAuthServiceConfig](env, "providers") | ||||
| 	assert.NilError(t, err) | ||||
| 	assert.DeepEqual(t, expected, res) | ||||
| 	assert.DeepEqual(t, result, expected) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Stavros
					Stavros