package utils_test

import (
	"context"
	"net/http"
	"testing"

	"github.com/fiskerinc/cloud-services/pkg/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)
	}
}
