package main

import (
	"context"
	"testing"
	"training/domain"
	"training/tracking"

	"github.com/google/go-cmp/cmp"
)

// section: test
func TestContext(t *testing.T) {
	ctx := context.Background()

	expUser := domain.User{ID: 10, Name: "Rob"}
	ctx = domain.WithContext(ctx, &expUser)

	expTracer := tracking.Tracer{ID: 20}
	ctx = tracking.WithContext(ctx, &expTracer)

	gotUser, err := domain.FromContext(ctx)
	if err != nil {
		t.Error(err)
	}
	if !cmp.Equal(gotUser, &expUser) {
		t.Errorf("unexpected user\n%s\n", cmp.Diff(gotUser, expUser))
	}

	gotTracer, err := tracking.FromContext(ctx)
	if err != nil {
		t.Error(err)
	}
	if !cmp.Equal(gotTracer, &expTracer) {
		t.Errorf("unexpected tracer\n%s\n", cmp.Diff(gotTracer, expTracer))
	}
}

// section: test

/*
// section: output
$ go test ./...
--- FAIL: TestContext (0.00s)
    main_test.go:23: user not found
    main_test.go:26: unexpected user
          interface{}(
        -       (*domain.User)(nil),
        +       domain.User{ID: 10, Name: "Rob"},
          )

FAIL
FAIL    training        0.094s
?       training/domain [no test files]
?       training/tracking       [no test files]
FAIL

// section: output
*/
