Initial cloud-services repo - gateway service + pkg modules
This commit is contained in:
45
pkg/utils/auth_helper_test.go
Normal file
45
pkg/utils/auth_helper_test.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package utils_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"fiskerinc.com/modules/utils"
|
||||
)
|
||||
|
||||
func TestWriteProviderToContext(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
res := utils.AUTHGetProviderFromContext(ctx)
|
||||
if res != "" {
|
||||
t.Errorf("Expected context to not have a value under provider")
|
||||
}
|
||||
|
||||
provider := "testProvider"
|
||||
newCTX := utils.AUTHWriteProviderToContext(provider, ctx)
|
||||
res = utils.AUTHGetProviderFromContext(newCTX)
|
||||
if res != provider {
|
||||
t.Errorf("Expected: %s but got: %s", provider, res)
|
||||
}
|
||||
|
||||
res = utils.AUTHGetProviderFromContext(ctx)
|
||||
if res != "" {
|
||||
t.Errorf("Expected context to not change")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteProviderToRequest(t *testing.T) {
|
||||
r, err := http.NewRequest("GET", "http://example.com", nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
provider := "testProvider"
|
||||
|
||||
r = utils.AUTHWriteProviderToRequest(provider, r)
|
||||
|
||||
res := utils.AUTHGetProviderFromRequest(r)
|
||||
if res != provider {
|
||||
t.Errorf("Expected: %s but got: %s", provider, res)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user