<commit_before>package flame

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

	"github.com/256dpi/fire"

	"github.com/stretchr/testify/assert"
)

func TestCallbackMissingAccessToken(t *testing.T) {
	cb := Callback("foo")

	req, err := http.NewRequest("GET", "foo", nil)
	assert.NoError(t, err)

	ctx := &fire.Context{
		HTTPRequest: req,
	}

	err = cb(ctx)
	assert.Error(t, err)
}

func TestCallbackInsufficientAccessToken(t *testing.T) {
	cb := Callback("foo")

	req, err := http.NewRequest("GET", "foo", nil)
	assert.NoError(t, err)

	at := &AccessToken{
		Scope: []string{"bar"},
	}

	req = req.WithContext(context.WithValue(req.Context(), AccessTokenContextKey, at))

	ctx := &fire.Context{
		HTTPRequest: req,
	}

	err = cb(ctx)
	assert.Error(t, err)
}

func TestCallbackProperAccessToken(t *testing.T) {
	cb := Callback("foo")

	req, err := http.NewRequest("GET", "foo", nil)
	assert.NoError(t, err)

	at := &AccessToken{
		Scope: []string{"foo"},
	}

	req = req.WithContext(context.WithValue(req.Context(), AccessTokenContextKey, at))

	ctx := &fire.Context{
		HTTPRequest: req,
	}

	err = cb(ctx)
	assert.NoError(t, err)
}<commit_msg>simplified<commit_after>package flame

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

	"github.com/256dpi/fire"

	"github.com/stretchr/testify/assert"
)

func TestCallbackMissingAccessToken(t *testing.T) {
	req, err := http.NewRequest("GET", "foo", nil)
	assert.NoError(t, err)

	ctx := &fire.Context{
		HTTPRequest: req,
	}

	err = Callback("foo")(ctx)
	assert.Error(t, err)
}

func TestCallbackInsufficientAccessToken(t *testing.T) {
	req, err := http.NewRequest("GET", "foo", nil)
	assert.NoError(t, err)

	at := &AccessToken{
		Scope: []string{"bar"},
	}

	req = req.WithContext(context.WithValue(req.Context(), AccessTokenContextKey, at))

	ctx := &fire.Context{
		HTTPRequest: req,
	}

	err = Callback("foo")(ctx)
	assert.Error(t, err)
}

func TestCallbackProperAccessToken(t *testing.T) {
	req, err := http.NewRequest("GET", "foo", nil)
	assert.NoError(t, err)

	at := &AccessToken{
		Scope: []string{"foo"},
	}

	req = req.WithContext(context.WithValue(req.Context(), AccessTokenContextKey, at))

	ctx := &fire.Context{
		HTTPRequest: req,
	}

	err = Callback("foo")(ctx)
	assert.NoError(t, err)
}
{'fraction_non_alphanumeric': 0.17767857142857144, 'fraction_numerical': 0.0026785714285714286, 'mean_word_length': 4.746153846153846, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5683125', 'n_tokens_mistral': 895, 'n_tokens_neox': 853, 'n_words': 162}