<commit_before>package fs

import (
	"encoding/json"
	"fmt"
	"testing"

	"github.com/koding/fuseklient/transport"
	. "github.com/smartystreets/goconvey/convey"
)

// fakeTransport implements Transport; is used in testing Transport requests
// and mocking responses.
type fakeTransport struct {
	TripResponses map[string]interface{}
}

func (f *fakeTransport) Trip(methodName string, req interface{}, res interface{}) error {
	r, ok := f.TripResponses[methodName]
	if !ok {
		return fmt.Errorf("Expected '%s' to be in list of mocked responses.", methodName)
	}

	bytes, err := json.Marshal(r)
	if err != nil {
		return err
	}

	return json.Unmarshal(bytes, &res)
}

func TestFakeTransport(t *testing.T) {
	Convey("Given fake transport", t, func() {
		ft := &fakeTransport{
			TripResponses: map[string]interface{}{"indiana": struct{ Name string }{"jones"}},
		}

		Convey("It implements Transport", func() {
			var _ transport.Transport = (*fakeTransport)(nil)
		})

		Convey("It should return error if method don't exist", func() {
			So(ft.Trip("random", "", ""), ShouldNotBeNil)
		})

		Convey("It should return unmarshal mock into response for method", func() {<commit_msg>panic if fakeTransport#Trip is called with unknown Trip name in tests<commit_after>package fs

import (
	"encoding/json"
	"fmt"
	"testing"

	"github.com/koding/fuseklient/transport"
	. "github.com/smartystreets/goconvey/convey"
)

// fakeTransport implements Transport; is used in testing Transport requests
// and mocking responses.
type fakeTransport struct {
	TripResponses map[string]interface{}
}

func (f *fakeTransport) Trip(methodName string, req interface{}, res interface{}) error {
	r, ok := f.TripResponses[methodName]
	if !ok {
		panic(fmt.Sprintf("Expected '%s' to be in list of mocked responses.", methodName))
	}

	bytes, err := json.Marshal(r)
	if err != nil {
		panic(err.Error())
	}

	return json.Unmarshal(bytes, &res)
}

func TestFakeTransport(t *testing.T) {
	Convey("Given fake transport", t, func() {
		ft := &fakeTransport{
			TripResponses: map[string]interface{}{"indiana": struct{ Name string }{"jones"}},
		}

		Convey("It implements Transport", func() {
			var _ transport.Transport = (*fakeTransport)(nil)
		})

		Convey("It should return unmarshal mock into response for method", func() {
{'fraction_non_alphanumeric': 0.13763066202090593, 'fraction_numerical': 0.0, 'mean_word_length': 4.713930348258707, 'pattern_counts': {'":': 2, '<': 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': '5284057', 'n_tokens_mistral': 785, 'n_tokens_neox': 737, 'n_words': 209}